summary refs log tree commit diff
path: root/nixos/modules/system/boot/stage-1-init.sh
diff options
context:
space:
mode:
authorRoger Qiu <roger.qiu@polycademy.com>2016-02-22 16:42:24 +1100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-23 11:56:08 +0100
commit142f65e07a7f3c8d37eb150443140213d80a7046 (patch)
treef7ffe5cb3e7b5e3f26ebf3681e0fff251e260b92 /nixos/modules/system/boot/stage-1-init.sh
parent8b3d057c78b3c4c0e70604e41133b21dad3f4718 (diff)
downloadnixlib-142f65e07a7f3c8d37eb150443140213d80a7046.tar
nixlib-142f65e07a7f3c8d37eb150443140213d80a7046.tar.gz
nixlib-142f65e07a7f3c8d37eb150443140213d80a7046.tar.bz2
nixlib-142f65e07a7f3c8d37eb150443140213d80a7046.tar.lz
nixlib-142f65e07a7f3c8d37eb150443140213d80a7046.tar.xz
nixlib-142f65e07a7f3c8d37eb150443140213d80a7046.tar.zst
nixlib-142f65e07a7f3c8d37eb150443140213d80a7046.zip
nixos/stage-1: Added boot.initrd.logCommands
Diffstat (limited to 'nixos/modules/system/boot/stage-1-init.sh')
-rw-r--r--nixos/modules/system/boot/stage-1-init.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh
index 95df0ace1ca4..94cecdf1fd79 100644
--- a/nixos/modules/system/boot/stage-1-init.sh
+++ b/nixos/modules/system/boot/stage-1-init.sh
@@ -71,6 +71,24 @@ mount -t devtmpfs -o "size=@devSize@" devtmpfs /dev
 mkdir -p /run
 mount -t tmpfs -o "mode=0755,size=@runSize@" tmpfs /run
 
+# Optionally log the script output to /dev/kmsg or /run/log/stage-1-init.log 
+if test -n "@logCommands@"; then
+    mkdir -p /tmp
+    mkfifo /tmp/stage-1-init.log.fifo
+    logOutFd=8 && logErrFd=9
+    eval "exec $logOutFd>&1 $logErrFd>&2"
+    if test -w /dev/kmsg; then
+        tee -i < /tmp/stage-1-init.log.fifo /proc/self/fd/"$logOutFd" | while read line; do
+            if test -n "$line"; then
+                echo "stage-1-init: $line" > /dev/kmsg
+            fi
+        done &
+    else
+        mkdir -p /run/log
+        tee -i < /tmp/stage-1-init.log.fifo /run/log/stage-1-init.log &
+    fi
+    exec > /tmp/stage-1-init.log.fifo 2>&1
+fi
 
 # Process the kernel command line.
 export stage2Init=/init
@@ -415,6 +433,14 @@ fi
 # Stop udevd.
 udevadm control --exit
 
+# Reset the logging file descriptors.
+# Do this just before pkill, which will kill the tee process.
+if test -n "@logCommands@"
+then
+    exec 1>&$logOutFd 2>&$logErrFd
+    eval "exec $logOutFd>&- $logErrFd>&-"
+fi
+
 # Kill any remaining processes, just to be sure we're not taking any
 # with us into stage 2. But keep storage daemons like unionfs-fuse.
 pkill -9 -v -f '@'