handling script/init errors

Sascha Hauer s.hauer at pengutronix.de
Tue Nov 12 03:28:58 EST 2013


Hi Marc,

On Tue, Nov 12, 2013 at 05:07:35PM +1100, Marc Reilly wrote:
> Hi,
> 
> Rarely, one of the commands (related to hardware access) in our startup 
> scripts fails, and the unit startup ends up bailing to a console prompt. 
> (Which is only on debug port, so no appropriate user feedback) 
> This would end up appearing to the user that nothing has happened, and will 
> either run until batteries are drained (or removed) or a special reset 
> sequence is done.
> 
> Is there a way to set up an error handler in the scripts? Ideally, a command 
> or script that could be called if /bin/sh encounters an error.

What would you consider an error? Is executing the 'false' command an
error?
Commands in scripts must be allowed to fail. You are supposed to catch
this via

if [ $? != 0 ]; then
	echo "something bad happened"
	exit 1
fi

Of course error handling in shell is very cumbersome, even more in a
restricted shell like hush. That's the reason I try to reduce the need
of shell scripts in barebox. Most things that "really need to work" are
better done in C.

Maybe you could implement a 'catch' command. It would execute a command
given as argument to the command. Something like:

CATCH_HANDLER=/env/bin/failure.sh
...
catch <command>

Then whenever <command> fails $CATCH_HANDLER would be executed.

Don't know if that makes sense, just an idea.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list