]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/quotacheck/quotacheck.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / quotacheck / quotacheck.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <stdbool.h>
5 #include <stdio.h>
6 #include <sys/prctl.h>
7 #include <unistd.h>
8
9 #include "proc-cmdline.h"
10 #include "process-util.h"
11 #include "signal-util.h"
12 #include "string-util.h"
13 #include "util.h"
14
15 static bool arg_skip = false;
16 static bool arg_force = false;
17
18 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
19
20 if (streq(key, "quotacheck.mode")) {
21
22 if (proc_cmdline_value_missing(key, value))
23 return 0;
24
25 if (streq(value, "auto"))
26 arg_force = arg_skip = false;
27 else if (streq(value, "force"))
28 arg_force = true;
29 else if (streq(value, "skip"))
30 arg_skip = true;
31 else
32 log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
33 }
34
35 #if HAVE_SYSV_COMPAT
36 else if (streq(key, "forcequotacheck") && !value) {
37 log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
38 arg_force = true;
39 }
40 #endif
41
42 return 0;
43 }
44
45 static void test_files(void) {
46
47 #if HAVE_SYSV_COMPAT
48 if (access("/forcequotacheck", F_OK) >= 0) {
49 log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system.");
50 arg_force = true;
51 }
52 #endif
53 }
54
55 int main(int argc, char *argv[]) {
56 int r;
57
58 if (argc > 1) {
59 log_error("This program takes no arguments.");
60 return EXIT_FAILURE;
61 }
62
63 log_set_target(LOG_TARGET_AUTO);
64 log_parse_environment();
65 log_open();
66
67 umask(0022);
68
69 r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
70 if (r < 0)
71 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
72
73 test_files();
74
75 if (!arg_force) {
76 if (arg_skip)
77 return EXIT_SUCCESS;
78
79 if (access("/run/systemd/quotacheck", F_OK) < 0)
80 return EXIT_SUCCESS;
81 }
82
83 r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
84 if (r < 0)
85 goto finish;
86 if (r == 0) {
87 static const char * const cmdline[] = {
88 QUOTACHECK,
89 "-anug",
90 NULL
91 };
92
93 /* Child */
94
95 execv(cmdline[0], (char**) cmdline);
96 _exit(EXIT_FAILURE); /* Operational error */
97 }
98
99 finish:
100 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
101 }