mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
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:
parent
a9e96b1ee0
commit
22a1ec68d5
@ -10,6 +10,7 @@ src/interface_conf.c
|
||||
src/interface_driver.c
|
||||
src/iptables.c
|
||||
src/libvirt.c
|
||||
src/logging.c
|
||||
src/lxc_container.c
|
||||
src/lxc_controller.c
|
||||
src/lxc_driver.c
|
||||
|
@ -274,21 +274,24 @@ virInitialize(void)
|
||||
return -1;
|
||||
|
||||
debugEnv = getenv("LIBVIRT_DEBUG");
|
||||
if (debugEnv && *debugEnv && *debugEnv != '0') {
|
||||
if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
|
||||
if (debugEnv && *debugEnv) {
|
||||
if (STREQ(debugEnv, "1") || STREQ(debugEnv, "debug"))
|
||||
virLogSetDefaultPriority(VIR_LOG_DEBUG);
|
||||
else if (STREQ(debugEnv, "2") || STREQ(debugEnv, "info"))
|
||||
virLogSetDefaultPriority(VIR_LOG_INFO);
|
||||
else if (STREQ(debugEnv, "3") || STREQ(debugEnv, "warning"))
|
||||
virLogSetDefaultPriority(VIR_LOG_WARN);
|
||||
else if (STREQ(debugEnv, "4") || STREQ(debugEnv, "error"))
|
||||
virLogSetDefaultPriority(VIR_LOG_ERROR);
|
||||
else
|
||||
virLogSetDefaultPriority(VIR_LOG_DEBUG);
|
||||
VIR_WARN0(_("Ignoring invalid log level setting."));
|
||||
}
|
||||
debugEnv = getenv("LIBVIRT_LOG_FILTERS");
|
||||
if (debugEnv)
|
||||
if (debugEnv && *debugEnv)
|
||||
virLogParseFilters(debugEnv);
|
||||
|
||||
debugEnv = getenv("LIBVIRT_LOG_OUTPUTS");
|
||||
if (debugEnv)
|
||||
if (debugEnv && *debugEnv)
|
||||
virLogParseOutputs(debugEnv);
|
||||
|
||||
DEBUG0("register drivers");
|
||||
|
@ -314,8 +314,10 @@ error:
|
||||
* Returns 0 if successful, -1 in case of error.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
if (!virLogInitialized)
|
||||
virLogStartup();
|
||||
virLogDefaultPriority = priority;
|
||||
@ -681,7 +683,8 @@ int virLogParseOutputs(const char *outputs) {
|
||||
const char *cur = outputs, *str;
|
||||
char *name;
|
||||
int prio;
|
||||
int ret = 0;
|
||||
int ret = -1;
|
||||
int count = 0;
|
||||
|
||||
if (cur == NULL)
|
||||
return(-1);
|
||||
@ -690,53 +693,57 @@ int virLogParseOutputs(const char *outputs) {
|
||||
while (*cur != 0) {
|
||||
prio= virParseNumber(&cur);
|
||||
if ((prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
if (*cur != ':')
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
cur++;
|
||||
if (STREQLEN(cur, "stderr", 6)) {
|
||||
cur += 6;
|
||||
if (virLogAddOutputToStderr(prio) == 0)
|
||||
ret++;
|
||||
count++;
|
||||
} else if (STREQLEN(cur, "syslog", 6)) {
|
||||
cur += 6;
|
||||
if (*cur != ':')
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
cur++;
|
||||
str = cur;
|
||||
while ((*cur != 0) && (!IS_SPACE(cur)))
|
||||
cur++;
|
||||
if (str == cur)
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
#if HAVE_SYSLOG_H
|
||||
name = strndup(str, cur - str);
|
||||
if (name == NULL)
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
if (virLogAddOutputToSyslog(prio, name) == 0)
|
||||
ret++;
|
||||
count++;
|
||||
VIR_FREE(name);
|
||||
#endif /* HAVE_SYSLOG_H */
|
||||
} else if (STREQLEN(cur, "file", 4)) {
|
||||
cur += 4;
|
||||
if (*cur != ':')
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
cur++;
|
||||
str = cur;
|
||||
while ((*cur != 0) && (!IS_SPACE(cur)))
|
||||
cur++;
|
||||
if (str == cur)
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
name = strndup(str, cur - str);
|
||||
if (name == NULL)
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
if (virLogAddOutputToFile(prio, name) == 0)
|
||||
ret++;
|
||||
count++;
|
||||
VIR_FREE(name);
|
||||
} else {
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
}
|
||||
virSkipSpaces(&cur);
|
||||
}
|
||||
ret = count;
|
||||
cleanup:
|
||||
if (ret == -1)
|
||||
VIR_WARN0(_("Ignoring invalid log output setting."));
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@ -762,7 +769,8 @@ int virLogParseFilters(const char *filters) {
|
||||
const char *cur = filters, *str;
|
||||
char *name;
|
||||
int prio;
|
||||
int ret = 0;
|
||||
int ret = -1;
|
||||
int count = 0;
|
||||
|
||||
if (cur == NULL)
|
||||
return(-1);
|
||||
@ -771,22 +779,26 @@ int virLogParseFilters(const char *filters) {
|
||||
while (*cur != 0) {
|
||||
prio= virParseNumber(&cur);
|
||||
if ((prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
if (*cur != ':')
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
cur++;
|
||||
str = cur;
|
||||
while ((*cur != 0) && (!IS_SPACE(cur)))
|
||||
cur++;
|
||||
if (str == cur)
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
name = strndup(str, cur - str);
|
||||
if (name == NULL)
|
||||
return(-1);
|
||||
goto cleanup;
|
||||
if (virLogDefineFilter(name, prio, 0) >= 0)
|
||||
ret++;
|
||||
count++;
|
||||
VIR_FREE(name);
|
||||
virSkipSpaces(&cur);
|
||||
}
|
||||
ret = count;
|
||||
cleanup:
|
||||
if (ret == -1)
|
||||
VIR_WARN0(_("Ignoring invalid log filter setting."));
|
||||
return(ret);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user