summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2021-04-21 13:50:10 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2021-04-21 13:50:10 +0000
commitdacf8817be3943b8911d290fb9cbaaa5d659ad95 (patch)
treeacd0824056af774b20c01bb7649a1ea05c25dda9
parent2c0bf67b7612a11f64e7407a69b51d909a5ae277 (diff)
downloads6-linux-init-dacf8817be3943b8911d290fb9cbaaa5d659ad95.tar.xz
The final wtmp entry is also os-specific
-rw-r--r--package/deps.mak11
-rw-r--r--src/include-local/os.h2
-rw-r--r--src/os/deps-lib/os-freebsd1
-rw-r--r--src/os/deps-lib/os-linux1
-rw-r--r--src/os/freebsd-os_final_wtmp.c10
-rw-r--r--src/os/freebsd-os_kbspecials.c5
-rw-r--r--src/os/linux-os_final_wtmp.c68
-rw-r--r--src/shutdown/s6-linux-init-hpr.c60
8 files changed, 93 insertions, 65 deletions
diff --git a/package/deps.mak b/package/deps.mak
index aaca31b..3fb754c 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -16,6 +16,7 @@ src/os/freebsd-os_kbspecials.o src/os/freebsd-os_kbspecials.lo: src/os/freebsd-o
src/os/freebsd-os_mount_devtmpfs.o src/os/freebsd-os_mount_devtmpfs.lo: src/os/freebsd-os_mount_devtmpfs.c src/include-local/os.h
src/os/freebsd-os_mount_tmpfs.o src/os/freebsd-os_mount_tmpfs.lo: src/os/freebsd-os_mount_tmpfs.c src/include-local/os.h
src/os/freebsd-os_reboot.o src/os/freebsd-os_reboot.lo: src/os/freebsd-os_reboot.c src/include-local/os.h
+src/os/linux-os_final_wtmp.o src/os/linux-os_final_wtmp.lo: src/os/linux-os_final_wtmp.c src/include-local/os.h
src/os/linux-os_kbspecials.o src/os/linux-os_kbspecials.lo: src/os/linux-os_kbspecials.c src/include-local/os.h
src/os/linux-os_mount_devtmpfs.o src/os/linux-os_mount_devtmpfs.lo: src/os/linux-os_mount_devtmpfs.c src/include-local/os.h
src/os/linux-os_mount_tmpfs.o src/os/linux-os_mount_tmpfs.lo: src/os/linux-os_mount_tmpfs.c src/include-local/os.h
@@ -24,7 +25,7 @@ src/shutdown/hpr_confirm_hostname.o src/shutdown/hpr_confirm_hostname.lo: src/sh
src/shutdown/hpr_shutdown.o src/shutdown/hpr_shutdown.lo: src/shutdown/hpr_shutdown.c src/shutdown/hpr.h
src/shutdown/hpr_wall.o src/shutdown/hpr_wall.lo: src/shutdown/hpr_wall.c src/shutdown/hpr.h
src/shutdown/hpr_wallv.o src/shutdown/hpr_wallv.lo: src/shutdown/hpr_wallv.c src/shutdown/hpr.h
-src/shutdown/s6-linux-init-hpr.o src/shutdown/s6-linux-init-hpr.lo: src/shutdown/s6-linux-init-hpr.c src/include-local/defaults.h src/shutdown/hpr.h src/include-local/os.h
+src/shutdown/s6-linux-init-hpr.o src/shutdown/s6-linux-init-hpr.lo: src/shutdown/s6-linux-init-hpr.c src/shutdown/hpr.h src/include-local/os.h
src/shutdown/s6-linux-init-shutdown.o src/shutdown/s6-linux-init-shutdown.lo: src/shutdown/s6-linux-init-shutdown.c src/include-local/defaults.h src/shutdown/hpr.h src/include-local/initctl.h
src/shutdown/s6-linux-init-shutdownd.o src/shutdown/s6-linux-init-shutdownd.lo: src/shutdown/s6-linux-init-shutdownd.c src/include-local/defaults.h src/shutdown/hpr.h src/include-local/initctl.h src/include/s6-linux-init/config.h
@@ -50,14 +51,14 @@ s6-linux-init-nuke: src/misc/s6-linux-init-nuke.o
s6-linux-init-umountall: EXTRA_LIBS := -lskarnet
s6-linux-init-umountall: src/misc/s6-linux-init-umountall.o
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
-libos-freebsd.a.xyzzy: src/os/freebsd-os_kbspecials.o src/os/freebsd-os_mount_devtmpfs.o src/os/freebsd-os_mount_tmpfs.o src/os/freebsd-os_reboot.o
+libos-freebsd.a.xyzzy: src/os/freebsd-os_final_wtmp.o src/os/freebsd-os_kbspecials.o src/os/freebsd-os_mount_devtmpfs.o src/os/freebsd-os_mount_tmpfs.o src/os/freebsd-os_reboot.o
else
-libos-freebsd.a.xyzzy: src/os/freebsd-os_kbspecials.lo src/os/freebsd-os_mount_devtmpfs.lo src/os/freebsd-os_mount_tmpfs.lo src/os/freebsd-os_reboot.lo
+libos-freebsd.a.xyzzy: src/os/freebsd-os_final_wtmp.lo src/os/freebsd-os_kbspecials.lo src/os/freebsd-os_mount_devtmpfs.lo src/os/freebsd-os_mount_tmpfs.lo src/os/freebsd-os_reboot.lo
endif
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
-libos-linux.a.xyzzy: src/os/linux-os_kbspecials.o src/os/linux-os_mount_devtmpfs.o src/os/linux-os_mount_tmpfs.o src/os/linux-os_reboot.o
+libos-linux.a.xyzzy: src/os/linux-os_final_wtmp.o src/os/linux-os_kbspecials.o src/os/linux-os_mount_devtmpfs.o src/os/linux-os_mount_tmpfs.o src/os/linux-os_reboot.o
else
-libos-linux.a.xyzzy: src/os/linux-os_kbspecials.lo src/os/linux-os_mount_devtmpfs.lo src/os/linux-os_mount_tmpfs.lo src/os/linux-os_reboot.lo
+libos-linux.a.xyzzy: src/os/linux-os_final_wtmp.lo src/os/linux-os_kbspecials.lo src/os/linux-os_mount_devtmpfs.lo src/os/linux-os_mount_tmpfs.lo src/os/linux-os_reboot.lo
endif
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
libhpr.a.xyzzy: src/shutdown/hpr_shutdown.o src/shutdown/hpr_wall.o src/shutdown/hpr_wallv.o src/shutdown/hpr_confirm_hostname.o
diff --git a/src/include-local/os.h b/src/include-local/os.h
index 72062e9..4a1d7c2 100644
--- a/src/include-local/os.h
+++ b/src/include-local/os.h
@@ -3,7 +3,9 @@
#ifndef S6_LINUX_INIT_OS_H
#define S6_LINUX_INIT_OS_H
+extern void os_final_wtmp (int) ;
extern void os_reboot (int) ;
+
extern void os_kbspecials (int) ;
extern void os_mount_tmpfs (char const *, unsigned int) ;
extern int os_mount_devtmpfs (char const *) ;
diff --git a/src/os/deps-lib/os-freebsd b/src/os/deps-lib/os-freebsd
index 54edc05..201369f 100644
--- a/src/os/deps-lib/os-freebsd
+++ b/src/os/deps-lib/os-freebsd
@@ -1,3 +1,4 @@
+freebsd-os_final_wtmp.o
freebsd-os_kbspecials.o
freebsd-os_mount_devtmpfs.o
freebsd-os_mount_tmpfs.o
diff --git a/src/os/deps-lib/os-linux b/src/os/deps-lib/os-linux
index f58c20e..f257471 100644
--- a/src/os/deps-lib/os-linux
+++ b/src/os/deps-lib/os-linux
@@ -1,3 +1,4 @@
+linux-os_final_wtmp.o
linux-os_kbspecials.o
linux-os_mount_devtmpfs.o
linux-os_mount_tmpfs.o
diff --git a/src/os/freebsd-os_final_wtmp.c b/src/os/freebsd-os_final_wtmp.c
new file mode 100644
index 0000000..868e0c3
--- /dev/null
+++ b/src/os/freebsd-os_final_wtmp.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include "os.h"
+
+ /* FreeBSD only does utx.log (wtmp) operations at the rc level. */
+
+void os_final_wtmp (int what)
+{
+ (void)what ;
+}
diff --git a/src/os/freebsd-os_kbspecials.c b/src/os/freebsd-os_kbspecials.c
index 71a0480..1d7092d 100644
--- a/src/os/freebsd-os_kbspecials.c
+++ b/src/os/freebsd-os_kbspecials.c
@@ -2,8 +2,9 @@
#include "os.h"
+ /* FreeBSD hardcodes cad and doesn't have kbrequest */
+
void os_kbspecials (int inns)
{
- if (inns) return ;
- return ;
+ (void)inns ;
}
diff --git a/src/os/linux-os_final_wtmp.c b/src/os/linux-os_final_wtmp.c
new file mode 100644
index 0000000..b3ce7c5
--- /dev/null
+++ b/src/os/linux-os_final_wtmp.c
@@ -0,0 +1,68 @@
+/* ISC license. */
+
+#include <skalibs/nonposix.h>
+
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <utmpx.h>
+
+#include <skalibs/strerr2.h>
+#include <skalibs/tai.h>
+
+#include "os.h"
+
+#ifndef WTMPX_FILE
+# include <utmp.h>
+# ifdef WTMP_FILE
+# define WTMPX_FILE WTMP_FILE
+# else
+# ifdef _PATH_WTMP
+# define WTMPX_FILE _PATH_WTMP
+# else
+# define WTMPX_FILE "/var/log/wtmp"
+# endif
+# endif
+#endif
+
+#ifndef UT_NAMESIZE
+# define UT_NAMESIZE 32
+#endif
+
+#ifndef UT_HOSTSIZE
+# define UT_HOSTSIZE 256
+#endif
+
+void os_final_wtmp (int what)
+{
+ struct utmpx utx =
+ {
+ .ut_type = RUN_LVL,
+ .ut_pid = getpid(),
+ .ut_line = "~",
+ .ut_id = "",
+ .ut_session = getsid(0)
+ } ;
+ strncpy(utx.ut_user, what == 3 ? "reboot" : "shutdown", UT_NAMESIZE) ;
+ if (gethostname(utx.ut_host, UT_HOSTSIZE) < 0)
+ {
+ utx.ut_host[0] = 0 ;
+ strerr_warnwu1sys("gethostname") ;
+ }
+ else utx.ut_host[UT_HOSTSIZE - 1] = 0 ;
+
+ /* glibc multilib can go fuck itself */
+#ifdef __WORDSIZE_TIME64_COMPAT32
+ {
+ struct timeval tv ;
+ if (!timeval_from_tain(&tv, &STAMP))
+ strerr_warnwu1sys("timeval_from_tain") ;
+ utx.ut_tv.tv_sec = tv.tv_sec ;
+ utx.ut_tv.tv_usec = tv.tv_usec ;
+ }
+#else
+ if (!timeval_from_tain(&utx.ut_tv, &STAMP))
+ strerr_warnwu1sys("timeval_from_tain") ;
+#endif
+ updwtmpx(WTMPX_FILE, &utx) ;
+}
diff --git a/src/shutdown/s6-linux-init-hpr.c b/src/shutdown/s6-linux-init-hpr.c
index c92717c..14e1844 100644
--- a/src/shutdown/s6-linux-init-hpr.c
+++ b/src/shutdown/s6-linux-init-hpr.c
@@ -1,37 +1,14 @@
/* ISC license. */
-#include <skalibs/nonposix.h>
-
#include <unistd.h>
-#include <signal.h>
#include <errno.h>
-#include <utmpx.h>
#include <skalibs/strerr2.h>
#include <skalibs/sgetopt.h>
-#include <skalibs/sig.h>
#include <skalibs/tai.h>
-#include <skalibs/djbunix.h>
-#include "os.h"
-#include "defaults.h"
#include "hpr.h"
-
-#ifndef UT_NAMESIZE
-#define UT_NAMESIZE 32
-#endif
-
-#ifndef UT_HOSTSIZE
-#define UT_HOSTSIZE 256
-#endif
-
-#ifndef _PATH_WTMP
-# ifdef WTMPX_FILE
-# define _PATH_WTMP WTMPX_FILE
-# else
-# define _PATH_WTMP "/var/log/wtmp"
-# endif
-#endif
+#include "os.h"
#define USAGE "s6-linux-init-hpr [ -h | -p | -r ] [ -n ] [ -d | -w ] [ -W ] [ -f ] [ -i ]"
@@ -87,40 +64,7 @@ int main (int argc, char const *const *argv)
}
if (!tain_now_g()) strerr_warnw1sys("get current time") ;
- if (dowtmp)
- {
- struct utmpx utx =
- {
- .ut_type = RUN_LVL,
- .ut_pid = getpid(),
- .ut_line = "~",
- .ut_id = "",
- .ut_session = getsid(0)
- } ;
- strncpy(utx.ut_user, what == 3 ? "reboot" : "shutdown", UT_NAMESIZE) ;
- if (gethostname(utx.ut_host, UT_HOSTSIZE) < 0)
- {
- utx.ut_host[0] = 0 ;
- strerr_warnwu1sys("gethostname") ;
- }
- else utx.ut_host[UT_HOSTSIZE - 1] = 0 ;
-
- /* glibc multilib can go fuck itself */
-#ifdef __WORDSIZE_TIME64_COMPAT32
- {
- struct timeval tv ;
- if (!timeval_from_tain(&tv, &STAMP))
- strerr_warnwu1sys("timeval_from_tain") ;
- utx.ut_tv.tv_sec = tv.tv_sec ;
- utx.ut_tv.tv_usec = tv.tv_usec ;
- }
-#else
- if (!timeval_from_tain(&utx.ut_tv, &STAMP))
- strerr_warnwu1sys("timeval_from_tain") ;
-#endif
-
- updwtmpx(_PATH_WTMP, &utx) ;
- }
+ if (dowtmp) os_final_wtmp(what) ;
if (dowall) hpr_wall(HPR_WALL_BANNER) ;
if (dowtmp < 2)
{