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