aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorWilliam Hubbs <williamh@gentoo.org>2011-01-08 14:25:32 -0600
committerWilliam Hubbs <williamh@gentoo.org>2011-01-12 19:21:48 -0600
commit84eda608c8ef98dc685289d2df595ea8866abf37 (patch)
treea8153a877d44ab0a36dac407c7fbdb714d8fad89 /sh
parente3905ed7bbc2ddcbf1084aed9d3937a04eda2038 (diff)
bug 328675: add error checking to runscript.sh
runscript.sh needs to abort if the . command used to load conf.d files and the service script does not execute successfully. I would like to thank Mike Frysinger for his input wrt style on this patch.
Diffstat (limited to 'sh')
-rw-r--r--sh/runscript.sh.in34
1 files changed, 21 insertions, 13 deletions
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 3d7252a6..4e8e2158 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -4,12 +4,24 @@
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
-. @SYSCONFDIR@/init.d/functions.sh
-. @LIBEXECDIR@/sh/rc-functions.sh
+sourcex()
+{
+ if [ "$1" = "-e" ]; then
+ shift
+ [ -e "$1" ] || return 1
+ fi
+ if ! . "$1"; then
+ eerror "$RC_SVCNAME: error loading $1"
+ exit 1
+ fi
+}
+
+sourcex "@SYSCONFDIR@/init.d/functions.sh"
+sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
# Support LiveCD foo
if [ -r /sbin/livecd-functions.sh ]; then
- . /sbin/livecd-functions.sh
+ sourcex "/sbin/livecd-functions.sh"
livecd_read_commandline
fi
@@ -145,30 +157,26 @@ _conf_d=${RC_SERVICE%/*}/../conf.d
# If we're net.eth0 or openvpn.work then load net or openvpn config
_c=${RC_SVCNAME%%.*}
if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
- if [ -e "$_conf_d/$_c.$RC_RUNLEVEL" ]; then
- . "$_conf_d/$_c.$RC_RUNLEVEL"
- elif [ -e "$_conf_d/$_c" ]; then
- . "$_conf_d/$_c"
+ if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then
+ sourcex -e "$_conf_d/$_c"
fi
fi
unset _c
# Overlay with our specific config
-if [ -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL" ]; then
- . "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"
-elif [ -e "$_conf_d/$RC_SVCNAME" ]; then
- . "$_conf_d/$RC_SVCNAME"
+if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
+ sourcex -e "$_conf_d/$RC_SVCNAME"
fi
unset _conf_d
# Load any system overrides
-[ -e @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
+sourcex -e "@SYSCONFDIR@/rc.conf"
# Apply any ulimit defined
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
# Load our script
-. "$RC_SERVICE"
+sourcex "$RC_SERVICE"
for _d in $required_dirs; do
if [ ! -d $_d ]; then