1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-21 10:50:24 +03:00

logging: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-20 13:49:46 +02:00
parent 9e96101d40
commit 620cd4d0c8
4 changed files with 12 additions and 26 deletions

View File

@ -388,9 +388,8 @@ virLogDaemonUnixSocketPaths(bool privileged,
char **adminSockfile)
{
if (privileged) {
if (VIR_STRDUP(*sockfile, RUNSTATEDIR "/libvirt/virtlogd-sock") < 0 ||
VIR_STRDUP(*adminSockfile, RUNSTATEDIR "/libvirt/virtlogd-admin-sock") < 0)
goto error;
*sockfile = g_strdup(RUNSTATEDIR "/libvirt/virtlogd-sock");
*adminSockfile = g_strdup(RUNSTATEDIR "/libvirt/virtlogd-admin-sock");
} else {
char *rundir = NULL;
mode_t old_umask;
@ -623,8 +622,7 @@ virLogDaemonExecRestartStatePath(bool privileged,
char **state_file)
{
if (privileged) {
if (VIR_STRDUP(*state_file, RUNSTATEDIR "/virtlogd-restart-exec.json") < 0)
goto error;
*state_file = g_strdup(RUNSTATEDIR "/virtlogd-restart-exec.json");
} else {
char *rundir = NULL;
mode_t old_umask;
@ -934,14 +932,12 @@ int main(int argc, char **argv) {
case 'p':
VIR_FREE(pid_file);
if (VIR_STRDUP_QUIET(pid_file, optarg) < 0)
goto no_memory;
pid_file = g_strdup(optarg);
break;
case 'f':
VIR_FREE(remote_config_file);
if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0)
goto no_memory;
remote_config_file = g_strdup(optarg);
break;
case 'V':
@ -1018,8 +1014,7 @@ int main(int argc, char **argv) {
/* Ensure the rundir exists (on tmpfs on some systems) */
if (privileged) {
if (VIR_STRDUP_QUIET(run_dir, RUNSTATEDIR "/libvirt") < 0)
goto no_memory;
run_dir = g_strdup(RUNSTATEDIR "/libvirt");
} else {
if (!(run_dir = virGetUserRuntimeDirectory())) {
VIR_ERROR(_("Can't determine user directory"));
@ -1220,8 +1215,4 @@ int main(int argc, char **argv) {
VIR_FREE(remote_config_file);
virLogDaemonConfigFree(config);
return ret;
no_memory:
VIR_ERROR(_("Can't allocate memory"));
exit(EXIT_FAILURE);
}

View File

@ -40,8 +40,7 @@ int
virLogDaemonConfigFilePath(bool privileged, char **configfile)
{
if (privileged) {
if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/virtlogd.conf") < 0)
goto error;
*configfile = g_strdup(SYSCONFDIR "/libvirt/virtlogd.conf");
} else {
char *configdir = NULL;

View File

@ -239,16 +239,14 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler,
_("Missing 'driver' in JSON document"));
goto error;
}
if (VIR_STRDUP(file->driver, tmp) < 0)
goto error;
file->driver = g_strdup(tmp);
if ((tmp = virJSONValueObjectGetString(object, "domname")) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing 'domname' in JSON document"));
goto error;
}
if (VIR_STRDUP(file->domname, tmp) < 0)
goto error;
file->domname = g_strdup(tmp);
if ((domuuid = virJSONValueObjectGetString(object, "domuuid")) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -402,9 +400,8 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
file->pipefd = pipefd[0];
pipefd[0] = -1;
memcpy(file->domuuid, domuuid, VIR_UUID_BUFLEN);
if (VIR_STRDUP(file->driver, driver) < 0 ||
VIR_STRDUP(file->domname, domname) < 0)
goto error;
file->driver = g_strdup(driver);
file->domname = g_strdup(domname);
if ((file->file = virRotatingFileWriterNew(path,
handler->max_size,

View File

@ -45,8 +45,7 @@ virLogManagerDaemonPath(bool privileged)
{
char *path;
if (privileged) {
if (VIR_STRDUP(path, RUNSTATEDIR "/libvirt/virtlogd-sock") < 0)
return NULL;
path = g_strdup(RUNSTATEDIR "/libvirt/virtlogd-sock");
} else {
char *rundir = NULL;