From 51cfc1f89a78323be6a13ddf40d5ffbd793c7554 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Fri, 3 May 2019 19:33:23 -0700 Subject: [PATCH] libmisc/btrfs: find btrfs command Ubuntu for instance keeps it in /bin, not /sbin. So look for it in our usual places. Signed-off-by: Serge Hallyn --- libmisc/btrfs.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libmisc/btrfs.c b/libmisc/btrfs.c index 7236454a..f6024bfb 100644 --- a/libmisc/btrfs.c +++ b/libmisc/btrfs.c @@ -1,14 +1,36 @@ #include #include #include +#include #include "prototypes.h" +static bool path_exists(const char *p) +{ + int ret; + struct stat sb; + + return stat(p, &sb) == 0; +} + +static const char *btrfs_cmd(void) +{ + const char *btrfs_paths[] = {"/sbin/btrfs", + "/bin/btrfs", "/usr/sbin/btrfs", "/usr/bin/btrfs", NULL}; + const char *p; + int i; + + for (i = 0, p = btrfs_paths[i]; p; i++, p = btrfs_paths[i]) + if (path_exists(p)) + return p; + + return NULL; +} static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const char *arg2) { int status = 0; - const char *cmd = "/sbin/btrfs"; + const char *cmd = btrfs_cmd(); const char *argv[] = { strrchr(cmd, '/'), "subvolume", -- 2.40.0