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