提交 f025c1bf 编写于 作者: A Andrea Bolognani

util: Fix virStorageBackendIQNFound() to work on FreeBSD

Despite being standardized in POSIX.1-2008, the 'm'
sscanf() modifier is currently not available on FreeBSD.

Reimplement parsing without sscanf() to work around the
issue.
Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
上级 f2695846
...@@ -146,8 +146,10 @@ virStorageBackendIQNFound(const char *initiatoriqn, ...@@ -146,8 +146,10 @@ virStorageBackendIQNFound(const char *initiatoriqn,
line = outbuf; line = outbuf;
while (line && *line) { while (line && *line) {
char *current = line;
char *newline; char *newline;
int num; char *next;
size_t i;
if (!(newline = strchr(line, '\n'))) if (!(newline = strchr(line, '\n')))
break; break;
...@@ -156,15 +158,29 @@ virStorageBackendIQNFound(const char *initiatoriqn, ...@@ -156,15 +158,29 @@ virStorageBackendIQNFound(const char *initiatoriqn,
VIR_FREE(iface); VIR_FREE(iface);
VIR_FREE(iqn); VIR_FREE(iqn);
num = sscanf(line, "%ms %*[^,],%*[^,],%*[^,],%*[^,],%ms", &iface, &iqn);
if (num != 2) { /* Find the first space, copy everything up to that point into
virReportError(VIR_ERR_INTERNAL_ERROR, * iface and move past it to continue processing */
_("malformed output of %s: %s"), if (!(next = strchr(current, ' ')))
ISCSIADM, line); goto error;
if (VIR_STRNDUP(iface, current, (next - current)) < 0)
goto cleanup; goto cleanup;
current = next + 1;
/* There are five comma separated fields after iface and we only
* care about the last one, so we need to skip four commas and
* copy whatever's left into iqn */
for (i = 0; i < 4; i++) {
if (!(next = strchr(current, ',')))
goto error;
current = next + 1;
} }
if (VIR_STRDUP(iqn, current) < 0)
goto cleanup;
if (STREQ(iqn, initiatoriqn)) { if (STREQ(iqn, initiatoriqn)) {
VIR_STEAL_PTR(*ifacename, iface); VIR_STEAL_PTR(*ifacename, iface);
...@@ -186,6 +202,12 @@ virStorageBackendIQNFound(const char *initiatoriqn, ...@@ -186,6 +202,12 @@ virStorageBackendIQNFound(const char *initiatoriqn,
VIR_FREE(outbuf); VIR_FREE(outbuf);
virCommandFree(cmd); virCommandFree(cmd);
return ret; return ret;
error:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("malformed output of %s: %s"),
ISCSIADM, line);
goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册