From a5556a90c532eb0da6a0da31825ca220746453be Mon Sep 17 00:00:00 2001 From: Werner Fink Date: Wed, 29 Nov 2023 13:17:01 +0100 Subject: [PATCH] UTMP support is gone, remove dependency also add support for initramfs at shutdown. Signed-off-by: Werner Fink --- Makefile | 14 +++++++++----- blog-final.service | 3 --- blog-quit.service | 5 ----- blog-store-messages.service.in | 6 +----- blog-switch-initramfs.service | 17 +++++++++++++++++ blog-switch-root.service | 2 +- blog-umount.service.in | 4 +--- blog.service | 3 --- blogd.c | 15 ++++++++++++--- libconsole/log.c | 2 +- 10 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 blog-switch-initramfs.service diff --git a/Makefile b/Makefile index 65fc467..931c119 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ BOOT_FIFO = /dev/blog DEBUG = DESTDIR = MAJOR := 2 -MINOR := 24 +MINOR := 28 VERSION := $(MAJOR).$(MINOR) DATE = $(shell date +'%d%b%y' | tr '[:lower:]' '[:upper:]') COPTS = @@ -137,13 +137,13 @@ install: $(TODO) $(INSTSCR) module-setup.sh $(DESTDIR)$(DRACUTMOD)/ $(LINK) libblogger.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libblogger.so.$(MAJOR) $(LINK) libblogger.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libblogger.so - for unit in blog blog-final blog-quit blog-store-messages blog-switch-root blog-umount ; do \ + for unit in blog blog-final blog-quit blog-store-messages blog-switch-root blog-switch-initramfs blog-umount ; do \ $(INSTCON) $${unit}.service $(DESTDIR)$(SYSDUNITS)/ ; \ done for unit in systemd-ask-password-blog.path systemd-ask-password-blog.service ; do \ $(INSTCON) $${unit} $(DESTDIR)$(SYSDUNITS)/ ; \ done - for target in default sysinit basic local-fs-pre rescue shutdown emergency initrd-switch-root; do \ + for target in default sysinit basic local-fs-pre rescue shutdown reboot poweroff kexec emergency initrd-switch-root; do \ $(MKDIR) $(DESTDIR)$(SYSDUNITS)/$${target}.target.wants ; \ done for service in systemd-ask-password-blog ; do \ @@ -163,8 +163,11 @@ install: $(TODO) for unit in blog-umount.service ; do \ $(LINK) ../$${unit} $(DESTDIR)$(SYSDUNITS)/local-fs-pre.target.wants/$${unit} ; \ done - for unit in blog-final.service ; do \ + for unit in blog-final.service blog-switch-initramfs.service ; do \ $(LINK) ../$${unit} $(DESTDIR)$(SYSDUNITS)/shutdown.target.wants/$${unit} ; \ + $(LINK) ../$${unit} $(DESTDIR)$(SYSDUNITS)/reboot.target.wants/$${unit} ; \ + $(LINK) ../$${unit} $(DESTDIR)$(SYSDUNITS)/poweroff.target.wants/$${unit} ; \ + $(LINK) ../$${unit} $(DESTDIR)$(SYSDUNITS)/kexec.target.wants/$${unit} ; \ done for target in systemd-ask-password-blog.service ; do \ $(MKDIR) $(DESTDIR)$(SYSDUNITS)/$${target}.wants ; \ @@ -203,7 +206,8 @@ FILES = README \ blog-quit.service \ blog-store-messages.service.in \ blog-switch-root.service \ - blog-umount.service.in \ + blog-switch-initramfs.service \ + blog-umount.service.in \ systemd-ask-password-blog.path \ systemd-ask-password-blog.service \ module-setup.sh \ diff --git a/blog-final.service b/blog-final.service index 673634b..45f6e01 100644 --- a/blog-final.service +++ b/blog-final.service @@ -8,6 +8,3 @@ RefuseManualStart=true Type=forking SendSIGKILL=no ExecStart=/sbin/blogd -f - -[Install] -WantedBy=shutdown.target diff --git a/blog-quit.service b/blog-quit.service index 95732bf..44c9184 100644 --- a/blog-quit.service +++ b/blog-quit.service @@ -12,8 +12,3 @@ Type=oneshot TimeoutSec=20 RemainAfterExit=yes ExecStart=/sbin/blogctl quit - -[Install] -WantedBy=default.target -WantedBy=emergency.target -WantedBy=rescue.target diff --git a/blog-store-messages.service.in b/blog-store-messages.service.in index abff18e..a6da2e3 100644 --- a/blog-store-messages.service.in +++ b/blog-store-messages.service.in @@ -3,17 +3,13 @@ Description=Tell blogd about writable boot log DefaultDependencies=no RequiresMountsFor=@@BOOT_LOGFILE@@ Conflicts=shutdown.target -Requisite=systemd-update-utmp.service -After=systemd-update-utmp.service After=systemd-remount-fs.service systemd-tmpfiles-setup.service auditd.service Before=sysinit.target shutdown.target ConditionPathExists=!/etc/initrd-release +ConditionPathIsReadWrite=/var/log [Service] Type=oneshot TimeoutSec=20 RemainAfterExit=yes ExecStart=/sbin/blogctl ready - -[Install] -WantedBy=sysinit.target diff --git a/blog-switch-initramfs.service b/blog-switch-initramfs.service new file mode 100644 index 0000000..78d96e5 --- /dev/null +++ b/blog-switch-initramfs.service @@ -0,0 +1,17 @@ +[Unit] +Description=Tell blogd to switch to initramfs +DefaultDependencies=no +# dracut-shutdown.service restores the initramfs when it is _stopped_ +# use Conflicts to make sure its ExecStop has run before we do +Conflicts=dracut-shutdown.service +After=plymouth-final.service blog-umount.service dracut-shutdown.service mkinitcpio-generate-shutdown-ramfs.service +ConditionPathExists=|/run/initramfs/bin/sh +ConditionPathExists=|/run/initramfs/shutdown + +[Service] +Type=oneshot +StandardInput=null +StandardOutput=null +StandardError=null +RemainAfterExit=yes +ExecStart=-/sbin/blogctl root=/run/initramfs diff --git a/blog-switch-root.service b/blog-switch-root.service index 62395fc..20b5d31 100644 --- a/blog-switch-root.service +++ b/blog-switch-root.service @@ -5,8 +5,8 @@ ConditionPathExists=/etc/initrd-release Before=initrd-switch-root.service [Service] -ExecStart=-/sbin/blogctl root=/sysroot Type=oneshot StandardInput=null StandardOutput=null StandardError=null +ExecStart=-/sbin/blogctl root=/sysroot diff --git a/blog-umount.service.in b/blog-umount.service.in index e1072cf..c303855 100644 --- a/blog-umount.service.in +++ b/blog-umount.service.in @@ -4,12 +4,10 @@ DefaultDependencies=no Conflicts=shutdown.target Before=systemd-tmpfiles-setup.service RequiresMountsFor=@@BOOT_OLDLOGFILE@@ +ConditionPathIsReadWrite=/var/log [Service] Type=oneshot TimeoutSec=0 RemainAfterExit=yes ExecStop=/sbin/blogctl close - -[Install] -WantedBy=local-fs-pre.target diff --git a/blog.service b/blog.service index 6904e92..7898b94 100644 --- a/blog.service +++ b/blog.service @@ -15,6 +15,3 @@ Type=forking SendSIGKILL=no RemainAfterExit=yes ExecStart=/sbin/blogd - -[Install] -WantedBy=basic.target diff --git a/blogd.c b/blogd.c index 0ca0f9e..335ec47 100644 --- a/blogd.c +++ b/blogd.c @@ -342,9 +342,18 @@ int main(int argc, char *argv[]) /* * Reconnecting to stdin aka ptm to 0 is done after we fork away */ - - dup2(pts, 1); - dup2(pts, 2); /* Now we are blind upto safeIO() loop */ +#ifdef DEBUG + int l; + if ((l = open("/dev/shm/blog.out", O_WRONLY|O_NOCTTY|O_NONBLOCK|O_CREAT|O_APPEND, S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)) >= 0) { + dup2(l, STDOUT_FILENO); + dup2(l, STDERR_FILENO); + close(l); + } else +#endif + { + dup2(pts, 1); + dup2(pts, 2); /* Now we are blind upto safeIO() loop */ + } if (pts > 2) close(pts); diff --git a/libconsole/log.c b/libconsole/log.c index 3bfbad9..3fb9336 100644 --- a/libconsole/log.c +++ b/libconsole/log.c @@ -608,7 +608,7 @@ void stop_logging(void) unlock(&ljoin); ljoin.canceled = 1; pthread_cond_broadcast(&lcond); - pthread_yield(); + sched_yield(); if (ljoin.used && lthread) pthread_cancel(lthread); }