From 3db5ad738151d27001658d570bce0c61648fc2cc Mon Sep 17 00:00:00 2001 From: Miloslav Trmac Date: Thu, 27 Jul 2006 02:17:03 +0000 Subject: Consistently exclude backup files when globbing --- rc.d/init.d/functions | 12 ++++++++++++ rc.d/init.d/network | 9 ++++----- rc.d/rc | 8 +------- rc.d/rc.sysinit | 1 + service | 10 ++++------ sysconfig/network-scripts/ifup-aliases | 7 ++++--- sysconfig/network-scripts/ifup-eth | 13 ++++++++----- sysconfig/network-scripts/network-functions | 8 ++++++-- 8 files changed, 40 insertions(+), 28 deletions(-) diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 19a86c16..2576f463 100755 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -573,3 +573,15 @@ resolve_dm_name() { /sbin/dmsetup table | egrep -iv "no block devices found|No devices found" | sed -n "s/\(^[^:]\+\): $newline\( \+$\|$\)/\1/p" ) 2>/dev/null } + +# Check whether file $1 is a backup or rpm-generated file and should be ignored +is_ignored_file() { + case "$1" in + *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave) + return 0 + ;; + esac + return 1 +} +# A sed expression to filter out the files that is_ignored_file recognizes +__sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' diff --git a/rc.d/init.d/network b/rc.d/init.d/network index a16a2692..19fa0264 100755 --- a/rc.d/init.d/network +++ b/rc.d/init.d/network @@ -43,13 +43,12 @@ cd /etc/sysconfig/network-scripts # find all the interfaces besides loopback. # ignore aliases, alternative configurations, and editor backup files -interfaces=`ls ifcfg* | \ - LANG=C sed -e '/\(ifcfg-lo\|:\|ifcfg-.*-range\)/d' \ - -e '/\(rpmsave\|rpmorig\|rpmnew\)/d' \ - -e '/\(~\|\.bak\)$/d' \ +interfaces=$(ls ifcfg* | \ + LANG=C sed -e "$__sed_discard_ignored_files" \ + -e '/\(ifcfg-lo\|:\|ifcfg-.*-range\)/d' \ -e '/ifcfg-[A-Za-z0-9\._-]\+$/ { s/^ifcfg-//g;s/[0-9]/ &/}' | \ LANG=C sort -k 1,1 -k 2n | \ - LANG=C sed 's/ //'` + LANG=C sed 's/ //') # See how we were called. case "$1" in diff --git a/rc.d/rc b/rc.d/rc index 626fcaac..9fc6eba5 100755 --- a/rc.d/rc +++ b/rc.d/rc @@ -12,13 +12,7 @@ check_runlevel () { # Check if the file exists at all. [ -x "$1" ] || return 1 - - # Reject backup files and files generated by rpm. - case "$1" in - *.rpmsave|*.rpmorig|*.rpmnew|*~|*.orig) - return 1 - ;; - esac + is_ignored_file "$1" && return 1 return 0 } diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit index e48d700b..f2139626 100755 --- a/rc.d/rc.sysinit +++ b/rc.d/rc.sysinit @@ -496,6 +496,7 @@ if [ "$READONLY" = "yes" ]; then fi for file in /etc/rwtab /etc/rwtab.d/* ; do + is_ignored_file "$file" && continue [ -f $file ] && cat $file | while read type path ; do case "$type" in empty) diff --git a/service b/service index c6f4be19..d65d3ff7 100755 --- a/service +++ b/service @@ -1,8 +1,6 @@ #!/bin/sh -# Set up a default search path. -PATH="/sbin:/usr/sbin:/bin:/usr/bin" -export PATH +. /etc/init.d/functions VERSION="`basename $0` ver. 0.91" USAGE="Usage: `basename $0` < option > | --status-all | \ @@ -32,11 +30,11 @@ while [ $# -gt 0 ]; do cd ${SERVICEDIR} for SERVICE in * ; do case "${SERVICE}" in - functions | halt | killall | single| linuxconf| kudzu | \ - *rpmorig | *rpmnew | *rpmsave | *~ | *.orig) + functions | halt | killall | single| linuxconf| kudzu) ;; *) - if [ -x "${SERVICEDIR}/${SERVICE}" ]; then + if ! is_ignored_file "${SERVICE}" \ + && [ -x "${SERVICEDIR}/${SERVICE}" ]; then env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" status fi ;; diff --git a/sysconfig/network-scripts/ifup-aliases b/sysconfig/network-scripts/ifup-aliases index c5a9f840..7d0acc35 100755 --- a/sysconfig/network-scripts/ifup-aliases +++ b/sysconfig/network-scripts/ifup-aliases @@ -317,7 +317,8 @@ function new_interface () if [ "$BASH_VERSINFO" ]; then shopt -s nullglob; else allow_null_glob_expansion=foo; fi -for FILE in ifcfg-${parent_device}:*[^~] ; do +for FILE in ifcfg-${parent_device}:* ; do + is_ignored_file "$FILE" && continue ini_env; . $FILE; [ -z "$DEVICE" ] && DEVICE=${FILE##ifcfg-} @@ -325,8 +326,8 @@ for FILE in ifcfg-${parent_device}:*[^~] ; do unset DEVICE done -for FILE in ifcfg-${parent_device}-range*[^~] ; do - +for FILE in ifcfg-${parent_device}-range* ; do + is_ignored_file "$FILE" && continue ini_env; . $FILE; diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth index 586c565e..e36691a2 100755 --- a/sysconfig/network-scripts/ifup-eth +++ b/sysconfig/network-scripts/ifup-eth @@ -118,11 +118,12 @@ if [ "${TYPE}" = "Bonding" ] || ethtool -i $DEVICE 2>/dev/null| grep -q "driver /sbin/ip link set dev ${DEVICE} down /sbin/ip link set dev ${DEVICE} up [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY} - for device in `LANG=C grep -l "^[[:space:]]*MASTER=${DEVICE}" /etc/sysconfig/network-scripts/ifcfg-*` ; do - if [ "$BOOTPROTO" = "dhcp" ]; then - /sbin/ifup ${device##*/} - fi - done + if [ "$BOOTPROTO" = "dhcp" ]; then + for device in `LANG=C grep -l "^[[:space:]]*MASTER=${DEVICE}" /etc/sysconfig/network-scripts/ifcfg-*` ; do + is_ignored_file "$device" && continue + /sbin/ifup ${device##*/} + done + fi fi # this isn't the same as the MAC in the configuration filename. It is @@ -200,6 +201,7 @@ else # Bonding initialization part II if [ "${TYPE}" = "Bonding" ] || ethtool -i $DEVICE 2>/dev/null| grep -q "driver: bonding" ; then for device in `LANG=C grep -l "^[[:space:]]*MASTER=${DEVICE}" /etc/sysconfig/network-scripts/ifcfg-*` ; do + is_ignored_file "$device" && continue /sbin/ifup ${device##*/} done fi @@ -276,6 +278,7 @@ fi # DHCP, remove any routes for the slaves. if [ "${TYPE}" = "Bonding" ] || ethtool -i $DEVICE 2>/dev/null| grep -q "driver: bonding" ; then for device in `LANG=C grep -l "^[[:space:]]*MASTER=${DEVICE}" /etc/sysconfig/network-scripts/ifcfg-*` ; do + is_ignored_file "$device" && continue if [ "$BOOTPROTO" = "dhcp" ]; then DEV=$DEVICE (. $device diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 3a333147..ca2d802a 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -7,6 +7,8 @@ PATH="/sbin:/usr/sbin:/bin:/usr/bin" export PATH +[ -z "$__sed_discard_ignored_files" ] && . /etc/init.d/functions + get_hwaddr () { if [ -f /sys/class/net/${1}/address ]; then @@ -20,7 +22,8 @@ get_hwaddr () get_config_by_hwaddr () { - LANG=C grep -il "^[[:space:]]*HWADDR=${1}\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-* + LANG=C grep -il "^[[:space:]]*HWADDR=${1}\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-* \ + | LC_ALL=C sed -e "$__sed_discard_ignored_files" } get_device_by_hwaddr () @@ -45,7 +48,8 @@ need_config () fi fi nconfig=$(LANG=C grep -l "^[[:space:]]*DEVICE=${1}\([[:space:]#]\|$\)" \ - /etc/sysconfig/network-scripts/ifcfg-*) + /etc/sysconfig/network-scripts/ifcfg-* \ + | LC_ALL=C sed -e "$__sed_discard_ignored_files") if [ -n "$nconfig" -a -f "$nconfig" ]; then CONFIG=${nconfig##*/} return -- cgit v1.2.1