summaryrefslogtreecommitdiffstats
path: root/etc/rc.subr
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2007-06-04 11:39:35 +0000
committeryar <yar@FreeBSD.org>2007-06-04 11:39:35 +0000
commit68cc2f890e531f8fbab96af900fa7fde9cd5ca07 (patch)
treebed5d6f6080c4b2a766830fe1db51a5ced14d21e /etc/rc.subr
parentf28297d01f737f3ca830b4161abd767edf0db5a3 (diff)
downloadFreeBSD-src-68cc2f890e531f8fbab96af900fa7fde9cd5ca07.zip
FreeBSD-src-68cc2f890e531f8fbab96af900fa7fde9cd5ca07.tar.gz
Be robust to a bogus script specification or contents
when figuring out what the real interpreter is for an interpreted command. That is, check whether we can read the script file in the first place and, if so, make sure we got a valid shebang line from it.
Diffstat (limited to 'etc/rc.subr')
-rw-r--r--etc/rc.subr35
1 files changed, 24 insertions, 11 deletions
diff --git a/etc/rc.subr b/etc/rc.subr
index 061f0b9..f0a2c9d 100644
--- a/etc/rc.subr
+++ b/etc/rc.subr
@@ -283,17 +283,30 @@ _find_processes()
_pref=
if [ $_interpreter != "." ]; then # an interpreted script
- # read interpreter name
- read _interp < ${_chroot}${_chroot:+"/"}$_procname
- _interp=${_interp#\#!} # strip #!
- set -- $_interp
- case $1 in
- */bin/env)
- shift # drop env to get real name
- ;;
- esac
- if [ $_interpreter != $1 ]; then
- warn "\$command_interpreter $_interpreter != $1"
+ _script=${_chroot}${_chroot:+"/"}$_procname
+ if [ -r $_script ]; then
+ read _interp < $_script # read interpreter name
+ case "$_interp" in
+ \#!*)
+ _interp=${_interp#\#!} # strip #!
+ set -- $_interp
+ case $1 in
+ */bin/env)
+ shift # drop env to get real name
+ ;;
+ esac
+ if [ $_interpreter != $1 ]; then
+ warn "\$command_interpreter $_interpreter != $1"
+ fi
+ ;;
+ *)
+ warn "no shebang line in $_script"
+ set -- $_interpreter
+ ;;
+ esac
+ else
+ warn "cannot read shebang line from $_script"
+ set -- $_interpreter
fi
_interp="$* $_procname" # cleanup spaces, add _procname
_interpbn=${1##*/}
OpenPOWER on IntegriCloud