diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index ec52dbc9c4ad97e269f9b0c4b9dfff13c1534a6f..bdd58cde2e7e2c3208ba68d2e71d5c54018c6886 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -184,28 +184,23 @@ virStorageBackendIQNFound(const char *initiatoriqn, int ret = IQN_MISSING, fd = -1; char ebuf[64]; FILE *fp = NULL; - pid_t child = 0; char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL, *saveptr = NULL; - const char *const prog[] = { - ISCSIADM, "--mode", "iface", NULL - }; + virCommandPtr cmd = virCommandNewArgList(ISCSIADM, + "--mode", "iface", NULL); if (VIR_ALLOC_N(line, LINE_SIZE) != 0) { ret = IQN_ERROR; virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Could not allocate memory for output of '%s'"), - prog[0]); + ISCSIADM); goto out; } memset(line, 0, LINE_SIZE); - if (virExec(prog, NULL, NULL, &child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) { - virStorageReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to run '%s' when looking for existing interface with IQN '%s'"), - prog[0], initiatoriqn); - + virCommandSetOutputFD(cmd, &fd); + if (virCommandRunAsync(cmd, NULL) < 0) { ret = IQN_ERROR; goto out; } @@ -214,7 +209,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open stream for file descriptor " "when reading output from '%s': '%s'"), - prog[0], virStrerror(errno, ebuf, sizeof ebuf)); + ISCSIADM, virStrerror(errno, ebuf, sizeof ebuf)); ret = IQN_ERROR; goto out; } @@ -226,7 +221,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, virStorageReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected line > %d characters " "when parsing output of '%s'"), - LINE_SIZE, prog[0]); + LINE_SIZE, ISCSIADM); goto out; } *newline = '\0'; @@ -251,6 +246,9 @@ virStorageBackendIQNFound(const char *initiatoriqn, } } + if (virCommandWait(cmd, NULL) < 0) + ret = IQN_ERROR; + out: if (ret == IQN_MISSING) { VIR_DEBUG("Could not find interface with IQN '%s'", iqn); @@ -259,6 +257,7 @@ out: VIR_FREE(line); VIR_FORCE_FCLOSE(fp); VIR_FORCE_CLOSE(fd); + virCommandFree(cmd); return ret; }