]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/quotacheck/quotacheck.c
process-spec: add another flag FORK_WAIT to safe_fork()
[thirdparty/systemd.git] / src / quotacheck / quotacheck.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
3d20ed6d
LP
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
5430f7f2
LP
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
3d20ed6d
LP
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
5430f7f2 15 Lesser General Public License for more details.
3d20ed6d 16
5430f7f2 17 You should have received a copy of the GNU Lesser General Public License
3d20ed6d
LP
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
3d20ed6d 21#include <errno.h>
07630cea
LP
22#include <stdbool.h>
23#include <stdio.h>
ce30c8dc 24#include <sys/prctl.h>
07630cea 25#include <unistd.h>
3d20ed6d 26
cf0fbc49 27#include "proc-cmdline.h"
0b452006 28#include "process-util.h"
ce30c8dc 29#include "signal-util.h"
07630cea
LP
30#include "string-util.h"
31#include "util.h"
3d20ed6d
LP
32
33static bool arg_skip = false;
34static bool arg_force = false;
35
96287a49 36static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
059cb385 37
1d84ad94
LP
38 if (streq(key, "quotacheck.mode")) {
39
40 if (proc_cmdline_value_missing(key, value))
41 return 0;
059cb385
LP
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
85013844
LP
50 log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
51 }
059cb385 52
349cc4a5 53#if HAVE_SYSV_COMPAT
059cb385
LP
54 else if (streq(key, "forcequotacheck") && !value) {
55 log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
141a79f4 56 arg_force = true;
3d20ed6d 57 }
141a79f4
ZJS
58#endif
59
3d20ed6d
LP
60 return 0;
61}
62
63static void test_files(void) {
85013844 64
349cc4a5 65#if HAVE_SYSV_COMPAT
32f992a5
LP
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.");
3d20ed6d 68 arg_force = true;
32f992a5 69 }
3d20ed6d
LP
70#endif
71}
72
73int main(int argc, char *argv[]) {
b5884878 74 int r;
3d20ed6d
LP
75
76 if (argc > 1) {
77 log_error("This program takes no arguments.");
78 return EXIT_FAILURE;
79 }
80
4cfa2c99 81 log_set_target(LOG_TARGET_AUTO);
3d20ed6d
LP
82 log_parse_environment();
83 log_open();
84
4c12626c
LP
85 umask(0022);
86
1d84ad94 87 r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
b5884878 88 if (r < 0)
da927ba9 89 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
b5884878 90
3d20ed6d
LP
91 test_files();
92
93 if (!arg_force) {
3d20ed6d 94 if (arg_skip)
83374163 95 return EXIT_SUCCESS;
3d20ed6d 96
2b583ce6 97 if (access("/run/systemd/quotacheck", F_OK) < 0)
83374163 98 return EXIT_SUCCESS;
3d20ed6d
LP
99 }
100
1f5d1e02 101 r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
b6e1fff1 102 if (r < 0)
57ab9f89 103 goto finish;
4c253ed1 104 if (r == 0) {
1f5d1e02
LP
105 static const char * const cmdline[] = {
106 QUOTACHECK,
107 "-anug",
108 NULL
109 };
ce30c8dc 110
3d20ed6d 111 /* Child */
ce30c8dc 112
3d20ed6d 113 execv(cmdline[0], (char**) cmdline);
a45d7127 114 _exit(EXIT_FAILURE); /* Operational error */
3d20ed6d
LP
115 }
116
57ab9f89 117finish:
b5884878 118 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
3d20ed6d 119}