]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
shutdown: fix shutdown with console=null
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Aug 2019 19:11:59 +0000 (21:11 +0200)
committerLukáš Nykrýn <lnykryn@redhat.com>
Thu, 22 Aug 2019 14:47:32 +0000 (16:47 +0200)
C.f. https://github.com/systemd/systemd/issues/13332.

modules.d/99shutdown/shutdown.sh

index e3884a88274db5b215a6b13e28253b6886fcdc4e..a30a126fa07aae5d93fe8d2de84a911758fde261 100755 (executable)
@@ -6,7 +6,13 @@
 # Harald Hoyer <harald@redhat.com>
 ACTION="$1"
 
-[ -w /dev/console ] && exec </dev/console >>/dev/console 2>>/dev/console
+# Before trying to use /dev/console, verify that it exists,
+# and that it can actually be used. When console=null is used,
+# echo will fail. We do the check in a subshell, because otherwise
+# the process will be killed when when running as PID 1.
+[ -w /dev/console ] && \
+    ( echo </dev/console &>/dev/null ) && \
+    exec </dev/console >>/dev/console 2>>/dev/console
 
 export TERM=linux
 export PATH=/usr/sbin:/usr/bin:/sbin:/bin