]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/quotacheck/quotacheck.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / quotacheck / quotacheck.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
3d20ed6d 2
3d20ed6d 3#include <errno.h>
07630cea
LP
4#include <stdbool.h>
5#include <stdio.h>
ce30c8dc 6#include <sys/prctl.h>
07630cea 7#include <unistd.h>
3d20ed6d 8
5e332028 9#include "main-func.h"
cf0fbc49 10#include "proc-cmdline.h"
0b452006 11#include "process-util.h"
ce30c8dc 12#include "signal-util.h"
07630cea
LP
13#include "string-util.h"
14#include "util.h"
3d20ed6d
LP
15
16static bool arg_skip = false;
17static bool arg_force = false;
18
96287a49 19static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
059cb385 20
1d84ad94
LP
21 if (streq(key, "quotacheck.mode")) {
22
23 if (proc_cmdline_value_missing(key, value))
24 return 0;
059cb385
LP
25
26 if (streq(value, "auto"))
27 arg_force = arg_skip = false;
28 else if (streq(value, "force"))
29 arg_force = true;
30 else if (streq(value, "skip"))
31 arg_skip = true;
32 else
85013844
LP
33 log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
34 }
059cb385 35
349cc4a5 36#if HAVE_SYSV_COMPAT
059cb385
LP
37 else if (streq(key, "forcequotacheck") && !value) {
38 log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
141a79f4 39 arg_force = true;
3d20ed6d 40 }
141a79f4
ZJS
41#endif
42
3d20ed6d
LP
43 return 0;
44}
45
46static void test_files(void) {
85013844 47
349cc4a5 48#if HAVE_SYSV_COMPAT
32f992a5
LP
49 if (access("/forcequotacheck", F_OK) >= 0) {
50 log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system.");
3d20ed6d 51 arg_force = true;
32f992a5 52 }
3d20ed6d
LP
53#endif
54}
55
2ab2a55b 56static int run(int argc, char *argv[]) {
b5884878 57 int r;
3d20ed6d 58
6bf3c61c 59 log_setup_service();
3d20ed6d 60
baaa35ad
ZJS
61 if (argc > 1)
62 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
63 "This program takes no arguments.");
2ab2a55b 64
4c12626c
LP
65 umask(0022);
66
1d84ad94 67 r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
b5884878 68 if (r < 0)
da927ba9 69 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
b5884878 70
3d20ed6d
LP
71 test_files();
72
73 if (!arg_force) {
3d20ed6d 74 if (arg_skip)
2ab2a55b 75 return 0;
3d20ed6d 76
2b583ce6 77 if (access("/run/systemd/quotacheck", F_OK) < 0)
2ab2a55b 78 return 0;
3d20ed6d
LP
79 }
80
0672e2c6 81 r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_RLIMIT_NOFILE_SAFE|FORK_WAIT|FORK_LOG, NULL);
b6e1fff1 82 if (r < 0)
2ab2a55b 83 return r;
4c253ed1 84 if (r == 0) {
1f5d1e02
LP
85 static const char * const cmdline[] = {
86 QUOTACHECK,
87 "-anug",
88 NULL
89 };
ce30c8dc 90
3d20ed6d 91 /* Child */
ce30c8dc 92
3d20ed6d 93 execv(cmdline[0], (char**) cmdline);
a45d7127 94 _exit(EXIT_FAILURE); /* Operational error */
3d20ed6d
LP
95 }
96
2ab2a55b 97 return 0;
3d20ed6d 98}
2ab2a55b
ZJS
99
100DEFINE_MAIN_FUNCTION(run);