lib: Don't check for retval for virCommandNew*()

The virCommand module is specifically designed so that no caller
has to check for retval of individual virCommand*() APIs except
for virCommandRun() where the actual error is reported. Moreover,
virCommandNew*() use g_new0() to allocate memory and thus it's
not really possible for those APIs to return NULL. Which is why
they are even marked as ATTRIBUTE_NONNULL. But there are few
places where we do check the retval which is a dead code
effectively. Drop those checks.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Michal Privoznik 2022-08-23 14:35:47 +02:00
parent 21ad635fc3
commit da255ce831
6 changed files with 4 additions and 20 deletions

View File

@ -268,8 +268,7 @@ qemuSlirpStart(virDomainObj *vm,
if (!(pidfile = qemuSlirpCreatePidFilename(cfg, vm->def, net->info.alias))) if (!(pidfile = qemuSlirpCreatePidFilename(cfg, vm->def, net->info.alias)))
return -1; return -1;
if (!(cmd = virCommandNew(cfg->slirpHelperName))) cmd = virCommandNew(cfg->slirpHelperName);
return -1;
virCommandClearCaps(cmd); virCommandClearCaps(cmd);
virCommandSetPidFile(cmd, pidfile); virCommandSetPidFile(cmd, pidfile);

View File

@ -279,8 +279,6 @@ qemuTPMCreateConfigFiles(const char *swtpm_setup)
return 0; return 0;
cmd = virCommandNew(swtpm_setup); cmd = virCommandNew(swtpm_setup);
if (!cmd)
return -1;
virCommandAddArgList(cmd, "--create-config-files", "skip-if-exist", NULL); virCommandAddArgList(cmd, "--create-config-files", "skip-if-exist", NULL);
virCommandClearCaps(cmd); virCommandClearCaps(cmd);
@ -388,8 +386,6 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
return -1; return -1;
cmd = virCommandNew(swtpm_setup); cmd = virCommandNew(swtpm_setup);
if (!cmd)
return -1;
virUUIDFormat(vmuuid, uuid); virUUIDFormat(vmuuid, uuid);
vmid = g_strdup_printf("%s:%s", vmname, uuid); vmid = g_strdup_printf("%s:%s", vmname, uuid);
@ -500,8 +496,6 @@ qemuTPMEmulatorReconfigure(const char *storagepath,
return 0; return 0;
cmd = virCommandNew(swtpm_setup); cmd = virCommandNew(swtpm_setup);
if (!cmd)
return -1;
virCommandSetUID(cmd, swtpm_user); virCommandSetUID(cmd, swtpm_user);
virCommandSetGID(cmd, swtpm_group); virCommandSetGID(cmd, swtpm_group);
@ -592,8 +586,6 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm,
unlink(tpm->data.emulator.source->data.nix.path); unlink(tpm->data.emulator.source->data.nix.path);
cmd = virCommandNew(swtpm); cmd = virCommandNew(swtpm);
if (!cmd)
goto error;
virCommandClearCaps(cmd); virCommandClearCaps(cmd);
@ -806,8 +798,6 @@ qemuTPMEmulatorStop(const char *swtpmStateDir,
return; return;
cmd = virCommandNew(swtpm_ioctl); cmd = virCommandNew(swtpm_ioctl);
if (!cmd)
return;
virCommandAddArgList(cmd, "--unix", pathname, "-s", NULL); virCommandAddArgList(cmd, "--unix", pathname, "-s", NULL);

View File

@ -133,8 +133,6 @@ int qemuExtVhostUserGPUStart(virQEMUDriver *driver,
goto error; goto error;
cmd = virCommandNew(video->driver->vhost_user_binary); cmd = virCommandNew(video->driver->vhost_user_binary);
if (!cmd)
goto error;
virCommandClearCaps(cmd); virCommandClearCaps(cmd);
virCommandSetPidFile(cmd, pidfile); virCommandSetPidFile(cmd, pidfile);

View File

@ -132,8 +132,7 @@ qemuVirtioFSBuildCommandLine(virQEMUDriverConfig *cfg,
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
g_auto(virBuffer) opts = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) opts = VIR_BUFFER_INITIALIZER;
if (!(cmd = virCommandNew(fs->binary))) cmd = virCommandNew(fs->binary);
return NULL;
virCommandAddArgFormat(cmd, "--fd=%d", *fd); virCommandAddArgFormat(cmd, "--fd=%d", *fd);
virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);

View File

@ -252,8 +252,7 @@ virTPMGetCaps(virTPMBinaryCapsParse capsParse,
{ {
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
if (!(cmd = virCommandNew(exec))) cmd = virCommandNew(exec);
return NULL;
if (param1) if (param1)
virCommandAddArg(cmd, param1); virCommandAddArg(cmd, param1);

View File

@ -116,8 +116,7 @@ testCompareOutputLit(const char *expectData,
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
g_autofree char *errbuf = NULL; g_autofree char *errbuf = NULL;
if (!(cmd = virCommandNewArgs(argv))) cmd = virCommandNewArgs(argv);
return -1;
virCommandAddEnvString(cmd, "LANG=C"); virCommandAddEnvString(cmd, "LANG=C");
virCommandSetInputBuffer(cmd, empty); virCommandSetInputBuffer(cmd, empty);