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