chiark / gitweb /
basic: add a common syscall wrapper around reboot()
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 16:42:59 +0000 (17:42 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:02 +0000 (07:59 +0200)
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]

index 360c5db0be668fe7ea3a33e42283934a1e417b63..cf0038b832b035e2e561889d13c7bffb77f52d88 100644 (file)
 #         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..3f7f63b
--- /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);
+}