]>
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 | ||
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" | |
5dc4c17f | 29 | #include "virt.h" |
a5c32cff | 30 | #include "fileio.h" |
3d20ed6d LP |
31 | |
32 | static bool arg_skip = false; | |
33 | static bool arg_force = false; | |
34 | ||
35 | static int parse_proc_cmdline(void) { | |
83374163 LP |
36 | _cleanup_free_ char *line = NULL; |
37 | char *w, *state; | |
3d20ed6d | 38 | size_t l; |
83374163 | 39 | int r; |
3d20ed6d | 40 | |
03aea2ae | 41 | if (detect_container(NULL) > 0) |
2fc97846 LP |
42 | return 0; |
43 | ||
83374163 LP |
44 | r = read_one_line_file("/proc/cmdline", &line); |
45 | if (r < 0) { | |
3d20ed6d LP |
46 | log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); |
47 | return 0; | |
48 | } | |
49 | ||
50 | FOREACH_WORD_QUOTED(w, l, line, state) { | |
51 | ||
52 | if (strneq(w, "quotacheck.mode=auto", l)) | |
53 | arg_force = arg_skip = false; | |
54 | else if (strneq(w, "quotacheck.mode=force", l)) | |
55 | arg_force = true; | |
56 | else if (strneq(w, "quotacheck.mode=skip", l)) | |
57 | arg_skip = true; | |
66a78c2b LP |
58 | else if (startswith(w, "quotacheck")) |
59 | log_warning("Invalid quotacheck parameter. Ignoring."); | |
32f992a5 LP |
60 | #ifdef HAVE_SYSV_COMPAT |
61 | else if (strneq(w, "forcequotacheck", l)) { | |
62 | log_error("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line."); | |
3d20ed6d | 63 | arg_force = true; |
32f992a5 | 64 | } |
3d20ed6d LP |
65 | #endif |
66 | } | |
3d20ed6d LP |
67 | return 0; |
68 | } | |
69 | ||
70 | static void test_files(void) { | |
32f992a5 LP |
71 | #ifdef HAVE_SYSV_COMPAT |
72 | if (access("/forcequotacheck", F_OK) >= 0) { | |
73 | log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system."); | |
3d20ed6d | 74 | arg_force = true; |
32f992a5 | 75 | } |
3d20ed6d LP |
76 | #endif |
77 | } | |
78 | ||
79 | int main(int argc, char *argv[]) { | |
83374163 | 80 | |
3d20ed6d | 81 | static const char * const cmdline[] = { |
83374163 | 82 | QUOTACHECK, |
3d20ed6d LP |
83 | "-anug", |
84 | NULL | |
85 | }; | |
86 | ||
3d20ed6d LP |
87 | pid_t pid; |
88 | ||
89 | if (argc > 1) { | |
90 | log_error("This program takes no arguments."); | |
91 | return EXIT_FAILURE; | |
92 | } | |
93 | ||
4cfa2c99 | 94 | log_set_target(LOG_TARGET_AUTO); |
3d20ed6d LP |
95 | log_parse_environment(); |
96 | log_open(); | |
97 | ||
4c12626c LP |
98 | umask(0022); |
99 | ||
3d20ed6d LP |
100 | parse_proc_cmdline(); |
101 | test_files(); | |
102 | ||
103 | if (!arg_force) { | |
3d20ed6d | 104 | if (arg_skip) |
83374163 | 105 | return EXIT_SUCCESS; |
3d20ed6d | 106 | |
2b583ce6 | 107 | if (access("/run/systemd/quotacheck", F_OK) < 0) |
83374163 | 108 | return EXIT_SUCCESS; |
3d20ed6d LP |
109 | } |
110 | ||
83374163 LP |
111 | pid = fork(); |
112 | if (pid < 0) { | |
3d20ed6d | 113 | log_error("fork(): %m"); |
83374163 | 114 | return EXIT_FAILURE; |
3d20ed6d LP |
115 | } else if (pid == 0) { |
116 | /* Child */ | |
117 | execv(cmdline[0], (char**) cmdline); | |
118 | _exit(1); /* Operational error */ | |
119 | } | |
120 | ||
83374163 | 121 | return wait_for_terminate_and_warn("quotacheck", pid) >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
3d20ed6d | 122 | } |