logging: Use g_strdup_printf() instead of virAsprintf()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-10-22 15:26:14 +02:00
parent b1d58418aa
commit 862d06df94
3 changed files with 9 additions and 27 deletions

View File

@ -405,11 +405,8 @@ virLogDaemonUnixSocketPaths(bool privileged,
} }
umask(old_umask); umask(old_umask);
if (virAsprintf(sockfile, "%s/virtlogd-sock", rundir) < 0 || *sockfile = g_strdup_printf("%s/virtlogd-sock", rundir);
virAsprintf(adminSockfile, "%s/virtlogd-admin-sock", rundir) < 0) { *adminSockfile = g_strdup_printf("%s/virtlogd-admin-sock", rundir);
VIR_FREE(rundir);
goto error;
}
VIR_FREE(rundir); VIR_FREE(rundir);
} }
@ -429,7 +426,7 @@ virLogDaemonErrorHandler(void *opaque G_GNUC_UNUSED,
} }
static int static void
virLogDaemonSetupLogging(virLogDaemonConfigPtr config, virLogDaemonSetupLogging(virLogDaemonConfigPtr config,
bool privileged, bool privileged,
bool verbose, bool verbose,
@ -466,13 +463,10 @@ virLogDaemonSetupLogging(virLogDaemonConfigPtr config,
/* 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.
*/ */
if (virLogSetDefaultOutput("virtlogd", godaemon, privileged) < 0) virLogSetDefaultOutput("virtlogd", godaemon, privileged);
return -1;
if (virLogGetNbOutputs() == 0) if (virLogGetNbOutputs() == 0)
virLogSetOutputs(virLogGetDefaultOutput()); virLogSetOutputs(virLogGetDefaultOutput());
return 0;
} }
@ -638,10 +632,7 @@ virLogDaemonExecRestartStatePath(bool privileged,
} }
umask(old_umask); umask(old_umask);
if (virAsprintf(state_file, "%s/virtlogd-restart-exec.json", rundir) < 0) { *state_file = g_strdup_printf("%s/virtlogd-restart-exec.json", rundir);
VIR_FREE(rundir);
goto error;
}
VIR_FREE(rundir); VIR_FREE(rundir);
} }
@ -658,7 +649,7 @@ virLogDaemonGetExecRestartMagic(void)
{ {
char *ret; char *ret;
ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid())); ret = g_strdup_printf("%lld", (long long int)getpid());
return ret; return ret;
} }
@ -980,10 +971,7 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (virLogDaemonSetupLogging(config, privileged, verbose, godaemon) < 0) { virLogDaemonSetupLogging(config, privileged, verbose, godaemon);
VIR_ERROR(_("Can't initialize logging"));
exit(EXIT_FAILURE);
}
if (!pid_file && if (!pid_file &&
virPidFileConstructPath(privileged, virPidFileConstructPath(privileged,

View File

@ -47,10 +47,7 @@ virLogDaemonConfigFilePath(bool privileged, char **configfile)
if (!(configdir = virGetUserConfigDirectory())) if (!(configdir = virGetUserConfigDirectory()))
goto error; goto error;
if (virAsprintf(configfile, "%s/virtlogd.conf", configdir) < 0) { *configfile = g_strdup_printf("%s/virtlogd.conf", configdir);
VIR_FREE(configdir);
goto error;
}
VIR_FREE(configdir); VIR_FREE(configdir);
} }

View File

@ -52,10 +52,7 @@ virLogManagerDaemonPath(bool privileged)
if (!(rundir = virGetUserRuntimeDirectory())) if (!(rundir = virGetUserRuntimeDirectory()))
return NULL; return NULL;
if (virAsprintf(&path, "%s/virtlogd-sock", rundir) < 0) { path = g_strdup_printf("%s/virtlogd-sock", rundir);
VIR_FREE(rundir);
return NULL;
}
VIR_FREE(rundir); VIR_FREE(rundir);
} }