0b0582a3aa10227767e359e693c4b43fec272388nd/***
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd This file is part of systemd.
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd
0b0582a3aa10227767e359e693c4b43fec272388nd Copyright 2010 Lennart Poettering
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd systemd is free software; you can redistribute it and/or modify it
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd under the terms of the GNU Lesser General Public License as published by
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd the Free Software Foundation; either version 2.1 of the License, or
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd (at your option) any later version.
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd systemd is distributed in the hope that it will be useful, but
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd WITHOUT ANY WARRANTY; without even the implied warranty of
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd Lesser General Public License for more details.
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd You should have received a copy of the GNU Lesser General Public License
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd along with systemd; If not, see <http://www.gnu.org/licenses/>.
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd***/
0b0582a3aa10227767e359e693c4b43fec272388nd
60ca0709311658bc8604806c62c6e33534921b3bnd#include <errno.h>
0b0582a3aa10227767e359e693c4b43fec272388nd#include <stdbool.h>
60ca0709311658bc8604806c62c6e33534921b3bnd#include <stdio.h>
60ca0709311658bc8604806c62c6e33534921b3bnd#include <sys/prctl.h>
0b0582a3aa10227767e359e693c4b43fec272388nd#include <unistd.h>
0b0582a3aa10227767e359e693c4b43fec272388nd
45de0209f6fdd98b9961f9641f85d572e14e3edcnd#include "proc-cmdline.h"
60ca0709311658bc8604806c62c6e33534921b3bnd#include "process-util.h"
60ca0709311658bc8604806c62c6e33534921b3bnd#include "signal-util.h"
0b0582a3aa10227767e359e693c4b43fec272388nd#include "string-util.h"
0b0582a3aa10227767e359e693c4b43fec272388nd#include "util.h"
0b0582a3aa10227767e359e693c4b43fec272388nd
60ca0709311658bc8604806c62c6e33534921b3bndstatic bool arg_skip = false;
60ca0709311658bc8604806c62c6e33534921b3bndstatic bool arg_force = false;
60ca0709311658bc8604806c62c6e33534921b3bnd
60ca0709311658bc8604806c62c6e33534921b3bndstatic int parse_proc_cmdline_item(const char *key, const char *value) {
578d284908c082afe20159da2b8967b504a33e9dnd
if (streq(key, "quotacheck.mode") && value) {
if (streq(value, "auto"))
arg_force = arg_skip = false;
else if (streq(value, "force"))
arg_force = true;
else if (streq(value, "skip"))
arg_skip = true;
else
log_warning("Invalid quotacheck.mode= parameter '%s'. Ignoring.", value);
}
#ifdef HAVE_SYSV_COMPAT
else if (streq(key, "forcequotacheck") && !value) {
log_warning("Please use 'quotacheck.mode=force' rather than 'forcequotacheck' on the kernel command line.");
arg_force = true;
}
#endif
return 0;
}
static void test_files(void) {
#ifdef HAVE_SYSV_COMPAT
if (access("/forcequotacheck", F_OK) >= 0) {
log_error("Please pass 'quotacheck.mode=force' on the kernel command line rather than creating /forcequotacheck on the root file system.");
arg_force = true;
}
#endif
}
int main(int argc, char *argv[]) {
static const char * const cmdline[] = {
QUOTACHECK,
"-anug",
NULL
};
pid_t pid;
int r;
if (argc > 1) {
log_error("This program takes no arguments.");
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
umask(0022);
r = parse_proc_cmdline(parse_proc_cmdline_item);
if (r < 0)
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
test_files();
if (!arg_force) {
if (arg_skip)
return EXIT_SUCCESS;
if (access("/run/systemd/quotacheck", F_OK) < 0)
return EXIT_SUCCESS;
}
pid = fork();
if (pid < 0) {
log_error_errno(errno, "fork(): %m");
return EXIT_FAILURE;
} else if (pid == 0) {
/* Child */
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
execv(cmdline[0], (char**) cmdline);
_exit(1); /* Operational error */
}
r = wait_for_terminate_and_warn("quotacheck", pid, true);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}