]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
3d20ed6d | 2 | |
3d20ed6d | 3 | #include <errno.h> |
07630cea LP |
4 | #include <stdbool.h> |
5 | #include <stdio.h> | |
ce30c8dc | 6 | #include <sys/prctl.h> |
07630cea | 7 | #include <unistd.h> |
3d20ed6d | 8 | |
cf0fbc49 | 9 | #include "proc-cmdline.h" |
0b452006 | 10 | #include "process-util.h" |
ce30c8dc | 11 | #include "signal-util.h" |
07630cea LP |
12 | #include "string-util.h" |
13 | #include "util.h" | |
3d20ed6d LP |
14 | |
15 | static bool arg_skip = false; | |
16 | static bool arg_force = false; | |
17 | ||
96287a49 | 18 | static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { |
059cb385 | 19 | |
1d84ad94 LP |
20 | if (streq(key, "quotacheck.mode")) { |
21 | ||
22 | if (proc_cmdline_value_missing(key, value)) | |
23 | return 0; | |
059cb385 LP |
24 | |
25 | if (streq(value, "auto")) | |
26 | arg_force = arg_skip = false; | |
27 | else if (streq(value, "force")) | |
28 | arg_force = true; | |
29 | else if (streq(value, "skip")) | |
30 | arg_skip = true; | |
31 | else | |
85013844 LP |
32 | log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value); |
33 | } | |
059cb385 | 34 | |
349cc4a5 | 35 | #if HAVE_SYSV_COMPAT |
059cb385 LP |
36 | else if (streq(key, "forcequotacheck") && !value) { |
37 | log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line."); | |
141a79f4 | 38 | arg_force = true; |
3d20ed6d | 39 | } |
141a79f4 ZJS |
40 | #endif |
41 | ||
3d20ed6d LP |
42 | return 0; |
43 | } | |
44 | ||
45 | static void test_files(void) { | |
85013844 | 46 | |
349cc4a5 | 47 | #if HAVE_SYSV_COMPAT |
32f992a5 LP |
48 | if (access("/forcequotacheck", F_OK) >= 0) { |
49 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system."); | |
3d20ed6d | 50 | arg_force = true; |
32f992a5 | 51 | } |
3d20ed6d LP |
52 | #endif |
53 | } | |
54 | ||
55 | int main(int argc, char *argv[]) { | |
b5884878 | 56 | int r; |
3d20ed6d LP |
57 | |
58 | if (argc > 1) { | |
59 | log_error("This program takes no arguments."); | |
60 | return EXIT_FAILURE; | |
61 | } | |
62 | ||
4cfa2c99 | 63 | log_set_target(LOG_TARGET_AUTO); |
3d20ed6d LP |
64 | log_parse_environment(); |
65 | log_open(); | |
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) |
83374163 | 77 | return EXIT_SUCCESS; |
3d20ed6d | 78 | |
2b583ce6 | 79 | if (access("/run/systemd/quotacheck", F_OK) < 0) |
83374163 | 80 | return EXIT_SUCCESS; |
3d20ed6d LP |
81 | } |
82 | ||
1f5d1e02 | 83 | r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL); |
b6e1fff1 | 84 | if (r < 0) |
57ab9f89 | 85 | goto finish; |
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 | ||
57ab9f89 | 99 | finish: |
b5884878 | 100 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
3d20ed6d | 101 | } |