]>
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 | |
5926d692 | 34 | log_warning("Invalid quotacheck.mode= value, ignoring: %s", value); |
85013844 | 35 | } |
059cb385 | 36 | |
349cc4a5 | 37 | #if HAVE_SYSV_COMPAT |
059cb385 | 38 | else if (streq(key, "forcequotacheck") && !value) { |
5926d692 | 39 | log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line. Proceeding anyway."); |
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 | 50 | if (access("/forcequotacheck", F_OK) >= 0) { |
5926d692 | 51 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system. Proceeding anyway."); |
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 | |
5926d692 MY |
80 | /* This is created by systemd-fsck when fsck detected and corrected errors. In normal |
81 | * operations quotacheck is not needed. */ | |
82 | if (access("/run/systemd/quotacheck", F_OK) < 0) { | |
83 | if (errno != ENOENT) | |
84 | log_warning_errno(errno, | |
85 | "Failed to check whether /run/systemd/quotacheck exists, ignoring: %m"); | |
86 | ||
2ab2a55b | 87 | return 0; |
5926d692 | 88 | } |
3d20ed6d LP |
89 | } |
90 | ||
fc5c6ecc TB |
91 | if (argc == 2) { |
92 | fspath = strdup(argv[1]); | |
93 | if (!fspath) | |
94 | return log_oom(); | |
95 | } else | |
96 | quota_check_all = true; | |
97 | ||
e9ccae31 | 98 | r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_RLIMIT_NOFILE_SAFE|FORK_WAIT|FORK_LOG, NULL); |
b6e1fff1 | 99 | if (r < 0) |
2ab2a55b | 100 | return r; |
fc5c6ecc | 101 | |
4c253ed1 | 102 | if (r == 0) { |
fc5c6ecc | 103 | const char *cmdline[] = { |
1f5d1e02 | 104 | QUOTACHECK, |
fc5c6ecc TB |
105 | quota_check_all ? "-anug" : "-nug", |
106 | fspath, | |
1f5d1e02 LP |
107 | NULL |
108 | }; | |
ce30c8dc | 109 | |
3d20ed6d | 110 | /* Child */ |
ce30c8dc | 111 | |
3d20ed6d | 112 | execv(cmdline[0], (char**) cmdline); |
a45d7127 | 113 | _exit(EXIT_FAILURE); /* Operational error */ |
3d20ed6d LP |
114 | } |
115 | ||
2ab2a55b | 116 | return 0; |
3d20ed6d | 117 | } |
2ab2a55b ZJS |
118 | |
119 | DEFINE_MAIN_FUNCTION(run); |