]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Check stderr when matching parted output
authorHao Liu <hliu@redhat.com>
Wed, 10 Dec 2014 07:14:26 +0000 (15:14 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Dec 2014 09:55:23 +0000 (10:55 +0100)
In old version of parted like parted-2.1-25, error message is shown in
stdout when printing a disk info without disk label.

    Error: /dev/sda: unrecognised disk label

This line has been moved to stderr in newer version of parted. So we
should check both stdout and stderr when locating this message.

This should fix bug:
    https://bugzilla.redhat.com/show_bug.cgi?id=1172468

Signed-off-by: Hao Liu <hliu@redhat.com>
src/storage/storage_backend_disk.c

index 4b05e8c3b50225e0b593be411ce3f462e7aef057..3f97fd9bfea72d92234cfbcd011b642036cc5c3d 100644 (file)
@@ -370,21 +370,26 @@ virStorageBackendDiskFindLabel(const char* device)
     };
     virCommandPtr cmd = virCommandNew(PARTED);
     char *output = NULL;
+    char *error = NULL;
     int ret = -1;
 
     virCommandAddArgSet(cmd, args);
     virCommandAddEnvString(cmd, "LC_ALL=C");
     virCommandSetOutputBuffer(cmd, &output);
+    virCommandSetErrorBuffer(cmd, &error);
 
     /* if parted succeeds we have a valid partition table */
     ret = virCommandRun(cmd, NULL);
     if (ret < 0) {
-        if (strstr(output, "unrecognised disk label"))
+        if (strstr(output, "unrecognised disk label") ||
+            strstr(error, "unrecognised disk label")) {
             ret = 1;
+        }
     }
 
     virCommandFree(cmd);
     VIR_FREE(output);
+    VIR_FREE(error);
     return ret;
 }