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