summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2021-04-20 00:00:22 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2021-04-20 00:00:22 +0000
commit1172c1e817d26d5f9bb0ec289dd9a71aadf2759c (patch)
tree6c7e5eb2ebb255c7be81d1535559fa7c4a63af4b /src/os
parent3bde455795bb3273922ec7be293e3911913576c2 (diff)
downloads6-linux-init-1172c1e817d26d5f9bb0ec289dd9a71aadf2759c.tar.xz
Add portability infrastructure
Diffstat (limited to 'src/os')
-rw-r--r--src/os/deps-lib/os-freebsd3
-rw-r--r--src/os/deps-lib/os-linux4
-rw-r--r--src/os/linux-os_kbspecials.c33
-rw-r--r--src/os/linux-os_mount_devtmpfs.c10
-rw-r--r--src/os/linux-os_mount_tmpfs.c31
-rw-r--r--src/os/linux-os_reboot.c10
6 files changed, 91 insertions, 0 deletions
diff --git a/src/os/deps-lib/os-freebsd b/src/os/deps-lib/os-freebsd
new file mode 100644
index 0000000..a8c2a99
--- /dev/null
+++ b/src/os/deps-lib/os-freebsd
@@ -0,0 +1,3 @@
+freebsd-os_reboot.o
+freebsd-os_kbspecials.o
+freebsd-os_mount_tmpfs.o
diff --git a/src/os/deps-lib/os-linux b/src/os/deps-lib/os-linux
new file mode 100644
index 0000000..56fe3fc
--- /dev/null
+++ b/src/os/deps-lib/os-linux
@@ -0,0 +1,4 @@
+linux-os_reboot.o
+linux-os_kbspecials.o
+linux-os_mount_devtmpfs.o
+linux-os_mount_tmpfs.o
diff --git a/src/os/linux-os_kbspecials.c b/src/os/linux-os_kbspecials.c
new file mode 100644
index 0000000..0d407ab
--- /dev/null
+++ b/src/os/linux-os_kbspecials.c
@@ -0,0 +1,33 @@
+/* ISC license. */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <sys/reboot.h>
+#include <sys/ioctl.h>
+#include <linux/kd.h>
+
+#include <skalibs/strerr2.h>
+#include <skalibs/sig.h>
+
+#include "os.h"
+
+void os_kbspecials (int inns)
+{
+ int fd ;
+ if (inns) return ;
+ fd = open("/dev/tty0", O_RDONLY | O_NOCTTY) ;
+ if (fd < 0)
+ strerr_warnwu2sys("open /dev/", "tty0 (kbrequest will not be handled)") ;
+ else
+ {
+ if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
+ strerr_warnwu2sys("ioctl KDSIGACCEPT on ", "tty0 (kbrequest will not be handled)") ;
+ close(fd) ;
+ }
+
+ sig_block(SIGINT) ; /* don't panic on early cad before s6-svscan catches it */
+ if (reboot(RB_DISABLE_CAD) == -1)
+ strerr_warnwu1sys("trap ctrl-alt-del") ;
+}
diff --git a/src/os/linux-os_mount_devtmpfs.c b/src/os/linux-os_mount_devtmpfs.c
new file mode 100644
index 0000000..b3f34a1
--- /dev/null
+++ b/src/os/linux-os_mount_devtmpfs.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include <sys/mount.h>
+
+#include "os.h"
+
+int os_mount_devtmpfs (char const *point)
+{
+ return mount("dev", point, "devtmpfs", MS_NOSUID | MS_NOEXEC, "") ;
+}
diff --git a/src/os/linux-os_mount_tmpfs.c b/src/os/linux-os_mount_tmpfs.c
new file mode 100644
index 0000000..0e173d0
--- /dev/null
+++ b/src/os/linux-os_mount_tmpfs.c
@@ -0,0 +1,31 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <sys/mount.h>
+
+#include <skalibs/strerr2.h>
+
+#include "os.h"
+
+void os_mount_tmpfs (char const *point, unsigned int mounttype)
+{
+ if (mounttype)
+ {
+ if (mounttype == 2)
+ {
+ if (mount("tmpfs", point, "tmpfs", MS_REMOUNT | MS_NODEV | MS_NOSUID, "mode=0755") == -1)
+ strerr_diefu2sys(111, "remount ", point) ;
+ }
+ else
+ {
+ if (umount(point) == -1)
+ {
+ if (errno != EINVAL)
+ strerr_warnwu2sys("umount ", point) ;
+ }
+ if (mount("tmpfs", point, "tmpfs", MS_NODEV | MS_NOSUID, "mode=0755") == -1)
+ strerr_diefu2sys(111, "mount tmpfs on ", point) ;
+ }
+ }
+}
diff --git a/src/os/linux-os_reboot.c b/src/os/linux-os_reboot.c
new file mode 100644
index 0000000..fb41584
--- /dev/null
+++ b/src/os/linux-os_reboot.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include <sys/reboot.h>
+
+#include "os.h"
+
+void os_reboot (int what)
+{
+ reboot(what == 3 ? RB_AUTOBOOT : what == 2 ? RB_POWER_OFF : RB_HALT_SYSTEM) ;
+}