Fallback lvs comparison to false.

If lvs invocation fails or doesn't return any output, then lv flags comparison to false.

Signed-off-by: Sidnei da Silva <sidnei.da.silva@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Sidnei da Silva 2013-10-21 20:16:32 -02:00 committed by Serge Hallyn
parent 34e135b238
commit 8aba14bbc8

View File

@ -813,7 +813,7 @@ static int lvm_umount(struct bdev *bdev)
static int lvm_compare_lv_attr(const char *path, int pos, const char expected) { static int lvm_compare_lv_attr(const char *path, int pos, const char expected) {
FILE *f; FILE *f;
int ret, len, start=0; int ret, len, status, start=0;
char *cmd, output[12]; char *cmd, output[12];
const char *lvscmd = "lvs --unbuffered --noheadings -o lv_attr %s 2>/dev/null"; const char *lvscmd = "lvs --unbuffered --noheadings -o lv_attr %s 2>/dev/null";
@ -833,21 +833,16 @@ static int lvm_compare_lv_attr(const char *path, int pos, const char expected) {
return -1; return -1;
} }
if (fgets(output, 12, f) == NULL) { ret = fgets(output, 12, f) == NULL;
process_lock();
(void) pclose(f);
process_unlock();
return -1;
}
process_lock(); process_lock();
ret = pclose(f); status = pclose(f);
process_unlock(); process_unlock();
if (!WIFEXITED(ret)) { if (ret || WEXITSTATUS(status))
SYSERROR("error executing lvs"); // Assume either vg or lvs do not exist, default
return -1; // comparison to false.
} return 0;
len = strlen(output); len = strlen(output);
while(start < len && output[start] == ' ') start++; while(start < len && output[start] == ' ') start++;