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;
}
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;
}
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';
}
}
+ if (virCommandWait(cmd, NULL) < 0)
+ ret = IQN_ERROR;
+
out:
if (ret == IQN_MISSING) {
VIR_DEBUG("Could not find interface with IQN '%s'", iqn);
VIR_FREE(line);
VIR_FORCE_FCLOSE(fp);
VIR_FORCE_CLOSE(fd);
+ virCommandFree(cmd);
return ret;
}