]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/quotacheck/quotacheck.c
log: introduce new helper call log_setup_service()
[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 log_error("This program takes no arguments.");
63 return -EINVAL;
64 }
65
66 umask(0022);
67
68 r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
69 if (r < 0)
70 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
71
72 test_files();
73
74 if (!arg_force) {
75 if (arg_skip)
76 return 0;
77
78 if (access("/run/systemd/quotacheck", F_OK) < 0)
79 return 0;
80 }
81
82 r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
83 if (r < 0)
84 return r;
85 if (r == 0) {
86 static const char * const cmdline[] = {
87 QUOTACHECK,
88 "-anug",
89 NULL
90 };
91
92 /* Child */
93
94 execv(cmdline[0], (char**) cmdline);
95 _exit(EXIT_FAILURE); /* Operational error */
96 }
97
98 return 0;
99 }
100
101 DEFINE_MAIN_FUNCTION(run);