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 <shallyn@cisco.com>
This commit is contained in:
Serge Hallyn 2019-05-03 19:33:23 -07:00
parent 816220f90c
commit 51cfc1f89a

View File

@ -1,14 +1,36 @@
#include <linux/btrfs_tree.h> #include <linux/btrfs_tree.h>
#include <linux/magic.h> #include <linux/magic.h>
#include <sys/statfs.h> #include <sys/statfs.h>
#include <stdbool.h>
#include "prototypes.h" #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) static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const char *arg2)
{ {
int status = 0; int status = 0;
const char *cmd = "/sbin/btrfs"; const char *cmd = btrfs_cmd();
const char *argv[] = { const char *argv[] = {
strrchr(cmd, '/'), strrchr(cmd, '/'),
"subvolume", "subvolume",