]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/quotacheck/quotacheck.c
tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
[thirdparty/systemd.git] / src / quotacheck / quotacheck.c
index ed95b48c63e6881cb1cccee32edc882a655b48e4..2714cde5c7c973b2ccb85e5441067f2166a6a808 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
 #include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/prctl.h>
 #include <unistd.h>
 
+#include "proc-cmdline.h"
+#include "process-util.h"
+#include "signal-util.h"
+#include "string-util.h"
 #include "util.h"
-#include "fileio.h"
 
 static bool arg_skip = false;
 static bool arg_force = false;
 
-static int parse_proc_cmdline_item(const char *key, const char *value) {
+static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
 
         if (streq(key, "quotacheck.mode") && value) {
 
@@ -74,6 +75,7 @@ int main(int argc, char *argv[]) {
         };
 
         pid_t pid;
+        int r;
 
         if (argc > 1) {
                 log_error("This program takes no arguments.");
@@ -86,7 +88,10 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        parse_proc_cmdline(parse_proc_cmdline_item);
+        r = parse_proc_cmdline(parse_proc_cmdline_item, NULL, false);
+        if (r < 0)
+                log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
+
         test_files();
 
         if (!arg_force) {
@@ -99,13 +104,21 @@ int main(int argc, char *argv[]) {
 
         pid = fork();
         if (pid < 0) {
-                log_error("fork(): %m");
+                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 */
         }
 
-        return wait_for_terminate_and_warn("quotacheck", pid) >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+        r = wait_for_terminate_and_warn("quotacheck", pid, true);
+
+        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }