]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
3d20ed6d LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
8 | under the terms of the GNU Lesser General Public License as published by |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
3d20ed6d LP |
10 | (at your option) any later version. |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 15 | Lesser General Public License for more details. |
3d20ed6d | 16 | |
5430f7f2 | 17 | You should have received a copy of the GNU Lesser General Public License |
3d20ed6d LP |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
19 | ***/ | |
20 | ||
3d20ed6d | 21 | #include <errno.h> |
07630cea LP |
22 | #include <stdbool.h> |
23 | #include <stdio.h> | |
ce30c8dc | 24 | #include <sys/prctl.h> |
07630cea | 25 | #include <unistd.h> |
3d20ed6d | 26 | |
cf0fbc49 | 27 | #include "proc-cmdline.h" |
0b452006 | 28 | #include "process-util.h" |
ce30c8dc | 29 | #include "signal-util.h" |
07630cea LP |
30 | #include "string-util.h" |
31 | #include "util.h" | |
3d20ed6d LP |
32 | |
33 | static bool arg_skip = false; | |
34 | static bool arg_force = false; | |
35 | ||
96287a49 | 36 | static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { |
059cb385 | 37 | |
1d84ad94 LP |
38 | if (streq(key, "quotacheck.mode")) { |
39 | ||
40 | if (proc_cmdline_value_missing(key, value)) | |
41 | return 0; | |
059cb385 LP |
42 | |
43 | if (streq(value, "auto")) | |
44 | arg_force = arg_skip = false; | |
45 | else if (streq(value, "force")) | |
46 | arg_force = true; | |
47 | else if (streq(value, "skip")) | |
48 | arg_skip = true; | |
49 | else | |
85013844 LP |
50 | log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value); |
51 | } | |
059cb385 | 52 | |
349cc4a5 | 53 | #if HAVE_SYSV_COMPAT |
059cb385 LP |
54 | else if (streq(key, "forcequotacheck") && !value) { |
55 | log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line."); | |
141a79f4 | 56 | arg_force = true; |
3d20ed6d | 57 | } |
141a79f4 ZJS |
58 | #endif |
59 | ||
3d20ed6d LP |
60 | return 0; |
61 | } | |
62 | ||
63 | static void test_files(void) { | |
85013844 | 64 | |
349cc4a5 | 65 | #if HAVE_SYSV_COMPAT |
32f992a5 LP |
66 | if (access("/forcequotacheck", F_OK) >= 0) { |
67 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system."); | |
3d20ed6d | 68 | arg_force = true; |
32f992a5 | 69 | } |
3d20ed6d LP |
70 | #endif |
71 | } | |
72 | ||
73 | int main(int argc, char *argv[]) { | |
83374163 | 74 | |
3d20ed6d | 75 | static const char * const cmdline[] = { |
83374163 | 76 | QUOTACHECK, |
3d20ed6d LP |
77 | "-anug", |
78 | NULL | |
79 | }; | |
80 | ||
3d20ed6d | 81 | pid_t pid; |
b5884878 | 82 | int r; |
3d20ed6d LP |
83 | |
84 | if (argc > 1) { | |
85 | log_error("This program takes no arguments."); | |
86 | return EXIT_FAILURE; | |
87 | } | |
88 | ||
4cfa2c99 | 89 | log_set_target(LOG_TARGET_AUTO); |
3d20ed6d LP |
90 | log_parse_environment(); |
91 | log_open(); | |
92 | ||
4c12626c LP |
93 | umask(0022); |
94 | ||
1d84ad94 | 95 | r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0); |
b5884878 | 96 | if (r < 0) |
da927ba9 | 97 | log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); |
b5884878 | 98 | |
3d20ed6d LP |
99 | test_files(); |
100 | ||
101 | if (!arg_force) { | |
3d20ed6d | 102 | if (arg_skip) |
83374163 | 103 | return EXIT_SUCCESS; |
3d20ed6d | 104 | |
2b583ce6 | 105 | if (access("/run/systemd/quotacheck", F_OK) < 0) |
83374163 | 106 | return EXIT_SUCCESS; |
3d20ed6d LP |
107 | } |
108 | ||
b6e1fff1 LP |
109 | r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG, &pid); |
110 | if (r < 0) | |
57ab9f89 | 111 | goto finish; |
4c253ed1 | 112 | if (r == 0) { |
ce30c8dc | 113 | |
3d20ed6d | 114 | /* Child */ |
ce30c8dc | 115 | |
3d20ed6d | 116 | execv(cmdline[0], (char**) cmdline); |
a45d7127 | 117 | _exit(EXIT_FAILURE); /* Operational error */ |
3d20ed6d LP |
118 | } |
119 | ||
7d4904fe | 120 | r = wait_for_terminate_and_check("quotacheck", pid, WAIT_LOG); |
b5884878 | 121 | |
57ab9f89 | 122 | finish: |
b5884878 | 123 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
3d20ed6d | 124 | } |