diff options
-rwxr-xr-x | 3 | 8 | ||||
-rw-r--r-- | core-services/05-misc.sh | 10 | ||||
-rw-r--r-- | core-services/08-sysctl.sh | 14 | ||||
-rw-r--r-- | core-services/99-cleanup.sh | 1 | ||||
-rw-r--r-- | functions | 2 | ||||
-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 | ||||
-rw-r--r-- | vlogger.8 | 49 | ||||
-rw-r--r-- | vlogger.c | 15 |
17 files changed, 156 insertions, 42 deletions
diff --git a/3 b/3 index 42d6c22..7945490 100755 --- a/3 +++ b/3 @@ -18,14 +18,16 @@ sv exit /var/service/* [ -x /etc/rc.shutdown ] && /etc/rc.shutdown -msg "Saving random seed..." -( 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 ) +if [ -z "$VIRTUALIZATION" ]; then + msg "Saving random seed..." + ( 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 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 743dcdb..0f3d28c 100644 --- a/core-services/05-misc.sh +++ b/core-services/05-misc.sh @@ -1,8 +1,12 @@ # vim: set ts=4 sw=4 et: -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 ) +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 +fi msg "Setting up loopback interface..." ip link set up dev lo 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/functions b/functions index e0c37c8..17850e2 100644 --- a/functions +++ b/functions @@ -17,7 +17,7 @@ msg_error() { msg_warn() { # bold/yellow - printf "\033[1m\033[33mWARNING: $@\033[m" + printf "\033[1m\033[33mWARNING: $@\033[m\n" } emergency_shell() { 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 diff --git a/vlogger.8 b/vlogger.8 index d2e88ff..b7919d9 100644 --- a/vlogger.8 +++ b/vlogger.8 @@ -12,17 +12,35 @@ .Op Fl t Ar tag .Op Ar message ... .Sh DESCRIPTION -By default, +The .Nm -reads lines from +utility writes messages to the system log. +.Pp +With +.Ar message +arguments +.Nm +will always write messages to the system log. +Without +.Ar message +arguments +.Nm +reads messages from .Dv stdin -and sends them to syslog. -If the file +or the file specified with the +.Fl f +flag. +If the .Pa /etc/vlogger -exists and is executable it is executed with -.Ar tag -as only argument and replaces -.Nm . +executable exists +.Nm +executes it with +.Ar tag , +level +and priority as arguments, +replacing the +.Nm +process. .Pp If .Nm @@ -34,10 +52,10 @@ supervision suite it uses the service name as default As example if .Nm is linked to -.Dv /var/service/foo/log/run +.Pa /var/service/foo/log/run it uses -.Dv foo -as default +.Dq foo +as .Ar tag . .Pp The options are as follows: @@ -45,7 +63,9 @@ The options are as follows: .It Fl f Ar file Read lines from the specified .Ar file . -This +This option cannot be combine +.Ar message +arguments. .It Fl i Log the PID of the .Nm @@ -66,7 +86,7 @@ See or .Xr syslog 3 . The default is -.Pa daemon.info . +.Dq user.notice . .It Fl S Force .Nm @@ -87,6 +107,9 @@ Defines the .Pa ident which is used as prefix for each log message or passed as first argument to .Pa /etc/vlogger . +The default is the +.Ev LOGNAME +environment variable. .It Ar message Write the .Ar message diff --git a/vlogger.c b/vlogger.c index 949fb5b..64f1a2e 100644 --- a/vlogger.c +++ b/vlogger.c @@ -78,12 +78,12 @@ main(int argc, char *argv[]) { char buf[1024]; char *p, *argv0; - char *tag = "vlogger"; + char *tag = NULL; int c; int Sflag = 0; int logflags = 0; - int facility = LOG_DAEMON; - int level = LOG_INFO; + int facility = LOG_USER; + int level = LOG_NOTICE; argv0 = *argv; @@ -94,7 +94,7 @@ main(int argc, char *argv[]) *p = '\0'; if ((p = strrchr(pwd, '/')) && strncmp(p+1, "log", 3) == 0 && (*p = '\0', (p = strrchr(pwd, '/'))) && (*(p+1) != '\0')) { - tag = strdup(p+1); + tag = p+1; } } } @@ -119,9 +119,12 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + if (argc > 0) + Sflag++; + if (!Sflag && access("/etc/vlogger", X_OK) != -1) { CODE *cp; - const char *sfacility, *slevel; + const char *sfacility = "", *slevel = ""; for (cp = prioritynames; cp->c_name; cp++) { if (cp->c_val == level) slevel = cp->c_name; @@ -135,7 +138,7 @@ main(int argc, char *argv[]) exit(1); } - openlog(tag, logflags, facility); + openlog(tag ? tag : getlogin(), logflags, facility); if (argc > 0) { size_t len; |