]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/quotacheck/quotacheck.c
Merge pull request #7582 from pfl/dhcp6_prefix_delegation
[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 systemd is free software; you can redistribute it and/or modify it
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
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
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <errno.h>
22 #include <stdbool.h>
23 #include <stdio.h>
24 #include <sys/prctl.h>
25 #include <unistd.h>
26
27 #include "proc-cmdline.h"
28 #include "process-util.h"
29 #include "signal-util.h"
30 #include "string-util.h"
31 #include "util.h"
32
33 static bool arg_skip = false;
34 static bool arg_force = false;
35
36 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
37
38 if (streq(key, "quotacheck.mode")) {
39
40 if (proc_cmdline_value_missing(key, value))
41 return 0;
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
50 log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
51 }
52
53 #if HAVE_SYSV_COMPAT
54 else if (streq(key, "forcequotacheck") && !value) {
55 log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
56 arg_force = true;
57 }
58 #endif
59
60 return 0;
61 }
62
63 static void test_files(void) {
64
65 #if HAVE_SYSV_COMPAT
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.");
68 arg_force = true;
69 }
70 #endif
71 }
72
73 int main(int argc, char *argv[]) {
74 int r;
75
76 if (argc > 1) {
77 log_error("This program takes no arguments.");
78 return EXIT_FAILURE;
79 }
80
81 log_set_target(LOG_TARGET_AUTO);
82 log_parse_environment();
83 log_open();
84
85 umask(0022);
86
87 r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
88 if (r < 0)
89 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
90
91 test_files();
92
93 if (!arg_force) {
94 if (arg_skip)
95 return EXIT_SUCCESS;
96
97 if (access("/run/systemd/quotacheck", F_OK) < 0)
98 return EXIT_SUCCESS;
99 }
100
101 r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
102 if (r < 0)
103 goto finish;
104 if (r == 0) {
105 static const char * const cmdline[] = {
106 QUOTACHECK,
107 "-anug",
108 NULL
109 };
110
111 /* Child */
112
113 execv(cmdline[0], (char**) cmdline);
114 _exit(EXIT_FAILURE); /* Operational error */
115 }
116
117 finish:
118 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
119 }