Make test_event.cc more resilient
- Work on both Debian and RedHat systems. - Ignore test if authentication log cannot be found or cannot be read.
This commit is contained in:
parent
4d7121593e
commit
b5fdcf66ab
@ -462,8 +462,35 @@ int test_events()
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string get_auth_log()
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
|
||||||
|
const char DEBIAN_AUTH_LOG[] = "/var/log/auth.log";
|
||||||
|
const char REDHAT_AUTH_LOG[] = "/var/log/secure";
|
||||||
|
|
||||||
|
if (access(DEBIAN_AUTH_LOG, F_OK) == 0)
|
||||||
|
{
|
||||||
|
cout << "notice: " << DEBIAN_AUTH_LOG << " exists, assuming a Debian system." << endl;
|
||||||
|
name = DEBIAN_AUTH_LOG;
|
||||||
|
}
|
||||||
|
else if (access(REDHAT_AUTH_LOG, F_OK) == 0)
|
||||||
|
{
|
||||||
|
cout << "notice: " << REDHAT_AUTH_LOG << " exists, assuming a RedHat system." << endl;
|
||||||
|
name = REDHAT_AUTH_LOG;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "warning: Neither " << DEBIAN_AUTH_LOG << ", nor " << REDHAT_AUTH_LOG << " exists." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
int test_logging()
|
int test_logging()
|
||||||
{
|
{
|
||||||
|
int errors = 0;
|
||||||
|
|
||||||
event::set_log_facility(event::AUTHENTICATION_FAILURE, LOG_AUTH);
|
event::set_log_facility(event::AUTHENTICATION_FAILURE, LOG_AUTH);
|
||||||
event::set_log_level(event::AUTHENTICATION_FAILURE, LOG_ERR);
|
event::set_log_level(event::AUTHENTICATION_FAILURE, LOG_ERR);
|
||||||
|
|
||||||
@ -481,6 +508,23 @@ int test_logging()
|
|||||||
|
|
||||||
MXS_LOG_EVENT(event::AUTHENTICATION_FAILURE, "%s", id.c_str());
|
MXS_LOG_EVENT(event::AUTHENTICATION_FAILURE, "%s", id.c_str());
|
||||||
|
|
||||||
|
string name = get_auth_log();
|
||||||
|
|
||||||
|
if (name.empty())
|
||||||
|
{
|
||||||
|
cout << "warning: Don't know where to look for authentication errors. Ignoring test." << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (access(name.c_str(), R_OK) != 0)
|
||||||
|
{
|
||||||
|
cout << "warning: Cannot read " << name << ", ignoring test." << endl;
|
||||||
|
name.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name.empty())
|
||||||
|
{
|
||||||
// We have no control over how quickly syslog messages are flushed
|
// We have no control over how quickly syslog messages are flushed
|
||||||
// to the file. So, we try a few times before giving up.
|
// to the file. So, we try a few times before giving up.
|
||||||
|
|
||||||
@ -494,8 +538,7 @@ int test_logging()
|
|||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
const char* zName = "/var/log/auth.log";
|
ifstream in(name);
|
||||||
ifstream in(zName);
|
|
||||||
|
|
||||||
if (in)
|
if (in)
|
||||||
{
|
{
|
||||||
@ -511,13 +554,16 @@ int test_logging()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "error: Could not open '" << zName << "'." << endl;
|
cerr << "error: Could not open '" << name << "'." << endl;
|
||||||
attempts = MAX_ATTEMPTS;
|
attempts = MAX_ATTEMPTS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!found && (attempts < MAX_ATTEMPTS));
|
while (!found && (attempts < MAX_ATTEMPTS));
|
||||||
|
|
||||||
return found ? 0 : 1;
|
errors = found ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user