]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: add a common syscall wrapper around reboot()
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 16:42:59 +0000 (17:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Feb 2018 09:42:06 +0000 (10:42 +0100)
This mimics the raw_clone() call we have in place already and
establishes a new syscall wrapper raw_reboot() that wraps the kernel's
reboot() system call in a bit more low-level fashion that glibc's
reboot() wrapper. The main difference is that the extra "arg" argument
is supported.

Ultimately this just replaces the syscall wrapper implementation we
currently have at three places in our codebase by a single one.

With this change this means that all our syscall() invocations are
neatly separated out in static inline system call wrappers in our header
functions.

src/basic/meson.build
src/basic/raw-reboot.h [new file with mode: 0644]
src/core/emergency-action.c
src/core/shutdown.c
src/systemctl/systemctl.c

index d0e499d0d2ab23625ad6d5fb1832c7b95c245844..811085eec106895938934badc6c96d713916758f 100644 (file)
@@ -157,6 +157,7 @@ basic_sources = files('''
         ratelimit.c
         ratelimit.h
         raw-clone.h
+        raw-reboot.h
         refcnt.h
         replace-var.c
         replace-var.h
diff --git a/src/basic/raw-reboot.h b/src/basic/raw-reboot.h
new file mode 100644 (file)
index 0000000..8ecefe9
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include <linux/reboot.h>
+#include <sys/reboot.h>
+#include <sys/syscall.h>
+
+/* glibc defines the reboot() API call, which is a wrapper around the system call of the same name, but without the
+ * extra "arg" parameter. Since we need that parameter for some calls, let's add a "raw" wrapper that is defined the
+ * same way, except it takes the additional argument. */
+
+static inline int raw_reboot(int cmd, const void *arg) {
+        return (int) syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, arg);
+}
index decfacd60055e92d37b0d71bc688898f0c015c49..095033732b19b1ef022ee815923ffcc1fbc8ee70 100644 (file)
 ***/
 
 #include <sys/reboot.h>
-#include <linux/reboot.h>
 
 #include "bus-error.h"
 #include "bus-util.h"
 #include "emergency-action.h"
+#include "raw-reboot.h"
 #include "special.h"
 #include "string-table.h"
 #include "terminal-util.h"
@@ -88,7 +88,7 @@ int emergency_action(
 
                 if (!isempty(reboot_arg)) {
                         log_info("Rebooting with argument '%s'.", reboot_arg);
-                        syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_arg);
+                        (void) raw_reboot(LINUX_REBOOT_CMD_RESTART2, reboot_arg);
                         log_warning_errno(errno, "Failed to reboot with parameter, retrying without: %m");
                 }
 
index 0326a7808d35e9239bb8cef5d5157c08806390e1..8907c4b0a36cda516d63c1f2c0b0502b245ca7a7 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <errno.h>
 #include <getopt.h>
-#include <linux/reboot.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -42,6 +41,7 @@
 #include "missing.h"
 #include "parse-util.h"
 #include "process-util.h"
+#include "raw-reboot.h"
 #include "signal-util.h"
 #include "string-util.h"
 #include "switch-root.h"
@@ -528,7 +528,7 @@ int main(int argc, char *argv[]) {
 
                         if (!isempty(param)) {
                                 log_info("Rebooting with argument '%s'.", param);
-                                syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, param);
+                                (void) raw_reboot(LINUX_REBOOT_CMD_RESTART2, param);
                                 log_warning_errno(errno, "Failed to reboot with parameter, retrying without: %m");
                         }
                 }
index 99ad2fc4b0f60ed2de4a8726c99c11eca15a1b5e..800f862938954c5659c7a58f5cf615a8ca653f57 100644 (file)
@@ -22,7 +22,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
-#include <linux/reboot.h>
 #include <locale.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -57,8 +56,8 @@
 #include "format-util.h"
 #include "fs-util.h"
 #include "glob-util.h"
-#include "hostname-util.h"
 #include "hexdecoct.h"
+#include "hostname-util.h"
 #include "initreq.h"
 #include "install.h"
 #include "io-util.h"
@@ -73,6 +72,7 @@
 #include "path-lookup.h"
 #include "path-util.h"
 #include "process-util.h"
+#include "raw-reboot.h"
 #include "rlimit-util.h"
 #include "set.h"
 #include "sigbus.h"
@@ -8514,8 +8514,7 @@ static int halt_now(enum action a) {
                         if (!arg_quiet)
                                 log_info("Rebooting with argument '%s'.", param);
                         if (!arg_dry_run) {
-                                (void) syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
-                                               LINUX_REBOOT_CMD_RESTART2, param);
+                                (void) raw_reboot(LINUX_REBOOT_CMD_RESTART2, param);
                                 log_warning_errno(errno, "Failed to reboot with parameter, retrying without: %m");
                         }
                 }