1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virStorageBackendIQNFound: Fix ret value assignment

Perform some method clean-up to follow more accepted coding standards:

 * Initialize @ret to error value and prove otherwise.
 * Initialize *ifacename to NULL

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Michal Privoznik 2018-06-29 10:12:58 +02:00
parent 0dc8ecbf1d
commit 893ccaeca4

View File

@ -117,15 +117,16 @@ static int
virStorageBackendIQNFound(const char *initiatoriqn, virStorageBackendIQNFound(const char *initiatoriqn,
char **ifacename) char **ifacename)
{ {
int ret = IQN_MISSING, fd = -1; int ret = IQN_ERROR, fd = -1;
char ebuf[64]; char ebuf[64];
FILE *fp = NULL; FILE *fp = NULL;
char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL; char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL;
virCommandPtr cmd = virCommandNewArgList(ISCSIADM, virCommandPtr cmd = virCommandNewArgList(ISCSIADM,
"--mode", "iface", NULL); "--mode", "iface", NULL);
*ifacename = NULL;
if (VIR_ALLOC_N(line, LINE_SIZE) != 0) { if (VIR_ALLOC_N(line, LINE_SIZE) != 0) {
ret = IQN_ERROR;
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not allocate memory for output of '%s'"), _("Could not allocate memory for output of '%s'"),
ISCSIADM); ISCSIADM);
@ -135,24 +136,20 @@ virStorageBackendIQNFound(const char *initiatoriqn,
memset(line, 0, LINE_SIZE); memset(line, 0, LINE_SIZE);
virCommandSetOutputFD(cmd, &fd); virCommandSetOutputFD(cmd, &fd);
if (virCommandRunAsync(cmd, NULL) < 0) { if (virCommandRunAsync(cmd, NULL) < 0)
ret = IQN_ERROR;
goto out; goto out;
}
if ((fp = VIR_FDOPEN(fd, "r")) == NULL) { if ((fp = VIR_FDOPEN(fd, "r")) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open stream for file descriptor " _("Failed to open stream for file descriptor "
"when reading output from '%s': '%s'"), "when reading output from '%s': '%s'"),
ISCSIADM, virStrerror(errno, ebuf, sizeof(ebuf))); ISCSIADM, virStrerror(errno, ebuf, sizeof(ebuf)));
ret = IQN_ERROR;
goto out; goto out;
} }
while (fgets(line, LINE_SIZE, fp) != NULL) { while (fgets(line, LINE_SIZE, fp) != NULL) {
newline = strrchr(line, '\n'); newline = strrchr(line, '\n');
if (newline == NULL) { if (newline == NULL) {
ret = IQN_ERROR;
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected line > %d characters " _("Unexpected line > %d characters "
"when parsing output of '%s'"), "when parsing output of '%s'"),
@ -169,24 +166,24 @@ virStorageBackendIQNFound(const char *initiatoriqn,
if (STREQ(iqn, initiatoriqn)) { if (STREQ(iqn, initiatoriqn)) {
token = strchr(line, ' '); token = strchr(line, ' ');
if (!token) { if (!token) {
ret = IQN_ERROR;
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing space when parsing output " _("Missing space when parsing output "
"of '%s'"), ISCSIADM); "of '%s'"), ISCSIADM);
goto out; goto out;
} }
if (VIR_STRNDUP(*ifacename, line, token - line) < 0) {
ret = IQN_ERROR; if (VIR_STRNDUP(*ifacename, line, token - line) < 0)
goto out; goto out;
}
VIR_DEBUG("Found interface '%s' with IQN '%s'", *ifacename, iqn); VIR_DEBUG("Found interface '%s' with IQN '%s'", *ifacename, iqn);
ret = IQN_FOUND;
break; break;
} }
} }
if (virCommandWait(cmd, NULL) < 0) if (virCommandWait(cmd, NULL) < 0)
ret = IQN_ERROR; goto out;
ret = *ifacename ? IQN_FOUND : IQN_MISSING;
out: out:
if (ret == IQN_MISSING) if (ret == IQN_MISSING)