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

View File

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

View File

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