diff options
-rwxr-xr-x | 3 | 2 | ||||
-rw-r--r-- | core-services/05-misc.sh | 4 | ||||
-rw-r--r-- | core-services/08-sysctl.sh | 14 | ||||
-rw-r--r-- | core-services/99-cleanup.sh | 1 | ||||
-rw-r--r-- | halt.8 | 15 | ||||
-rw-r--r-- | halt.c | 67 | ||||
-rw-r--r-- | services/agetty-hvc0/conf | 3 | ||||
l--------- | services/agetty-hvc0/finish | 1 | ||||
l--------- | services/agetty-hvc0/run | 1 | ||||
l--------- | services/agetty-hvc0/supervise | 1 | ||||
-rw-r--r-- | services/agetty-hvsi0/conf | 8 | ||||
l--------- | services/agetty-hvsi0/finish | 1 | ||||
l--------- | services/agetty-hvsi0/run | 1 | ||||
l--------- | services/agetty-hvsi0/supervise | 1 |
14 files changed, 102 insertions, 18 deletions
diff --git a/3 b/3 index 20d7c99..7945490 100755 --- a/3 +++ b/3 @@ -27,7 +27,7 @@ if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)} fi -halt -w # for utmp +halt -w # for wtmp if [ -z "$VIRTUALIZATION" ]; then msg "Stopping udev..." diff --git a/core-services/05-misc.sh b/core-services/05-misc.sh index 8aabaa0..0f3d28c 100644 --- a/core-services/05-misc.sh +++ b/core-services/05-misc.sh @@ -1,9 +1,11 @@ # vim: set ts=4 sw=4 et: +install -m0664 -o root -g utmp /dev/null /run/utmp +halt -B # for wtmp + if [ -z "$VIRTUALIZATION" ]; then msg "Initializing random seed..." cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true - ( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 ) fi msg "Setting up loopback interface..." diff --git a/core-services/08-sysctl.sh b/core-services/08-sysctl.sh index 37d7b9f..3df5c5a 100644 --- a/core-services/08-sysctl.sh +++ b/core-services/08-sysctl.sh @@ -2,15 +2,19 @@ if [ -x /sbin/sysctl -o -x /bin/sysctl ]; then msg "Loading sysctl(8) settings..." + mkdir -p /run/vsysctl.d for i in /run/sysctl.d/*.conf \ /etc/sysctl.d/*.conf \ /usr/local/lib/sysctl.d/*.conf \ - /usr/lib/sysctl.d/*.conf \ - /etc/sysctl.conf; do + /usr/lib/sysctl.d/*.conf; do - if [ -e "$i" ]; then - printf '* Applying %s ...\n' "$i" - sysctl -p "$i" + if [ -e "$i" ] && [ ! -e "/run/vsysctl.d/${i##*/}" ]; then + ln -s "$i" "/run/vsysctl.d/${i##*/}" fi done + for i in /run/vsysctl.d/*.conf; do + sysctl -p "$i" + done + rm -rf -- /run/vsysctl.d + sysctl -p /etc/sysctl.conf fi diff --git a/core-services/99-cleanup.sh b/core-services/99-cleanup.sh index 2d7da1d..f27f728 100644 --- a/core-services/99-cleanup.sh +++ b/core-services/99-cleanup.sh @@ -1,6 +1,5 @@ # vim: set ts=4 sw=4 et: -install -m0664 -o root -g utmp /dev/null /run/utmp if [ ! -e /var/log/wtmp ]; then install -m0664 -o root -g utmp /dev/null /var/log/wtmp fi diff --git a/halt.8 b/halt.8 index 8930ad3..47d9020 100644 --- a/halt.8 +++ b/halt.8 @@ -1,4 +1,4 @@ -.Dd July 29, 2014 +.Dd September 5, 2019 .Dt HALT 8 .Os Linux .Sh NAME @@ -10,6 +10,9 @@ .Nm halt .Op Fl n .Op Fl f +.Op Fl d +.Op Fl w +.Op Fl B .Nm reboot .Op Fl n .Op Fl f @@ -40,6 +43,12 @@ Force halt or reboot, don't call .Xr init 8 . This is .Sy dangerous ! +.It Fl d +Do not write the wtmp record. +.It Fl w +Just write the wtmp record. +.It Fl B +Just write the wtmp record, but for a boot. .El .Sh UNSUPPORTED OPTIONS This version of @@ -50,10 +59,6 @@ the following features are .Sy not supported and silently ignored: .Bl -tag -width indent -.It Fl w -to just write the wtmp record. -.It Fl d -to not write the wtmp record. .It Fl h to put hard drives in standby mode. .It Fl i diff --git a/halt.c b/halt.c index 9ea75bc..3f1062e 100644 --- a/halt.c +++ b/halt.c @@ -1,16 +1,65 @@ -#include <errno.h> -#include <unistd.h> +#include <sys/reboot.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/utsname.h> + #include <err.h> +#include <errno.h> +#include <fcntl.h> #include <string.h> -#include <sys/reboot.h> +#include <unistd.h> +#include <utmp.h> extern char *__progname; typedef enum {NOOP, HALT, REBOOT, POWEROFF} action_type; +#ifndef OUR_WTMP +#define OUR_WTMP "/var/log/wtmp" +#endif + +#ifndef OUR_UTMP +#define OUR_UTMP "/run/utmp" +#endif + +void write_wtmp(int boot) { + int fd; + + if ((fd = open(OUR_WTMP, O_WRONLY|O_APPEND)) < 0) + return; + + struct utmp utmp = {0}; + struct utsname uname_buf; + struct timeval tv; + + gettimeofday(&tv, 0); + utmp.ut_tv.tv_sec = tv.tv_sec; + utmp.ut_tv.tv_usec = tv.tv_usec; + + utmp.ut_type = boot ? BOOT_TIME : RUN_LVL; + + strncpy(utmp.ut_name, boot ? "reboot" : "shutdown", sizeof utmp.ut_name); + strncpy(utmp.ut_id , "~~", sizeof utmp.ut_id); + strncpy(utmp.ut_line, boot ? "~" : "~~", sizeof utmp.ut_line); + if (uname(&uname_buf) == 0) + strncpy(utmp.ut_host, uname_buf.release, sizeof utmp.ut_host); + + write(fd, (char *)&utmp, sizeof utmp); + close(fd); + + if (boot) { + if ((fd = open(OUR_UTMP, O_WRONLY|O_APPEND)) < 0) + return; + write(fd, (char *)&utmp, sizeof utmp); + close(fd); + } +} + int main(int argc, char *argv[]) { int do_sync = 1; int do_force = 0; + int do_wtmp = 1; int opt; action_type action = NOOP; @@ -23,7 +72,7 @@ int main(int argc, char *argv[]) { else warnx("no default behavior, needs to be called as halt/reboot/poweroff."); - while ((opt = getopt(argc, argv, "dfhinw")) != -1) + while ((opt = getopt(argc, argv, "dfhinwB")) != -1) switch (opt) { case 'n': do_sync = 0; @@ -33,6 +82,8 @@ int main(int argc, char *argv[]) { do_sync = 0; break; case 'd': + do_wtmp = 0; + break; case 'h': case 'i': /* silently ignored. */ @@ -40,10 +91,16 @@ int main(int argc, char *argv[]) { case 'f': do_force = 1; break; + case 'B': + write_wtmp(1); + return 0; default: - errx(1, "Usage: %s [-n] [-f]", __progname); + errx(1, "Usage: %s [-n] [-f] [-d] [-w] [-B]", __progname); } + if (do_wtmp) + write_wtmp(0); + if (do_sync) sync(); diff --git a/services/agetty-hvc0/conf b/services/agetty-hvc0/conf new file mode 100644 index 0000000..ecf4f1e --- /dev/null +++ b/services/agetty-hvc0/conf @@ -0,0 +1,3 @@ +GETTY_ARGS="-L" +BAUD_RATE=9600 +TERM_NAME=vt100 diff --git a/services/agetty-hvc0/finish b/services/agetty-hvc0/finish new file mode 120000 index 0000000..ad464cb --- /dev/null +++ b/services/agetty-hvc0/finish @@ -0,0 +1 @@ +../agetty-generic/finish \ No newline at end of file diff --git a/services/agetty-hvc0/run b/services/agetty-hvc0/run new file mode 120000 index 0000000..ffa62a5 --- /dev/null +++ b/services/agetty-hvc0/run @@ -0,0 +1 @@ +../agetty-serial/run \ No newline at end of file diff --git a/services/agetty-hvc0/supervise b/services/agetty-hvc0/supervise new file mode 120000 index 0000000..665ccf0 --- /dev/null +++ b/services/agetty-hvc0/supervise @@ -0,0 +1 @@ +/run/runit/supervise.agetty-hvc0 \ No newline at end of file diff --git a/services/agetty-hvsi0/conf b/services/agetty-hvsi0/conf new file mode 100644 index 0000000..ec61b5f --- /dev/null +++ b/services/agetty-hvsi0/conf @@ -0,0 +1,8 @@ +GETTY_ARGS="-L" +if [ -x /sbin/agetty -o -x /bin/agetty ]; then + # util-linux specific settings + GETTY_ARGS="${GETTY_ARGS} -8" +fi + +BAUD_RATE=19200 +TERM_NAME=vt100 diff --git a/services/agetty-hvsi0/finish b/services/agetty-hvsi0/finish new file mode 120000 index 0000000..ad464cb --- /dev/null +++ b/services/agetty-hvsi0/finish @@ -0,0 +1 @@ +../agetty-generic/finish \ No newline at end of file diff --git a/services/agetty-hvsi0/run b/services/agetty-hvsi0/run new file mode 120000 index 0000000..ffa62a5 --- /dev/null +++ b/services/agetty-hvsi0/run @@ -0,0 +1 @@ +../agetty-serial/run \ No newline at end of file diff --git a/services/agetty-hvsi0/supervise b/services/agetty-hvsi0/supervise new file mode 120000 index 0000000..7dd4fb6 --- /dev/null +++ b/services/agetty-hvsi0/supervise @@ -0,0 +1 @@ +/run/runit/supervise.agetty-hvsi0 \ No newline at end of file |