daemon: Split output parsing and output defining

Since virLogParseAndDefineOutputs is going to be stripped from 'output defining'
logic, replace all relevant occurrences with virLogSetOutputs call to make the
change transparent to all original callers (daemons mostly).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety 2016-03-17 15:26:40 +01:00
parent c33babfe31
commit c9279169a1
6 changed files with 28 additions and 17 deletions

View File

@ -693,8 +693,8 @@ daemonSetupLogging(struct daemonConfig *config,
if (virLogGetNbFilters() == 0) if (virLogGetNbFilters() == 0)
virLogParseAndDefineFilters(config->log_filters); virLogParseAndDefineFilters(config->log_filters);
if (virLogGetNbOutputs() == 0) if (config->log_outputs && virLogGetNbOutputs() == 0)
virLogParseAndDefineOutputs(config->log_outputs); virLogSetOutputs(config->log_outputs);
/* /*
* Command line override for --verbose * Command line override for --verbose
@ -721,7 +721,7 @@ daemonSetupLogging(struct daemonConfig *config,
if (virAsprintf(&tmp, "%d:journald", priority) < 0) if (virAsprintf(&tmp, "%d:journald", priority) < 0)
goto error; goto error;
virLogParseAndDefineOutputs(tmp); virLogSetOutputs(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} }
} }
@ -764,7 +764,7 @@ daemonSetupLogging(struct daemonConfig *config,
if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0) if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0)
goto error; goto error;
} }
virLogParseAndDefineOutputs(tmp); virLogSetOutputs(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} }

View File

@ -478,8 +478,8 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
if (virLogGetNbFilters() == 0) if (virLogGetNbFilters() == 0)
virLogParseAndDefineFilters(config->log_filters); virLogParseAndDefineFilters(config->log_filters);
if (virLogGetNbOutputs() == 0) if (config->log_outputs && virLogGetNbOutputs() == 0)
virLogParseAndDefineOutputs(config->log_outputs); virLogSetOutputs(config->log_outputs);
/* /*
* Command line override for --verbose * Command line override for --verbose
@ -499,7 +499,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
if (access("/run/systemd/journal/socket", W_OK) >= 0) { if (access("/run/systemd/journal/socket", W_OK) >= 0) {
if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0) if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)
goto error; goto error;
virLogParseAndDefineOutputs(tmp); virLogSetOutputs(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} }
} }
@ -543,7 +543,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0) if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0)
goto error; goto error;
} }
virLogParseAndDefineOutputs(tmp); virLogSetOutputs(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} }

View File

@ -406,8 +406,8 @@ virLogDaemonSetupLogging(virLogDaemonConfigPtr config,
if (virLogGetNbFilters() == 0) if (virLogGetNbFilters() == 0)
virLogParseAndDefineFilters(config->log_filters); virLogParseAndDefineFilters(config->log_filters);
if (virLogGetNbOutputs() == 0) if (config->log_outputs && virLogGetNbOutputs() == 0)
virLogParseAndDefineOutputs(config->log_outputs); virLogSetOutputs(config->log_outputs);
/* /*
* Command line override for --verbose * Command line override for --verbose
@ -427,7 +427,7 @@ virLogDaemonSetupLogging(virLogDaemonConfigPtr config,
if (access("/run/systemd/journal/socket", W_OK) >= 0) { if (access("/run/systemd/journal/socket", W_OK) >= 0) {
if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0) if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)
goto error; goto error;
virLogParseAndDefineOutputs(tmp); virLogSetOutputs(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} }
} }
@ -471,7 +471,7 @@ virLogDaemonSetupLogging(virLogDaemonConfigPtr config,
if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0) if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0)
goto error; goto error;
} }
virLogParseAndDefineOutputs(tmp); virLogSetOutputs(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} }

View File

@ -1627,7 +1627,7 @@ virLogSetFromEnv(void)
virLogParseAndDefineFilters(debugEnv); virLogParseAndDefineFilters(debugEnv);
debugEnv = virGetEnvAllowSUID("LIBVIRT_LOG_OUTPUTS"); debugEnv = virGetEnvAllowSUID("LIBVIRT_LOG_OUTPUTS");
if (debugEnv && *debugEnv) if (debugEnv && *debugEnv)
virLogParseAndDefineOutputs(debugEnv); virLogSetOutputs(debugEnv);
} }

View File

@ -872,6 +872,9 @@ int virTestMain(int argc,
#ifdef TEST_OOM #ifdef TEST_OOM
char *oomstr; char *oomstr;
#endif #endif
size_t noutputs = 0;
virLogOutputPtr output = NULL;
virLogOutputPtr *outputs = NULL;
if (getenv("VIR_TEST_FILE_ACCESS")) if (getenv("VIR_TEST_FILE_ACCESS"))
VIRT_TEST_PRELOAD(TEST_MOCK); VIRT_TEST_PRELOAD(TEST_MOCK);
@ -911,9 +914,15 @@ int virTestMain(int argc,
virLogSetFromEnv(); virLogSetFromEnv();
if (!getenv("LIBVIRT_DEBUG") && !virLogGetNbOutputs()) { if (!getenv("LIBVIRT_DEBUG") && !virLogGetNbOutputs()) {
if (virLogDefineOutput(virtTestLogOutput, virtTestLogClose, &testLog, if (!(output = virLogOutputNew(virtTestLogOutput, virtTestLogClose,
VIR_LOG_DEBUG, VIR_LOG_TO_STDERR, NULL, 0) < 0) &testLog, VIR_LOG_DEBUG,
VIR_LOG_TO_STDERR, NULL)) ||
VIR_APPEND_ELEMENT(outputs, noutputs, output) < 0 ||
virLogDefineOutputs(outputs, noutputs) < 0) {
virLogOutputFree(output);
virLogOutputListFree(outputs, noutputs);
return EXIT_FAILURE; return EXIT_FAILURE;
}
} }
if ((testRange = getenv("VIR_TEST_RANGE")) != NULL) { if ((testRange = getenv("VIR_TEST_RANGE")) != NULL) {
@ -988,6 +997,7 @@ int virTestMain(int argc,
fprintf(stderr, "%*s", 40 - (int)(testCounter % 40), ""); fprintf(stderr, "%*s", 40 - (int)(testCounter % 40), "");
fprintf(stderr, " %-3zu %s\n", testCounter, ret == 0 ? "OK" : "FAIL"); fprintf(stderr, " %-3zu %s\n", testCounter, ret == 0 ? "OK" : "FAIL");
} }
virLogReset();
VIR_FREE(perl); VIR_FREE(perl);
return ret; return ret;
} }

View File

@ -48,9 +48,10 @@ testLogParseOutputs(const void *opaque)
{ {
int ret = -1; int ret = -1;
int noutputs; int noutputs;
virLogOutputPtr *outputs = NULL;
const struct testLogData *data = opaque; const struct testLogData *data = opaque;
noutputs = virLogParseAndDefineOutputs(data->str); noutputs = virLogParseOutputs(data->str, &outputs);
if (noutputs < 0) { if (noutputs < 0) {
if (!data->pass) { if (!data->pass) {
VIR_TEST_DEBUG("Got expected error: %s\n", VIR_TEST_DEBUG("Got expected error: %s\n",
@ -70,7 +71,7 @@ testLogParseOutputs(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
virLogReset(); virLogOutputListFree(outputs, noutputs);
return ret; return ret;
} }