]>
Commit | Line | Data |
---|---|---|
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 <stdio.h> | |
23 | #include <stdbool.h> | |
24 | #include <string.h> | |
25 | #include <errno.h> | |
26 | #include <unistd.h> | |
27 | ||
28 | #include "util.h" | |
29 | #include "fileio.h" | |
30 | ||
31 | static bool arg_skip = false; | |
32 | static bool arg_force = false; | |
33 | ||
34 | static int parse_proc_cmdline_item(const char *key, const char *value) { | |
35 | ||
36 | if (streq(key, "quotacheck.mode") && value) { | |
37 | ||
38 | if (streq(value, "auto")) | |
39 | arg_force = arg_skip = false; | |
40 | else if (streq(value, "force")) | |
41 | arg_force = true; | |
42 | else if (streq(value, "skip")) | |
43 | arg_skip = true; | |
44 | else | |
45 | log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value); | |
46 | } | |
47 | ||
48 | #ifdef HAVE_SYSV_COMPAT | |
49 | else if (streq(key, "forcequotacheck") && !value) { | |
50 | log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line."); | |
51 | arg_force = true; | |
52 | } | |
53 | #endif | |
54 | ||
55 | return 0; | |
56 | } | |
57 | ||
58 | static void test_files(void) { | |
59 | ||
60 | #ifdef HAVE_SYSV_COMPAT | |
61 | if (access("/forcequotacheck", F_OK) >= 0) { | |
62 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system."); | |
63 | arg_force = true; | |
64 | } | |
65 | #endif | |
66 | } | |
67 | ||
68 | int main(int argc, char *argv[]) { | |
69 | ||
70 | static const char * const cmdline[] = { | |
71 | QUOTACHECK, | |
72 | "-anug", | |
73 | NULL | |
74 | }; | |
75 | ||
76 | pid_t pid; | |
77 | int r; | |
78 | ||
79 | if (argc > 1) { | |
80 | log_error("This program takes no arguments."); | |
81 | return EXIT_FAILURE; | |
82 | } | |
83 | ||
84 | log_set_target(LOG_TARGET_AUTO); | |
85 | log_parse_environment(); | |
86 | log_open(); | |
87 | ||
88 | umask(0022); | |
89 | ||
90 | r = parse_proc_cmdline(parse_proc_cmdline_item); | |
91 | if (r < 0) | |
92 | log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); | |
93 | ||
94 | test_files(); | |
95 | ||
96 | if (!arg_force) { | |
97 | if (arg_skip) | |
98 | return EXIT_SUCCESS; | |
99 | ||
100 | if (access("/run/systemd/quotacheck", F_OK) < 0) | |
101 | return EXIT_SUCCESS; | |
102 | } | |
103 | ||
104 | pid = fork(); | |
105 | if (pid < 0) { | |
106 | log_error_errno(errno, "fork(): %m"); | |
107 | return EXIT_FAILURE; | |
108 | } else if (pid == 0) { | |
109 | /* Child */ | |
110 | execv(cmdline[0], (char**) cmdline); | |
111 | _exit(1); /* Operational error */ | |
112 | } | |
113 | ||
114 | r = wait_for_terminate_and_warn("quotacheck", pid); | |
115 | ||
116 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
117 | } |