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