]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/quotacheck/quotacheck.c
tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
[thirdparty/systemd.git] / src / quotacheck / quotacheck.c
CommitLineData
3d20ed6d
LP
1/***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
3d20ed6d
LP
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 14 Lesser General Public License for more details.
3d20ed6d 15
5430f7f2 16 You should have received a copy of the GNU Lesser General Public License
3d20ed6d
LP
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
3d20ed6d 20#include <errno.h>
07630cea
LP
21#include <stdbool.h>
22#include <stdio.h>
ce30c8dc 23#include <sys/prctl.h>
07630cea 24#include <unistd.h>
3d20ed6d 25
cf0fbc49 26#include "proc-cmdline.h"
0b452006 27#include "process-util.h"
ce30c8dc 28#include "signal-util.h"
07630cea
LP
29#include "string-util.h"
30#include "util.h"
3d20ed6d
LP
31
32static bool arg_skip = false;
33static bool arg_force = false;
34
96287a49 35static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
059cb385
LP
36
37 if (streq(key, "quotacheck.mode") && value) {
38
39 if (streq(value, "auto"))
40 arg_force = arg_skip = false;
41 else if (streq(value, "force"))
42 arg_force = true;
43 else if (streq(value, "skip"))
44 arg_skip = true;
45 else
85013844
LP
46 log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
47 }
059cb385 48
32f992a5 49#ifdef HAVE_SYSV_COMPAT
059cb385
LP
50 else if (streq(key, "forcequotacheck") && !value) {
51 log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
141a79f4 52 arg_force = true;
3d20ed6d 53 }
141a79f4
ZJS
54#endif
55
3d20ed6d
LP
56 return 0;
57}
58
59static void test_files(void) {
85013844 60
32f992a5
LP
61#ifdef HAVE_SYSV_COMPAT
62 if (access("/forcequotacheck", F_OK) >= 0) {
63 log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system.");
3d20ed6d 64 arg_force = true;
32f992a5 65 }
3d20ed6d
LP
66#endif
67}
68
69int main(int argc, char *argv[]) {
83374163 70
3d20ed6d 71 static const char * const cmdline[] = {
83374163 72 QUOTACHECK,
3d20ed6d
LP
73 "-anug",
74 NULL
75 };
76
3d20ed6d 77 pid_t pid;
b5884878 78 int r;
3d20ed6d
LP
79
80 if (argc > 1) {
81 log_error("This program takes no arguments.");
82 return EXIT_FAILURE;
83 }
84
4cfa2c99 85 log_set_target(LOG_TARGET_AUTO);
3d20ed6d
LP
86 log_parse_environment();
87 log_open();
88
4c12626c
LP
89 umask(0022);
90
d7f69e16 91 r = parse_proc_cmdline(parse_proc_cmdline_item, NULL, false);
b5884878 92 if (r < 0)
da927ba9 93 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
b5884878 94
3d20ed6d
LP
95 test_files();
96
97 if (!arg_force) {
3d20ed6d 98 if (arg_skip)
83374163 99 return EXIT_SUCCESS;
3d20ed6d 100
2b583ce6 101 if (access("/run/systemd/quotacheck", F_OK) < 0)
83374163 102 return EXIT_SUCCESS;
3d20ed6d
LP
103 }
104
83374163
LP
105 pid = fork();
106 if (pid < 0) {
56f64d95 107 log_error_errno(errno, "fork(): %m");
83374163 108 return EXIT_FAILURE;
3d20ed6d 109 } else if (pid == 0) {
ce30c8dc 110
3d20ed6d 111 /* Child */
ce30c8dc
LP
112
113 (void) reset_all_signal_handlers();
114 (void) reset_signal_mask();
115 assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
116
3d20ed6d
LP
117 execv(cmdline[0], (char**) cmdline);
118 _exit(1); /* Operational error */
119 }
120
820d3acf 121 r = wait_for_terminate_and_warn("quotacheck", pid, true);
b5884878
LP
122
123 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
3d20ed6d 124}