]> git.proxmox.com Git - systemd.git/blame - src/quotacheck/quotacheck.c
bump version to 252.11-pve1
[systemd.git] / src / quotacheck / quotacheck.c
CommitLineData
a032b68d 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
663996b3 2
663996b3 3#include <errno.h>
db2df898
MP
4#include <stdbool.h>
5#include <stdio.h>
86f210e9 6#include <sys/prctl.h>
bb4f798a
MB
7#include <sys/stat.h>
8#include <sys/types.h>
db2df898 9#include <unistd.h>
663996b3 10
6e866b33 11#include "main-func.h"
db2df898 12#include "proc-cmdline.h"
e3bff60a 13#include "process-util.h"
86f210e9 14#include "signal-util.h"
db2df898
MP
15#include "string-util.h"
16#include "util.h"
663996b3
MS
17
18static bool arg_skip = false;
19static bool arg_force = false;
20
8a584da2 21static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
663996b3 22
2897b343
MP
23 if (streq(key, "quotacheck.mode")) {
24
25 if (proc_cmdline_value_missing(key, value))
26 return 0;
663996b3 27
60f067b4 28 if (streq(value, "auto"))
663996b3 29 arg_force = arg_skip = false;
60f067b4 30 else if (streq(value, "force"))
663996b3 31 arg_force = true;
60f067b4 32 else if (streq(value, "skip"))
663996b3 33 arg_skip = true;
60f067b4 34 else
e842803a
MB
35 log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
36 }
60f067b4 37
f5e65279 38#if HAVE_SYSV_COMPAT
60f067b4
JS
39 else if (streq(key, "forcequotacheck") && !value) {
40 log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
41 arg_force = true;
663996b3 42 }
60f067b4
JS
43#endif
44
663996b3
MS
45 return 0;
46}
47
48static void test_files(void) {
e842803a 49
f5e65279 50#if HAVE_SYSV_COMPAT
663996b3
MS
51 if (access("/forcequotacheck", F_OK) >= 0) {
52 log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system.");
53 arg_force = true;
54 }
55#endif
56}
57
6e866b33 58static int run(int argc, char *argv[]) {
f47781d8 59 int r;
663996b3 60
3a6ce677 61 log_setup();
663996b3 62
6e866b33
MB
63 if (argc > 1)
64 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
65 "This program takes no arguments.");
663996b3
MS
66
67 umask(0022);
68
2897b343 69 r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
f47781d8
MP
70 if (r < 0)
71 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
72
663996b3
MS
73 test_files();
74
75 if (!arg_force) {
76 if (arg_skip)
6e866b33 77 return 0;
663996b3
MS
78
79 if (access("/run/systemd/quotacheck", F_OK) < 0)
6e866b33 80 return 0;
663996b3
MS
81 }
82
6e866b33 83 r = safe_fork("(quotacheck)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_RLIMIT_NOFILE_SAFE|FORK_WAIT|FORK_LOG, NULL);
1d42b86d 84 if (r < 0)
6e866b33 85 return r;
1d42b86d
MB
86 if (r == 0) {
87 static const char * const cmdline[] = {
88 QUOTACHECK,
89 "-anug",
90 NULL
91 };
86f210e9 92
663996b3 93 /* Child */
86f210e9 94
663996b3 95 execv(cmdline[0], (char**) cmdline);
1d42b86d 96 _exit(EXIT_FAILURE); /* Operational error */
663996b3
MS
97 }
98
6e866b33 99 return 0;
663996b3 100}
6e866b33
MB
101
102DEFINE_MAIN_FUNCTION(run);