mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
Exit on errors from virDaemonSetupLogging
This prevents starting any daemons with improper logging settings. This is desirable on its own, but will be even more beneficial when more functions start reporting errors and failing on them, coming up in following patches Signed-off-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
b863085493
commit
a873924e36
@ -913,13 +913,14 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
VIR_FREE(remote_config_file);
|
VIR_FREE(remote_config_file);
|
||||||
|
|
||||||
virDaemonSetupLogging("virtlockd",
|
if (virDaemonSetupLogging("virtlockd",
|
||||||
config->log_level,
|
config->log_level,
|
||||||
config->log_filters,
|
config->log_filters,
|
||||||
config->log_outputs,
|
config->log_outputs,
|
||||||
privileged,
|
privileged,
|
||||||
verbose,
|
verbose,
|
||||||
godaemon);
|
godaemon) < 0)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
if (!pid_file &&
|
if (!pid_file &&
|
||||||
virPidFileConstructPath(privileged,
|
virPidFileConstructPath(privileged,
|
||||||
|
@ -719,13 +719,14 @@ int main(int argc, char **argv) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
virDaemonSetupLogging("virtlogd",
|
if (virDaemonSetupLogging("virtlogd",
|
||||||
config->log_level,
|
config->log_level,
|
||||||
config->log_filters,
|
config->log_filters,
|
||||||
config->log_outputs,
|
config->log_outputs,
|
||||||
privileged,
|
privileged,
|
||||||
verbose,
|
verbose,
|
||||||
godaemon);
|
godaemon) < 0)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
if (!pid_file &&
|
if (!pid_file &&
|
||||||
virPidFileConstructPath(privileged,
|
virPidFileConstructPath(privileged,
|
||||||
|
@ -936,13 +936,14 @@ int main(int argc, char **argv) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
virDaemonSetupLogging(DAEMON_NAME,
|
if (virDaemonSetupLogging(DAEMON_NAME,
|
||||||
config->log_level,
|
config->log_level,
|
||||||
config->log_filters,
|
config->log_filters,
|
||||||
config->log_outputs,
|
config->log_outputs,
|
||||||
privileged,
|
privileged,
|
||||||
verbose,
|
verbose,
|
||||||
godaemon);
|
godaemon) < 0)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
/* Let's try to initialize global variable that holds the host's boot time. */
|
/* Let's try to initialize global variable that holds the host's boot time. */
|
||||||
if (virHostBootTimeInit() < 0) {
|
if (virHostBootTimeInit() < 0) {
|
||||||
|
@ -151,7 +151,7 @@ virDaemonForkIntoBackground(const char *argv0)
|
|||||||
* but if verbose or error debugging is asked for then also output
|
* but if verbose or error debugging is asked for then also output
|
||||||
* informational and debug messages. Default size if 64 kB.
|
* informational and debug messages. Default size if 64 kB.
|
||||||
*/
|
*/
|
||||||
void
|
int
|
||||||
virDaemonSetupLogging(const char *daemon_name,
|
virDaemonSetupLogging(const char *daemon_name,
|
||||||
unsigned int log_level,
|
unsigned int log_level,
|
||||||
char *log_filters,
|
char *log_filters,
|
||||||
@ -160,7 +160,8 @@ virDaemonSetupLogging(const char *daemon_name,
|
|||||||
bool verbose,
|
bool verbose,
|
||||||
bool godaemon)
|
bool godaemon)
|
||||||
{
|
{
|
||||||
virLogReset();
|
if (virLogReset() < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Libvirtd's order of precedence is:
|
* Libvirtd's order of precedence is:
|
||||||
@ -169,15 +170,17 @@ virDaemonSetupLogging(const char *daemon_name,
|
|||||||
* Given the precedence, we must process the variables in the opposite
|
* Given the precedence, we must process the variables in the opposite
|
||||||
* order, each one overriding the previous.
|
* order, each one overriding the previous.
|
||||||
*/
|
*/
|
||||||
if (log_level != 0)
|
if (log_level != 0 &&
|
||||||
virLogSetDefaultPriority(log_level);
|
virLogSetDefaultPriority(log_level) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* In case the config is empty, both filters and outputs will become empty,
|
/* In case the config is empty, both filters and outputs will become empty,
|
||||||
* however we can't start with empty outputs, thus we'll need to define and
|
* however we can't start with empty outputs, thus we'll need to define and
|
||||||
* setup a default one.
|
* setup a default one.
|
||||||
*/
|
*/
|
||||||
ignore_value(virLogSetFilters(log_filters));
|
if (virLogSetFilters(log_filters) < 0 ||
|
||||||
ignore_value(virLogSetOutputs(log_outputs));
|
virLogSetOutputs(log_outputs) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* If there are some environment variables defined, use those instead */
|
/* If there are some environment variables defined, use those instead */
|
||||||
virLogSetFromEnv();
|
virLogSetFromEnv();
|
||||||
@ -185,16 +188,22 @@ virDaemonSetupLogging(const char *daemon_name,
|
|||||||
/*
|
/*
|
||||||
* Command line override for --verbose
|
* Command line override for --verbose
|
||||||
*/
|
*/
|
||||||
if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO))
|
if (verbose &&
|
||||||
virLogSetDefaultPriority(VIR_LOG_INFO);
|
virLogGetDefaultPriority() > VIR_LOG_INFO &&
|
||||||
|
virLogSetDefaultPriority(VIR_LOG_INFO) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* Define the default output. This is only applied if there was no setting
|
/* Define the default output. This is only applied if there was no setting
|
||||||
* from either the config or the environment.
|
* from either the config or the environment.
|
||||||
*/
|
*/
|
||||||
virLogSetDefaultOutput(daemon_name, godaemon, privileged);
|
if (virLogSetDefaultOutput(daemon_name, godaemon, privileged) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (virLogGetNbOutputs() == 0)
|
if (virLogGetNbOutputs() == 0 &&
|
||||||
virLogSetOutputs(virLogGetDefaultOutput());
|
virLogSetOutputs(virLogGetDefaultOutput()) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ VIR_ENUM_IMPL(virDaemonErr,
|
|||||||
|
|
||||||
int virDaemonForkIntoBackground(const char *argv0);
|
int virDaemonForkIntoBackground(const char *argv0);
|
||||||
|
|
||||||
void virDaemonSetupLogging(const char *daemon_name,
|
int virDaemonSetupLogging(const char *daemon_name,
|
||||||
unsigned int log_level,
|
unsigned int log_level,
|
||||||
char *log_filters,
|
char *log_filters,
|
||||||
char *log_outputs,
|
char *log_outputs,
|
||||||
bool privileged,
|
bool privileged,
|
||||||
bool verbose,
|
bool verbose,
|
||||||
bool godaemon);
|
bool godaemon);
|
||||||
|
|
||||||
int virDaemonUnixSocketPaths(const char *sock_prefix,
|
int virDaemonUnixSocketPaths(const char *sock_prefix,
|
||||||
bool privileged,
|
bool privileged,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user