chiark / gitweb /
Remove src/python-systemd
[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         return 0;
47 }
48
49 static void test_files(void) {
50 }
51
52 int main(int argc, char *argv[]) {
53
54         static const char * const cmdline[] = {
55                 QUOTACHECK,
56                 "-anug",
57                 NULL
58         };
59
60         pid_t pid;
61         int r;
62
63         if (argc > 1) {
64                 log_error("This program takes no arguments.");
65                 return EXIT_FAILURE;
66         }
67
68         log_set_target(LOG_TARGET_AUTO);
69         log_parse_environment();
70         log_open();
71
72         umask(0022);
73
74         r = parse_proc_cmdline(parse_proc_cmdline_item);
75         if (r < 0)
76                 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
77
78         test_files();
79
80         if (!arg_force) {
81                 if (arg_skip)
82                         return EXIT_SUCCESS;
83
84                 if (access("/run/systemd/quotacheck", F_OK) < 0)
85                         return EXIT_SUCCESS;
86         }
87
88         pid = fork();
89         if (pid < 0) {
90                 log_error_errno(errno, "fork(): %m");
91                 return EXIT_FAILURE;
92         } else if (pid == 0) {
93                 /* Child */
94                 execv(cmdline[0], (char**) cmdline);
95                 _exit(1); /* Operational error */
96         }
97
98         r = wait_for_terminate_and_warn("quotacheck", pid, true);
99
100         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
101 }