]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
3d20ed6d | 2 | |
3d20ed6d | 3 | #include <errno.h> |
07630cea LP |
4 | #include <stdbool.h> |
5 | #include <stdio.h> | |
ce30c8dc | 6 | #include <sys/prctl.h> |
ca78ad1d ZJS |
7 | #include <sys/stat.h> |
8 | #include <sys/types.h> | |
07630cea | 9 | #include <unistd.h> |
3d20ed6d | 10 | |
5e332028 | 11 | #include "main-func.h" |
cf0fbc49 | 12 | #include "proc-cmdline.h" |
0b452006 | 13 | #include "process-util.h" |
ce30c8dc | 14 | #include "signal-util.h" |
07630cea LP |
15 | #include "string-util.h" |
16 | #include "util.h" | |
3d20ed6d LP |
17 | |
18 | static bool arg_skip = false; | |
19 | static bool arg_force = false; | |
20 | ||
96287a49 | 21 | static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { |
059cb385 | 22 | |
1d84ad94 LP |
23 | if (streq(key, "quotacheck.mode")) { |
24 | ||
25 | if (proc_cmdline_value_missing(key, value)) | |
26 | return 0; | |
059cb385 LP |
27 | |
28 | if (streq(value, "auto")) | |
29 | arg_force = arg_skip = false; | |
30 | else if (streq(value, "force")) | |
31 | arg_force = true; | |
32 | else if (streq(value, "skip")) | |
33 | arg_skip = true; | |
34 | else | |
85013844 LP |
35 | log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value); |
36 | } | |
059cb385 | 37 | |
349cc4a5 | 38 | #if HAVE_SYSV_COMPAT |
059cb385 LP |
39 | else if (streq(key, "forcequotacheck") && !value) { |
40 | log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line."); | |
141a79f4 | 41 | arg_force = true; |
3d20ed6d | 42 | } |
141a79f4 ZJS |
43 | #endif |
44 | ||
3d20ed6d LP |
45 | return 0; |
46 | } | |
47 | ||
48 | static void test_files(void) { | |
85013844 | 49 | |
349cc4a5 | 50 | #if HAVE_SYSV_COMPAT |
32f992a5 LP |
51 | if (access("/forcequotacheck", F_OK) >= 0) { |
52 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system."); | |
3d20ed6d | 53 | arg_force = true; |
32f992a5 | 54 | } |
3d20ed6d LP |
55 | #endif |
56 | } | |
57 | ||
2ab2a55b | 58 | static int run(int argc, char *argv[]) { |
b5884878 | 59 | int r; |
3d20ed6d | 60 | |
6bf3c61c | 61 | log_setup_service(); |
3d20ed6d | 62 | |
baaa35ad ZJS |
63 | if (argc > 1) |
64 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
65 | "This program takes no arguments."); | |
2ab2a55b | 66 | |
4c12626c LP |
67 | umask(0022); |
68 | ||
1d84ad94 | 69 | r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0); |
b5884878 | 70 | if (r < 0) |
da927ba9 | 71 | log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); |
b5884878 | 72 | |
3d20ed6d LP |
73 | test_files(); |
74 | ||
75 | if (!arg_force) { | |
3d20ed6d | 76 | if (arg_skip) |
2ab2a55b | 77 | return 0; |
3d20ed6d | 78 | |
2b583ce6 | 79 | if (access("/run/systemd/quotacheck", F_OK) < 0) |
2ab2a55b | 80 | return 0; |
3d20ed6d LP |
81 | } |
82 | ||
0672e2c6 | 83 | r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_RLIMIT_NOFILE_SAFE|FORK_WAIT|FORK_LOG, NULL); |
b6e1fff1 | 84 | if (r < 0) |
2ab2a55b | 85 | return r; |
4c253ed1 | 86 | if (r == 0) { |
1f5d1e02 LP |
87 | static const char * const cmdline[] = { |
88 | QUOTACHECK, | |
89 | "-anug", | |
90 | NULL | |
91 | }; | |
ce30c8dc | 92 | |
3d20ed6d | 93 | /* Child */ |
ce30c8dc | 94 | |
3d20ed6d | 95 | execv(cmdline[0], (char**) cmdline); |
a45d7127 | 96 | _exit(EXIT_FAILURE); /* Operational error */ |
3d20ed6d LP |
97 | } |
98 | ||
2ab2a55b | 99 | return 0; |
3d20ed6d | 100 | } |
2ab2a55b ZJS |
101 | |
102 | DEFINE_MAIN_FUNCTION(run); |