]>
Commit | Line | Data |
---|---|---|
3d20ed6d LP |
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 | |
5430f7f2 LP |
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 | |
3d20ed6d LP |
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 | |
5430f7f2 | 16 | Lesser General Public License for more details. |
3d20ed6d | 17 | |
5430f7f2 | 18 | You should have received a copy of the GNU Lesser General Public License |
3d20ed6d LP |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
20 | ***/ | |
21 | ||
3d20ed6d | 22 | #include <errno.h> |
07630cea LP |
23 | #include <stdbool.h> |
24 | #include <stdio.h> | |
ce30c8dc | 25 | #include <sys/prctl.h> |
07630cea | 26 | #include <unistd.h> |
3d20ed6d | 27 | |
0b452006 | 28 | #include "process-util.h" |
ce30c8dc | 29 | #include "signal-util.h" |
07630cea LP |
30 | #include "string-util.h" |
31 | #include "util.h" | |
3d20ed6d LP |
32 | |
33 | static bool arg_skip = false; | |
34 | static bool arg_force = false; | |
35 | ||
059cb385 LP |
36 | static int parse_proc_cmdline_item(const char *key, const char *value) { |
37 | ||
38 | if (streq(key, "quotacheck.mode") && value) { | |
39 | ||
40 | if (streq(value, "auto")) | |
41 | arg_force = arg_skip = false; | |
42 | else if (streq(value, "force")) | |
43 | arg_force = true; | |
44 | else if (streq(value, "skip")) | |
45 | arg_skip = true; | |
46 | else | |
85013844 LP |
47 | log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value); |
48 | } | |
059cb385 | 49 | |
32f992a5 | 50 | #ifdef HAVE_SYSV_COMPAT |
059cb385 LP |
51 | else if (streq(key, "forcequotacheck") && !value) { |
52 | log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line."); | |
141a79f4 | 53 | arg_force = true; |
3d20ed6d | 54 | } |
141a79f4 ZJS |
55 | #endif |
56 | ||
3d20ed6d LP |
57 | return 0; |
58 | } | |
59 | ||
60 | static void test_files(void) { | |
85013844 | 61 | |
32f992a5 LP |
62 | #ifdef HAVE_SYSV_COMPAT |
63 | if (access("/forcequotacheck", F_OK) >= 0) { | |
64 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system."); | |
3d20ed6d | 65 | arg_force = true; |
32f992a5 | 66 | } |
3d20ed6d LP |
67 | #endif |
68 | } | |
69 | ||
70 | int main(int argc, char *argv[]) { | |
83374163 | 71 | |
3d20ed6d | 72 | static const char * const cmdline[] = { |
83374163 | 73 | QUOTACHECK, |
3d20ed6d LP |
74 | "-anug", |
75 | NULL | |
76 | }; | |
77 | ||
3d20ed6d | 78 | pid_t pid; |
b5884878 | 79 | int r; |
3d20ed6d LP |
80 | |
81 | if (argc > 1) { | |
82 | log_error("This program takes no arguments."); | |
83 | return EXIT_FAILURE; | |
84 | } | |
85 | ||
4cfa2c99 | 86 | log_set_target(LOG_TARGET_AUTO); |
3d20ed6d LP |
87 | log_parse_environment(); |
88 | log_open(); | |
89 | ||
4c12626c LP |
90 | umask(0022); |
91 | ||
b5884878 LP |
92 | r = parse_proc_cmdline(parse_proc_cmdline_item); |
93 | if (r < 0) | |
da927ba9 | 94 | log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); |
b5884878 | 95 | |
3d20ed6d LP |
96 | test_files(); |
97 | ||
98 | if (!arg_force) { | |
3d20ed6d | 99 | if (arg_skip) |
83374163 | 100 | return EXIT_SUCCESS; |
3d20ed6d | 101 | |
2b583ce6 | 102 | if (access("/run/systemd/quotacheck", F_OK) < 0) |
83374163 | 103 | return EXIT_SUCCESS; |
3d20ed6d LP |
104 | } |
105 | ||
83374163 LP |
106 | pid = fork(); |
107 | if (pid < 0) { | |
56f64d95 | 108 | log_error_errno(errno, "fork(): %m"); |
83374163 | 109 | return EXIT_FAILURE; |
3d20ed6d | 110 | } else if (pid == 0) { |
ce30c8dc | 111 | |
3d20ed6d | 112 | /* Child */ |
ce30c8dc LP |
113 | |
114 | (void) reset_all_signal_handlers(); | |
115 | (void) reset_signal_mask(); | |
116 | assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); | |
117 | ||
3d20ed6d LP |
118 | execv(cmdline[0], (char**) cmdline); |
119 | _exit(1); /* Operational error */ | |
120 | } | |
121 | ||
820d3acf | 122 | r = wait_for_terminate_and_warn("quotacheck", pid, true); |
b5884878 LP |
123 | |
124 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
3d20ed6d | 125 | } |