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