summary refs log tree commit diff
path: root/nixos/modules/system/boot/stage-2-init.sh
diff options
context:
space:
mode:
authorRoger Qiu <roger.qiu@polycademy.com>2016-02-22 16:42:51 +1100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-23 11:56:09 +0100
commit474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde (patch)
tree914b516dabc0fb7a01504618a8c1828e22188669 /nixos/modules/system/boot/stage-2-init.sh
parent142f65e07a7f3c8d37eb150443140213d80a7046 (diff)
downloadnixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.tar
nixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.tar.gz
nixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.tar.bz2
nixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.tar.lz
nixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.tar.xz
nixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.tar.zst
nixpkgs-474d5a7bd00e4d3cf3e15e4f0c80a5f46b96cbde.zip
nixos/stage-2: Added boot.logCommands
Diffstat (limited to 'nixos/modules/system/boot/stage-2-init.sh')
-rw-r--r--nixos/modules/system/boot/stage-2-init.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/nixos/modules/system/boot/stage-2-init.sh b/nixos/modules/system/boot/stage-2-init.sh
index a73070ab332..17b24e1678b 100644
--- a/nixos/modules/system/boot/stage-2-init.sh
+++ b/nixos/modules/system/boot/stage-2-init.sh
@@ -155,6 +155,23 @@ mkdir -m 0755 -p /var/setuid-wrappers
 mount -t tmpfs -o "mode=0755" tmpfs /var/setuid-wrappers
 
 
+# Optionally log the script output to /dev/kmsg or /run/log/stage-2-init.log.
+# Only at this point are all the necessary prerequisites ready for these commands.
+if test -n "@logCommands@"; then
+    exec {logOutFd}>&1 {logErrFd}>&2
+    if test -w /dev/kmsg; then
+        exec > >(tee -i /proc/self/fd/"$logOutFd" | while read line; do
+            if test -n "$line"; then
+                echo "stage-2-init: $line" > /dev/kmsg
+            fi
+        done) 2>&1
+    else
+        mkdir -p /run/log
+        exec > >(tee -i /run/log/stage-2-init.log) 2>&1
+    fi
+fi
+
+
 # Run the script that performs all configuration activation that does
 # not have to be done at boot time.
 echo "running activation script..."
@@ -182,6 +199,13 @@ ln -sfn /run/booted-system /nix/var/nix/gcroots/booted-system
 @shell@ @postBootCommands@
 
 
+# Reset the logging file descriptors
+if test -n "@logCommands@"; then
+    exec 1>&$logOutFd 2>&$logErrFd
+    exec {logOutFd}>&- {logErrFd}>&-
+fi 
+
+
 # Start systemd.
 echo "starting systemd..."
 PATH=/run/current-system/systemd/lib/systemd \