]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: create_home(): Extract want_btrfs_subvolume()
authorHadi Chokr <hadichokr@icloud.com>
Mon, 20 Jul 2026 11:57:50 +0000 (11:57 +0000)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Tue, 28 Jul 2026 15:11:47 +0000 (17:11 +0200)
Move the condition deciding whether the home directory should be
created as a Btrfs subvolume into a helper function, in preparation
for extending it in a following commit.

While at it, remove superfluous parentheses and an unnecessary cast.

No functional change.

Signed-off-by: Hadi Chokr <hadichokr@icloud.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
src/useradd.c

index fd8e36b8a87871d0cff5780be72bca5c0ef8ae92..9588911c2949aa95ed2d999f3cba17266bb834b0 100644 (file)
@@ -2131,6 +2131,17 @@ usr_update (unsigned long subuid_count, unsigned long subgid_count,
        }
 }
 
+#if WITH_BTRFS
+static bool
+want_btrfs_subvolume(const char *path)
+{
+       if (!subvolflg)
+               return false;
+
+       return strlen(prefix_user_home) - strlen(path) <= 1;
+}
+#endif
+
 /*
  * create_home - create the user's home directory
  *
@@ -2186,7 +2197,7 @@ static void create_home(const struct option_flags *flags)
 
                dir_created = false;
 #if WITH_BTRFS
-               if (subvolflg && (strlen(prefix_user_home) - (int)strlen(path)) <= 1) {
+               if (want_btrfs_subvolume(path)) {
                        char *btrfs_check = strdup(path);
                        struct statfs  sfs;