X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fblkid.c;h=7935ac3fc5bb9c15201d28f136cd2336fa11a6f0;hp=2885a8f30c3f0c607ed7b3536b6ec01d5c487123;hb=19005b2cfc6b077aafd16cb5b97a08180e4e39f8;hpb=5d7ee3f0c5b65cc7c417d762a648ce6c5bfdb532 diff --git a/daemon/blkid.c b/daemon/blkid.c index 2885a8f..7935ac3 100644 --- a/daemon/blkid.c +++ b/daemon/blkid.c @@ -33,18 +33,16 @@ get_blkid_tag (const char *device, const char *tag) char *out, *err; int r; - /* Kill the cache file, forcing blkid to reread values from the - * original filesystems. In blkid there is a '-p' option which is - * supposed to do this, but (a) it doesn't work and (b) that option - * is not supported in RHEL 5. - */ - unlink ("/etc/blkid/blkid.tab"); /* Red Hat, Fedora */ - unlink ("/etc/blkid.tab"); /* Debian */ - - r = command (&out, &err, - "blkid", "-o", "value", "-s", tag, device, NULL); - if (r == -1) { - reply_with_error ("%s: %s", device, err); + r = commandr (&out, &err, + "blkid", + /* Adding -c option kills all caching, even on RHEL 5. */ + "-c", "/dev/null", + "-o", "value", "-s", tag, device, NULL); + if (r != 0 && r != 2) { + if (r >= 0) + reply_with_error ("%s: %s (blkid returned %d)", device, err, r); + else + reply_with_error ("%s: %s", device, err); free (out); free (err); return NULL; @@ -52,6 +50,14 @@ get_blkid_tag (const char *device, const char *tag) free (err); + if (r == 2) { /* means UUID etc not found */ + free (out); + out = strdup (""); + if (out == NULL) + reply_with_perror ("strdup"); + return out; + } + /* Trim trailing \n if present. */ size_t len = strlen (out); if (len > 0 && out[len-1] == '\n')