Tighten libvirt's parsing of logging env

* src/libvirt.c src/logging.c: Don't convert high priority levels to the
  debug level. Don't parse LIBVIRT_LOG_FILTERS and LIBVIRT_LOG_OUTPUTS
  when they're set to the empty string. Warn when the user specifies an
  invalid value (empty string remains a noop).
* po/POTFILES.in: src/logging.c now include translatable strings
This commit is contained in:
Amy Griffis 2009-08-06 15:38:11 +02:00 committed by Daniel Veillard
parent a9e96b1ee0
commit 22a1ec68d5
3 changed files with 41 additions and 25 deletions

View File

@ -10,6 +10,7 @@ src/interface_conf.c
src/interface_driver.c src/interface_driver.c
src/iptables.c src/iptables.c
src/libvirt.c src/libvirt.c
src/logging.c
src/lxc_container.c src/lxc_container.c
src/lxc_controller.c src/lxc_controller.c
src/lxc_driver.c src/lxc_driver.c

View File

@ -274,21 +274,24 @@ virInitialize(void)
return -1; return -1;
debugEnv = getenv("LIBVIRT_DEBUG"); debugEnv = getenv("LIBVIRT_DEBUG");
if (debugEnv && *debugEnv && *debugEnv != '0') { if (debugEnv && *debugEnv) {
if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info")) if (STREQ(debugEnv, "1") || STREQ(debugEnv, "debug"))
virLogSetDefaultPriority(VIR_LOG_DEBUG);
else if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
virLogSetDefaultPriority(VIR_LOG_INFO); virLogSetDefaultPriority(VIR_LOG_INFO);
else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning")) else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning"))
virLogSetDefaultPriority(VIR_LOG_WARN); virLogSetDefaultPriority(VIR_LOG_WARN);
else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error")) else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error"))
virLogSetDefaultPriority(VIR_LOG_ERROR); virLogSetDefaultPriority(VIR_LOG_ERROR);
else else
virLogSetDefaultPriority(VIR_LOG_DEBUG); VIR_WARN0(_("Ignoring invalid log level setting."));
} }
debugEnv = getenv("LIBVIRT_LOG_FILTERS"); debugEnv = getenv("LIBVIRT_LOG_FILTERS");
if (debugEnv) if (debugEnv && *debugEnv)
virLogParseFilters(debugEnv); virLogParseFilters(debugEnv);
debugEnv = getenv("LIBVIRT_LOG_OUTPUTS"); debugEnv = getenv("LIBVIRT_LOG_OUTPUTS");
if (debugEnv) if (debugEnv && *debugEnv)
virLogParseOutputs(debugEnv); virLogParseOutputs(debugEnv);
DEBUG0("register drivers"); DEBUG0("register drivers");

View File

@ -314,8 +314,10 @@ error:
* Returns 0 if successful, -1 in case of error. * Returns 0 if successful, -1 in case of error.
*/ */
int virLogSetDefaultPriority(int priority) { int virLogSetDefaultPriority(int priority) {
if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) if ((priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) {
VIR_WARN0(_("Ignoring invalid log level setting."));
return(-1); return(-1);
}
if (!virLogInitialized) if (!virLogInitialized)
virLogStartup(); virLogStartup();
virLogDefaultPriority = priority; virLogDefaultPriority = priority;
@ -681,7 +683,8 @@ int virLogParseOutputs(const char *outputs) {
const char *cur = outputs, *str; const char *cur = outputs, *str;
char *name; char *name;
int prio; int prio;
int ret = 0; int ret = -1;
int count = 0;
if (cur == NULL) if (cur == NULL)
return(-1); return(-1);
@ -690,53 +693,57 @@ int virLogParseOutputs(const char *outputs) {
while (*cur != 0) { while (*cur != 0) {
prio= virParseNumber(&cur); prio= virParseNumber(&cur);
if ((prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR)) if ((prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
return(-1); goto cleanup;
if (*cur != ':') if (*cur != ':')
return(-1); goto cleanup;
cur++; cur++;
if (STREQLEN(cur, "stderr", 6)) { if (STREQLEN(cur, "stderr", 6)) {
cur += 6; cur += 6;
if (virLogAddOutputToStderr(prio) == 0) if (virLogAddOutputToStderr(prio) == 0)
ret++; count++;
} else if (STREQLEN(cur, "syslog", 6)) { } else if (STREQLEN(cur, "syslog", 6)) {
cur += 6; cur += 6;
if (*cur != ':') if (*cur != ':')
return(-1); goto cleanup;
cur++; cur++;
str = cur; str = cur;
while ((*cur != 0) && (!IS_SPACE(cur))) while ((*cur != 0) && (!IS_SPACE(cur)))
cur++; cur++;
if (str == cur) if (str == cur)
return(-1); goto cleanup;
#if HAVE_SYSLOG_H #if HAVE_SYSLOG_H
name = strndup(str, cur - str); name = strndup(str, cur - str);
if (name == NULL) if (name == NULL)
return(-1); goto cleanup;
if (virLogAddOutputToSyslog(prio, name) == 0) if (virLogAddOutputToSyslog(prio, name) == 0)
ret++; count++;
VIR_FREE(name); VIR_FREE(name);
#endif /* HAVE_SYSLOG_H */ #endif /* HAVE_SYSLOG_H */
} else if (STREQLEN(cur, "file", 4)) { } else if (STREQLEN(cur, "file", 4)) {
cur += 4; cur += 4;
if (*cur != ':') if (*cur != ':')
return(-1); goto cleanup;
cur++; cur++;
str = cur; str = cur;
while ((*cur != 0) && (!IS_SPACE(cur))) while ((*cur != 0) && (!IS_SPACE(cur)))
cur++; cur++;
if (str == cur) if (str == cur)
return(-1); goto cleanup;
name = strndup(str, cur - str); name = strndup(str, cur - str);
if (name == NULL) if (name == NULL)
return(-1); goto cleanup;
if (virLogAddOutputToFile(prio, name) == 0) if (virLogAddOutputToFile(prio, name) == 0)
ret++; count++;
VIR_FREE(name); VIR_FREE(name);
} else { } else {
return(-1); goto cleanup;
} }
virSkipSpaces(&cur); virSkipSpaces(&cur);
} }
ret = count;
cleanup:
if (ret == -1)
VIR_WARN0(_("Ignoring invalid log output setting."));
return(ret); return(ret);
} }
@ -762,7 +769,8 @@ int virLogParseFilters(const char *filters) {
const char *cur = filters, *str; const char *cur = filters, *str;
char *name; char *name;
int prio; int prio;
int ret = 0; int ret = -1;
int count = 0;
if (cur == NULL) if (cur == NULL)
return(-1); return(-1);
@ -771,22 +779,26 @@ int virLogParseFilters(const char *filters) {
while (*cur != 0) { while (*cur != 0) {
prio= virParseNumber(&cur); prio= virParseNumber(&cur);
if ((prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR)) if ((prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
return(-1); goto cleanup;
if (*cur != ':') if (*cur != ':')
return(-1); goto cleanup;
cur++; cur++;
str = cur; str = cur;
while ((*cur != 0) && (!IS_SPACE(cur))) while ((*cur != 0) && (!IS_SPACE(cur)))
cur++; cur++;
if (str == cur) if (str == cur)
return(-1); goto cleanup;
name = strndup(str, cur - str); name = strndup(str, cur - str);
if (name == NULL) if (name == NULL)
return(-1); goto cleanup;
if (virLogDefineFilter(name, prio, 0) >= 0) if (virLogDefineFilter(name, prio, 0) >= 0)
ret++; count++;
VIR_FREE(name); VIR_FREE(name);
virSkipSpaces(&cur); virSkipSpaces(&cur);
} }
ret = count;
cleanup:
if (ret == -1)
VIR_WARN0(_("Ignoring invalid log filter setting."));
return(ret); return(ret);
} }