From 84eda608c8ef98dc685289d2df595ea8866abf37 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 8 Jan 2011 14:25:32 -0600 Subject: 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. --- sh/runscript.sh.in | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'sh/runscript.sh.in') diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 3d7252a..4e8e215 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -4,12 +4,24 @@ # Copyright (c) 2007-2009 Roy Marples # 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 -- cgit v1.2.3