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