int lvm_compare_lv_attr(const char *path, int pos, const char expected) { struct lxc_popen_FILE *f; int ret, status; size_t len; char *cmd; char output[12]; int start = 0; const char *lvscmd = "lvs --unbuffered --noheadings -o lv_attr %s 2>/dev/null"; len = strlen(lvscmd) + strlen(path) + 1; cmd = alloca(len); ret = snprintf(cmd, len, lvscmd, path); if (ret < 0 || (size_t)ret >= len) return -1; f = lxc_popen(cmd); if (!f) { SYSERROR("popen failed"); return -1; } ret = 0; if (!fgets(output, 12, f->f)) ret = 1; status = lxc_pclose(f); /* Assume either vg or lvs do not exist, default comparison to false. */ if (ret || WEXITSTATUS(status)) return 0; len = strlen(output); while (start < len && output[start] == ' ') start++; if (start + pos < len && output[start + pos] == expected) return 1; return 0; }
int zfs_list_entry(const char *path, char *output, size_t inlen) { struct lxc_popen_FILE *f; int found=0; f = lxc_popen("zfs list 2> /dev/null"); if (f == NULL) { SYSERROR("popen failed"); return 0; } while (fgets(output, inlen, f->f)) { if (strstr(output, path)) { found = 1; break; } } (void) lxc_pclose(f); return found; }