|
bbmd@debian:/etc/init.d$ sudo patch -p2 < /home/bbmd/rc.patch
patch: **** Only garbage was found in the patch input.
这是一个给/etc/init.d/rc打的补丁,要怎么打上去?
- #! /bin/sh
- #
- # rc
- #
- # Starts/stops services on runlevel changes.
- #
- # Optimization: A start script is not run when the service was already
- # configured to run in the previous runlevel. A stop script is not run
- # when the the service was already configured not to run in the previous
- # runlevel.
- #
- # Authors:
- # Miquel van Smoorenburg <miquels@ci...>
- # Bruce Perens <Bruce@Pi...>
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- export PATH
- # Un-comment the following for debugging.
- # debug=echo
- test -f /etc/default/bootsplash && . /etc/default/bootsplash
- rc_splash() {
- #test "$SPLASH" != "no" && test "$_rc_splash" -eq 1 && /sbin/splash "$1"
- test "$SPLASH" != "no" && /sbin/splash.sh "$1"
- # make sure we don't add unless we really made progress
- if [ "$1" != "master" -a "$1" != "splash start" -a "$1" != "shutdown" ]
- then
- progress=$(( $progress + 1 ))
- fi
- }
- # Specify method used to enable concurrent init.d scripts.
- # Valid options are 'none', 'shell' and 'startpar'
- CONCURRENCY=none
- # Make sure the name survive changing the argument list
- scriptname="$0"
- umask 022
- #
- # Start script or program.
- #
- case "$CONCURRENCY" in
- none)
- startup() {
- action=$1
- shift
- scripts="$@"
- sh=sh
- # Debian Policy 9.3.1 requires .sh scripts in runlevel S to be sourced
- # However, some important packages currently contain .sh scripts
- # that do "exit" at some point, thus killing this process. Bad!
- #[ S = "$runlevel" ] && sh=.
- for script in $scripts ; do
- case "$script" in
- *.sh)
- if [ "." = "$sh" ] ; then
- set "$action"
- RC_SAVE_PATH="$PATH"
- $debug . "$script"
- PATH="$RC_SAVE_PATH"
- else
- $debug $sh "$script" $action
- fi
- ;;
- *)
- $debug "$script" $action
- ;;
- esac
- rc_splash "$script $action" # handle bootsplash stuff
- done
- }
- ;;
- shell)
- startup() {
- action=$1
- shift
- scripts="$@"
- sh=sh
- # Debian Policy 9.3.1 requires .sh scripts in runlevel S to be sourced
- # However, some important packages currently contain .sh scripts
- # that do "exit" at some point, thus killing this process. Bad!
- #[ S = "$runlevel" ] && sh=.
- backgrounded=0
- for script in $scripts ; do
- case "$script" in
- *.sh)
- if [ "." = "$sh" ] ; then
- set "$action"
- RC_SAVE_PATH="$PATH"
- $debug . "$script"
- PATH="$RC_SAVE_PATH"
- else
- $debug $sh "$script" $action
- fi
- ;;
- *)
- $debug "$script" $action &
- backgrounded=1
- ;;
- esac
- done
- [ 1 = "$backgrounded" ] && wait
- }
- ;;
- startpar)
- startup() {
- action=$1
- shift
- scripts="$@"
- sh=sh
- # Debian Policy 9.3.1 requires .sh scripts in runlevel S to be sourced
- # However, some important packages currently contain .sh scripts
- # that do "exit" at some point, thus killing this process. Bad!
- #[ S = "$runlevel" ] && sh=.
- # Make sure .sh scripts are sourced in runlevel S
- if [ "." = "$sh" ] ; then
- newscripts=
- for script in $scripts ; do
- case "$script" in
- *.sh)
- set "$action"
- RC_SAVE_PATH="$PATH"
- $debug . "$script"
- PATH="$RC_SAVE_PATH"
- ;;
- *)
- newscripts="$newscripts $script"
- ;;
- esac
- done
- scripts="$newscripts"
- fi
- # startpar is not working as it should yet [pere 2005-09-10]
- [ -n "$scripts" ] && $debug startpar -a $action $scripts
- $debug startpar -a $action $scripts
- }
- ;;
- esac
- on_exit() {
- echo "error: '$scriptname' exited outside the expected code flow."
- }
- trap on_exit EXIT # Enable emergency handler
- # Ignore CTRL-C only in this shell, so we can interrupt subprocesses.
- trap ":" INT QUIT TSTP
- # Set onlcr to avoid staircase effect.
- stty onlcr 0>&1
- # Now find out what the current and what the previous runlevel are.
- runlevel=$RUNLEVEL
- # Get first argument. Set new runlevel to this argument.
- [ "$1" != "" ] && runlevel=$1
- if [ "$runlevel" = "" ]
- then
- echo "Usage: $scriptname <runlevel>" >&2
- exit 1
- fi
- previous=$PREVLEVEL
- [ "$previous" = "" ] && previous=N
- export runlevel previous
- if [ S = "$runlevel" ]
- then
- #
- # See if system needs to be setup. This is ONLY meant to
- # be used for the initial setup after a fresh installation!
- #
- if [ -x /sbin/unconfigured.sh ]
- then
- /sbin/unconfigured.sh
- fi
- fi
- . /etc/default/rcS
- export VERBOSE
- #
- # initialize boosplash progress bar variables
- #
- runrcS=/etc/rcS.d
- runrc=/etc/rc$runlevel.d
- prerc=/etc/rc$previous.d
- SSC=($(echo $runrc/S*))
- case "$SSC" in
- *\*)
- sscripts=0 ;;
- *)
- sscripts=${#SSC[*]} ;;
- esac
- if [ "$previous" != "N" ]; then
- KSC=($(echo $runrc/K*))
- case "$KSC" in
- *\*)
- kscripts=0 ;;
- *)
- kscripts=${#KSC[*]} ;;
- esac
- fi
- if [ "$previous" = "N" -a "$runlevel" != "S" ]; then
- SSC=($(echo $runrcS/S*))
- case "$SSC" in
- *\*)
- sscripts=0 ;;
- *)
- progress=${#SSC[*]}
- sscripts=$((${#SSC[*]} + $sscripts)) ;;
- esac
- else
- if [ "$runlevel" = "S" ]; then
- #
- # The system is started, let bootsplash know which is next (default)
- # runlevel to calculate correct progress bar size.
- #
- SSC=($(echo $runrcS/S*))
- NXT=($( grep initdefault /etc/inittab | sed {s/:/\ /g} ))
- nextlevel=${NXT[1]}
- nextrc="/etc/rc$nextlevel.d"
- NSC=($(echo $nextrc/S*))
- sscripts=$((${#SSC[*]} + ${#NSC[*]}))
- fi
- progress=0
- fi
- #
- # let bootsplash know if we are shutting down or starting up
- #
- if [ "$runlevel" = "0" -o "$runlevel" = "6" ]
- then
- kscripts=$(($kscripts+$sscripts))
- rc_splash "splash start"
- rc_splash "shutdown"
- else
- rc_splash "splash start"
- fi
- export sscripts progress kscripts
- # Is there an rc directory for this new runlevel?
- if [ -d /etc/rc$runlevel.d ]
- then
- # First, run the KILL scripts.
- if [ "$previous" != N ]
- then
- # Run all scripts with the same level in parallel
- CURLEVEL=""
- for s in /etc/rc$runlevel.d/K*
- do
- level=$(echo $s | sed 's/.*\/K\([0-9][0-9]\).*/\1/')
- if [ "$level" = "$CURLEVEL" ]
- then
- continue
- fi
- CURLEVEL=$level
- SCRIPTS=""
- for i in /etc/rc$runlevel.d/K$level*
- do
- # Check if the script is there.
- [ ! -f $i ] && continue
- #
- # Find stop script in previous runlevel but
- # no start script there.
- #
- suffix=${i#/etc/rc$runlevel.d/K[0-9][0-9]}
- previous_stop=/etc/rc$previous.d/K[0-9][0-9]$suffix
- previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
- #
- # If there is a stop script in the previous level
- # and _no_ start script there, we don't
- # have to re-stop the service.
- #
- [ -f $previous_stop ] && [ ! -f $previous_start ] && $progress$(($progress+2)) &&
- continue
- # Stop the service.
- SCRIPTS="$SCRIPTS $i"
- done
- startup stop $SCRIPTS
- done
- fi
- case "$runlevel" in
- 0|6)
- ACTION=stop
- first_step=100
- progress_size=100
- step_change=-1
- ;;
- S)
- ACTION=start
- first_step=0
- progress_size=100
- step_change=1
- ;;
- *)
- ACTION=start
- first_step=0
- progress_size=100
- step_change=1
- ;;
- esac
- # Count the number of scripts we need to run (for usplash progress bar)
- num_steps=0
- for s in /etc/rc$runlevel.d/S*; do
- num_steps=$(($num_steps + 1))
- case "${s##/etc/rc$runlevel.d/S??}" in
- gdm|xdm|kdm)
- break
- ;;
- esac
- done
- # Now run the START scripts for this runlevel.
- # Run all scripts with the same level in parallel
- CURLEVEL=""
- step=0
- for s in /etc/rc$runlevel.d/S*
- do
- level=$(echo $s | sed 's/.*\/S\([0-9][0-9]\).*/\1/')
- if [ "$level" = "$CURLEVEL" ]
- then
- continue
- fi
- CURLEVEL=$level
- SCRIPTS=""
- for i in /etc/rc$runlevel.d/S$level*
- do
- [ ! -f $i ] && continue
- if [ "$previous" != N ]
- then
- #
- # Find start script in previous runlevel and
- # stop script in this runlevel.
- #
- suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]}
- stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix
- previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
- #
- # If there is a start script in the previous level
- # and _no_ stop script in this level, we don't
- # have to re-start the service.
- #
- [ -f $previous_start ] && [ ! -f $stop ] && $progress = $(($progress+2)) && continue
- fi
- SCRIPTS="$SCRIPTS $i"
- done
- startup $ACTION $SCRIPTS
- # Use 50% of the progress bar for rcS and the rest for the
- # runlevel we want to end up in
- step=$(($step + $step_change))
- #progress=$(($step * $progress_size / $num_steps + $first_step))
- if type usplash_write >/dev/null 2>&1; then
- usplash_write "PROGRESS $progress" || true
- fi
- done
- fi
- [ $runlevel != "S" ] && rc_splash "master" # finish up bootsplash
- if [ S = "$runlevel" ]
- then
- #
- # For compatibility, run the files in /etc/rc.boot too.
- #
- [ -d /etc/rc.boot ] && run-parts /etc/rc.boot
- #
- # Finish setup if needed. The comment above about
- # /sbin/unconfigured.sh applies here as well!
- #
- if [ -x /sbin/setup.sh ]
- then
- /sbin/setup.sh
- fi
- fi
- trap - EXIT # Disable emergency handler
- exit 0
复制代码 |
|