Skip to content

Commit

Permalink
UTMP support is gone, remove dependency
Browse files Browse the repository at this point in the history
also add support for initramfs at shutdown.

Signed-off-by: Werner Fink <[email protected]>
  • Loading branch information
bitstreamout committed Nov 29, 2023
1 parent 33eac85 commit a5556a9
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 29 deletions.
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 \
Expand All @@ -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 ; \
Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 0 additions & 3 deletions blog-final.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ RefuseManualStart=true
Type=forking
SendSIGKILL=no
ExecStart=/sbin/blogd -f

[Install]
WantedBy=shutdown.target
5 changes: 0 additions & 5 deletions blog-quit.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ Type=oneshot
TimeoutSec=20
RemainAfterExit=yes
ExecStart=/sbin/blogctl quit

[Install]
WantedBy=default.target
WantedBy=emergency.target
WantedBy=rescue.target
6 changes: 1 addition & 5 deletions blog-store-messages.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions blog-switch-initramfs.service
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion blog-switch-root.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions blog-umount.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions blog.service
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ Type=forking
SendSIGKILL=no
RemainAfterExit=yes
ExecStart=/sbin/blogd

[Install]
WantedBy=basic.target
15 changes: 12 additions & 3 deletions blogd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion libconsole/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a5556a9

Please sign in to comment.