]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/btrfs.c: Remove hardcoded Paths and resolve them via env to increase portability
authorHadi Chokr <hadichokr@icloud.com>
Sat, 24 Jan 2026 17:54:33 +0000 (18:54 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 20 Feb 2026 01:32:14 +0000 (19:32 -0600)
Signed-off-by: Hadi Chokr <hadichokr@icloud.com>
lib/btrfs.c

index 03915981cfff2b44313e6ec69fe209e85b2c1d8f..85ec7dbc489ed9ba3d2896b009d1b96f525b0040 100644 (file)
@@ -5,32 +5,16 @@
 
 #include "prototypes.h"
 
-static bool path_exists(const char *p)
-{
-       struct stat sb;
-
-       return stat(p, &sb) == 0;
-}
-
-static const char *btrfs_cmd(void)
-{
-       const char *const 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;
+#define PATH_ENV  "/usr/bin/env"
 
-       return NULL;
-}
 
 static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const char *arg2)
 {
        int status = 0;
-       const char *cmd = btrfs_cmd();
+       const char *cmd = PATH_ENV;
        const char *argv[] = {
+               "env",
                "btrfs",
                "subvolume",
                subcmd,
@@ -39,12 +23,12 @@ static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const c
                NULL
        };
 
-       if (!cmd || access(cmd, X_OK)) {
+       if (access(cmd, X_OK) == -1)
                return 1;
-       }
 
        if (run_command(cmd, argv, NULL, &status))
                return -1;
+
        return status;
 }