diff --git a/src/basic/meson.build b/src/basic/meson.build index d0e499d0d2..811085eec1 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -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 index 0000000000..8ecefe9e21 --- /dev/null +++ b/src/basic/raw-reboot.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +#include +#include +#include + +/* 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); +} diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index decfacd600..095033732b 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -20,11 +20,11 @@ ***/ #include -#include #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"); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 0326a7808d..8907c4b0a3 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -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"); } } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 99ad2fc4b0..800f862938 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -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"); } }