[PATCH] appliance: use bash features for string matching in files
Read the content of /proc/cmdline using bash features, and use its [[ ... ]] expression to find texts in a variable. This shaves off 5 grep invocations. --- appliance/init | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/appliance/init b/appliance/init index f6fe9b9..8d662fa 100755 --- a/appliance/init +++ b/appliance/init @@ -75,7 +75,9 @@ $UDEVD --daemon #--debug udevadm trigger udevadm settle --timeout=600 -if grep -sq selinux=1 /proc/cmdline; then +cmdline=$(</proc/cmdline) + +if [[ $cmdline == *selinux=1* ]]; then mount -t selinuxfs none /sys/fs/selinux fi @@ -91,16 +93,16 @@ shopt -u nullglob hwclock -u -s # Parse the kernel command line. -if grep -sq guestfs_verbose=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_verbose=1* ]]; then guestfs_verbose=1 fi -if grep -sq guestfs_network=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_network=1* ]]; then guestfs_network=1 fi -if grep -sq guestfs_rescue=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_rescue=1* ]]; then guestfs_rescue=1 fi -if grep -sq guestfs_noreboot=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_noreboot=1* ]]; then guestfs_noreboot=1 fi eval `grep -Eo 'guestfs_channel=[^[:space:]]+' /proc/cmdline` -- 2.5.5
On Tue, Mar 22, 2016 at 03:48:53PM +0100, Pino Toscano wrote:
Read the content of /proc/cmdline using bash features, and use its [[ ... ]] expression to find texts in a variable.
This shaves off 5 grep invocations. --- appliance/init | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/appliance/init b/appliance/init index f6fe9b9..8d662fa 100755 --- a/appliance/init +++ b/appliance/init @@ -75,7 +75,9 @@ $UDEVD --daemon #--debug udevadm trigger udevadm settle --timeout=600
-if grep -sq selinux=1 /proc/cmdline; then +cmdline=$(</proc/cmdline) + +if [[ $cmdline == *selinux=1* ]]; then mount -t selinuxfs none /sys/fs/selinux fi
@@ -91,16 +93,16 @@ shopt -u nullglob hwclock -u -s
# Parse the kernel command line. -if grep -sq guestfs_verbose=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_verbose=1* ]]; then guestfs_verbose=1 fi -if grep -sq guestfs_network=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_network=1* ]]; then guestfs_network=1 fi -if grep -sq guestfs_rescue=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_rescue=1* ]]; then guestfs_rescue=1 fi -if grep -sq guestfs_noreboot=1 /proc/cmdline; then +if [[ $cmdline == *guestfs_noreboot=1* ]]; then guestfs_noreboot=1 fi eval `grep -Eo 'guestfs_channel=[^[:space:]]+' /proc/cmdline`
ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
participants (2)
-
Pino Toscano -
Richard W.M. Jones