mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
storage: iscsi: Convert virExec to virCommand
v2: Use virCommand auto-cleanup
This commit is contained in:
parent
5b77f1d5dc
commit
1fcafb02e2
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user