Fix test failures from latest logging changes

This commit is contained in:
Andrew Bettison 2013-04-05 15:28:54 +10:30
parent a822dca2fa
commit f06613c35f
3 changed files with 27 additions and 29 deletions

32
log.c
View File

@ -444,6 +444,7 @@ static void _open_log_file(_log_iterator *it)
if (_log_file != NO_FILE) {
if (_log_file_path == NULL)
_log_file_path = getenv("SERVALD_LOG_FILE");
_log_symlink_path = NULL;
if (_log_file_path == NULL && !cf_limbo) {
strbuf sbfile = strbuf_local(_log_file_path_buf, sizeof _log_file_path_buf);
strbuf_path_join(sbfile, serval_instancepath(), log_file_directory_path(), NULL);
@ -454,18 +455,15 @@ static void _open_log_file(_log_iterator *it)
if (strbuf_overrun(sbfile)) {
_log_file = NO_FILE;
_logs_printf_nl(LOG_LEVEL_ERROR, __HERE__, "Cannot form log file name - buffer overrun");
_log_symlink_path = NULL;
} else {
_log_file_start_time = it->file_start_time;
_log_file_path = strbuf_str(sbfile);
strbuf sbsymlink = strbuf_local(_log_symlink_path_buf, sizeof _log_symlink_path_buf);
strbuf_path_join(sbsymlink, serval_instancepath(), "serval.log", NULL);
if (strbuf_overrun(sbsymlink)) {
if (strbuf_overrun(sbsymlink))
_logs_printf_nl(LOG_LEVEL_ERROR, __HERE__, "Cannot form log symlink name - buffer overrun");
_log_symlink_path = NULL;
} else {
else
_log_symlink_path = strbuf_str(sbsymlink);
}
}
}
if (!_log_file) {
@ -485,19 +483,19 @@ static void _open_log_file(_log_iterator *it)
_log_current_datetime(it, LOG_LEVEL_INFO);
_logs_printf_nl(LOG_LEVEL_INFO, __NOWHERE__, "Logging to %s (fd %d)", _log_file_path, fileno(_log_file));
// Update the log symlink to point to the latest log file.
const char *f = _log_file_path;
const char *s = _log_symlink_path;
const char *relpath = f;
for (; *f && *f == *s; ++f, ++s)
if (*f == '/')
relpath = f;
while (*relpath == '/')
++relpath;
while (*s == '/')
++s;
if (strchr(s, '/'))
relpath = _log_file_path;
if (_log_symlink_path) {
const char *f = _log_file_path;
const char *s = _log_symlink_path;
const char *relpath = f;
for (; *f && *f == *s; ++f, ++s)
if (*f == '/')
relpath = f;
while (*relpath == '/')
++relpath;
while (*s == '/')
++s;
if (strchr(s, '/'))
relpath = _log_file_path;
unlink(_log_symlink_path);
if (symlink(relpath, _log_symlink_path) == -1)
_logs_printf_nl(LOG_LEVEL_ERROR, __HERE__, "Cannot symlink %s to %s - %s [errno=%d]", _log_symlink_path, relpath, strerror(errno), errno);

View File

@ -270,24 +270,24 @@ test_InterfacesModernIncompatible() {
--error-pattern='config file.*loaded despite defects.*incompatible'
}
doc_LogFileAbsolute="Absolute log file"
doc_LogFileAbsolute="Absolute log file directory"
test_LogFileAbsolute() {
executeOk_servald config \
set debug.verbose true \
set log.file_path "$PWD/log"
set log.file.directory_path "$PWD/wakawaka"
executeOk_servald echo one
assertGrep log '^DEBUG:.*echo:argv\[1\]="one"$'
assertGrep --matches=0 --message="log contains no error messages" log '^ERROR:'
assert --message="exactly one log file" [ $(ls -d wakawaka/*.log | wc -l) -eq 1 ]
assertGrep wakawaka/*.log '^DEBUG:.*echo:argv\[1\]="one"$'
}
doc_LogFileRelative="Relative log file"
doc_LogFileRelative="Relative log file directory"
test_LogFileRelative() {
executeOk_servald config \
set debug.verbose true \
set log.file_path "log"
set log.file.directory_path "blah"
executeOk_servald echo one
assertGrep "$SERVALINSTANCE_PATH/log" '^DEBUG:.*echo:argv\[1\]="one"$'
assertGrep --matches=0 --message="log contains no error messages" "$SERVALINSTANCE_PATH/log" '^ERROR:'
assert --message="exactly one log file" [ $(ls -d "$SERVALINSTANCE_PATH/blah/"*.log | wc -l) -eq 1 ]
assertGrep "$SERVALINSTANCE_PATH/blah/"*.log '^DEBUG:.*echo:argv\[1\]="one"$'
}
runTests "$@"

View File

@ -53,13 +53,13 @@ test_StartCreateInstanceDir() {
doc_StartLogfile="Starting server gives no errors"
setup_StartLogfile() {
setup
executeOk_servald config set log.file_path "$PWD/log"
executeOk_servald config set log.file.directory_path "$PWD/log"
}
test_StartLogfile() {
executeOk $servald start
executeOk_servald start
sleep 0.1
assert [ -s log ]
tfw_cat log
assert [ -s log/*.log ]
tfw_cat log/*.log
}
doc_StartNoInterfaces="Starting server with no configured interfaces gives warning"