]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/quotacheck.c
manager: call generators with umask 0022
[thirdparty/systemd.git] / src / quotacheck.c
CommitLineData
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
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 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 General Public License for more details.
17
18 You should have received a copy of the GNU 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
30static bool arg_skip = false;
31static bool arg_force = false;
32
33static int parse_proc_cmdline(void) {
34 char *line, *w, *state;
35 int r;
36 size_t l;
37
03aea2ae 38 if (detect_container(NULL) > 0)
2fc97846
LP
39 return 0;
40
3d20ed6d
LP
41 if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
42 log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
43 return 0;
44 }
45
46 FOREACH_WORD_QUOTED(w, l, line, state) {
47
48 if (strneq(w, "quotacheck.mode=auto", l))
49 arg_force = arg_skip = false;
50 else if (strneq(w, "quotacheck.mode=force", l))
51 arg_force = true;
52 else if (strneq(w, "quotacheck.mode=skip", l))
53 arg_skip = true;
54 else if (startswith(w, "quotacheck.mode"))
55 log_warning("Invalid quotacheck.mode= parameter. Ignoring.");
1de4d79b 56#if defined(TARGET_FEDORA) || defined(TARGET_MANDRIVA)
3d20ed6d
LP
57 else if (strneq(w, "forcequotacheck", l))
58 arg_force = true;
59#endif
60 }
61
62 free(line);
63 return 0;
64}
65
66static void test_files(void) {
1de4d79b
AB
67#if defined(TARGET_FEDORA) || defined(TARGET_MANDRIVA)
68 /* This exists only on Fedora or Mandriva */
550c4dcc 69 if (access("/forcequotacheck", F_OK) >= 0)
3d20ed6d
LP
70 arg_force = true;
71#endif
72}
73
74int main(int argc, char *argv[]) {
75 static const char * const cmdline[] = {
76 "/sbin/quotacheck",
77 "-anug",
78 NULL
79 };
80
81 int r = EXIT_FAILURE;
82 pid_t pid;
83
84 if (argc > 1) {
85 log_error("This program takes no arguments.");
86 return EXIT_FAILURE;
87 }
88
89 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
90 log_parse_environment();
91 log_open();
92
93 parse_proc_cmdline();
94 test_files();
95
96 if (!arg_force) {
3d20ed6d
LP
97 if (arg_skip)
98 return 0;
99
2b583ce6 100 if (access("/run/systemd/quotacheck", F_OK) < 0)
3d20ed6d
LP
101 return 0;
102 }
103
104 if ((pid = fork()) < 0) {
105 log_error("fork(): %m");
106 goto finish;
107 } else if (pid == 0) {
108 /* Child */
109 execv(cmdline[0], (char**) cmdline);
110 _exit(1); /* Operational error */
111 }
112
0a27cf3f 113 r = wait_for_terminate_and_warn("quotacheck", pid) == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
3d20ed6d
LP
114
115finish:
116 return r;
117}