mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone
Blob Blame History Raw
From 2bb0c9f0596ef616992a248dec535c3dffc0337d Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 19 Mar 2016 18:27:07 +0000
Subject: [PATCH] appliance: init: Move cmdline parsing earlier.

Since commit bb5d30ab2af5720775c63179afdec3ad9efd510d, we don't
require any external programs like grep to parse the command line.  We
only use bash intrinsics.

Therefore we can do it early (but after /proc is mounted).

This allows verbose mode to enable set -x early on, so we can trace
most things that the init script does.

(cherry picked from commit cb8f69e95929e512fcb8882ffb647dc72fc4a865)
---
 appliance/init | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/appliance/init b/appliance/init
index 239b50e..55b1a35 100755
--- a/appliance/init
+++ b/appliance/init
@@ -33,9 +33,29 @@ done
 
 mkdir -p /sysroot
 
+# Mount /proc.
 if [ ! -d /proc ]; then rm -f /proc; fi
 mkdir -p /proc
 mount -t proc /proc /proc
+
+# Parse the kernel command line early (must be after /proc is mounted).
+cmdline=$(</proc/cmdline)
+
+if [[ $cmdline == *guestfs_verbose=1* ]]; then
+    guestfs_verbose=1
+    set -x
+fi
+if [[ $cmdline == *guestfs_network=1* ]]; then
+    guestfs_network=1
+fi
+if [[ $cmdline == *guestfs_rescue=1* ]]; then
+    guestfs_rescue=1
+fi
+if [[ $cmdline == *guestfs_noreboot=1* ]]; then
+    guestfs_noreboot=1
+fi
+
+# Mount the other special filesystems.
 if [ ! -d /sys ]; then rm -f /sys; fi
 mkdir -p /sys
 mount -t sysfs /sys /sys
@@ -77,8 +97,6 @@ $UDEVD --daemon #--debug
 udevadm trigger
 udevadm settle --timeout=600
 
-cmdline=$(</proc/cmdline)
-
 if [[ $cmdline == *selinux=1* ]]; then
   mount -t selinuxfs none /sys/fs/selinux
 fi
@@ -94,22 +112,6 @@ shopt -u nullglob
 # Update the system clock.
 hwclock -u -s
 
-# Parse the kernel command line.
-if [[ $cmdline == *guestfs_verbose=1* ]]; then
-    guestfs_verbose=1
-    set -x
-fi
-if [[ $cmdline == *guestfs_network=1* ]]; then
-    guestfs_network=1
-fi
-if [[ $cmdline == *guestfs_rescue=1* ]]; then
-    guestfs_rescue=1
-fi
-if [[ $cmdline == *guestfs_noreboot=1* ]]; then
-    guestfs_noreboot=1
-fi
-eval `grep -Eo 'guestfs_channel=[^[:space:]]+' /proc/cmdline`
-
 # Set up the network.
 ip addr add 127.0.0.1/8 brd + dev lo scope host
 ip link set dev lo up
@@ -157,6 +159,7 @@ fi
 if ! test "$guestfs_rescue" = 1; then
   # Run the daemon.
   cmd="guestfsd"
+  eval `grep -Eo 'guestfs_channel=[^[:space:]]+' /proc/cmdline`
   if test "x$guestfs_channel" != "x"; then
     cmd="$cmd --channel $guestfs_channel"
   fi
-- 
1.8.3.1