Add autotools support for BtrFS option

Feature is enabled by default, if headers are available. It can be
turned off explictly.
This commit is contained in:
Adam Majer
2019-01-23 16:17:05 +01:00
committed by Serge Hallyn
parent c1d36a8acb
commit 50b23584d7
6 changed files with 39 additions and 3 deletions

View File

@ -823,7 +823,9 @@ static void usage (int status)
Prog, Prog, Prog);
(void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n"
" new account\n"), usageout);
#ifdef WITH_BTRFS
(void) fputs (_(" --btrfs-subvolume-home use BTRFS subvolume for home directory\n"), usageout);
#endif
(void) fputs (_(" -c, --comment COMMENT GECOS field of the new account\n"), usageout);
(void) fputs (_(" -d, --home-dir HOME_DIR home directory of the new account\n"), usageout);
(void) fputs (_(" -D, --defaults print or change default useradd configuration\n"), usageout);
@ -1104,7 +1106,9 @@ static void process_flags (int argc, char **argv)
int c;
static struct option long_options[] = {
{"base-dir", required_argument, NULL, 'b'},
#ifdef WITH_BTRFS
{"btrfs-subvolume-home", no_argument, NULL, 200},
#endif
{"comment", required_argument, NULL, 'c'},
{"home-dir", required_argument, NULL, 'd'},
{"defaults", no_argument, NULL, 'D'},
@ -2083,6 +2087,7 @@ static void create_home (void)
subvolume but no BTRFS. The paths cound be different by the
trailing slash
*/
#if WITH_BTRFS
if (subvolflg && (strlen(prefix_user_home) - (int)strlen(path)) <= 1) {
char *btrfs_check = strdup(path);
@ -2107,7 +2112,9 @@ static void create_home (void)
fail_exit (E_HOMEDIR);
}
}
else if (mkdir (path, 0) != 0) {
else
#endif
if (mkdir (path, 0) != 0) {
fprintf (stderr,
_("%s: cannot create directory %s\n"),
Prog, path);

View File

@ -1272,6 +1272,7 @@ int main (int argc, char **argv)
#endif /* EXTRA_CHECK_HOME_DIR */
if (rflg) {
#ifdef WITH_BTRFS
int is_subvolume = btrfs_is_subvolume (user_home);
if (is_subvolume < 0) {
errors++;
@ -1286,7 +1287,9 @@ int main (int argc, char **argv)
/* continue */
}
}
else if (remove_tree (user_home, true) != 0) {
else
#endif
if (remove_tree (user_home, true) != 0) {
fprintf (stderr,
_("%s: error removing directory %s\n"),
Prog, user_home);

View File

@ -1819,12 +1819,14 @@ static void move_home (void)
return;
} else {
if (EXDEV == errno) {
#ifdef WITH_BTRFS
if (btrfs_is_subvolume (prefix_user_home) > 0) {
fprintf (stderr,
_("%s: error: cannot move subvolume from %s to %s - different device\n"),
Prog, prefix_user_home, prefix_user_newhome);
fail_exit (E_HOMEDIR);
}
#endif
if (copy_tree (prefix_user_home, prefix_user_newhome, true,
true,