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