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