Login Main site Create account

13.05.2005 13:15

busybox and shell traps


Today I stumbled accross an issue with busybox and shell traps. I tried to add some kind of automatic error responses to my thinclient runlevel scripts using signal traps. I configured a trap to signal 0 to start a dialog interface containing the detaild error message, but because of the trap on signal 0, it's always executed - on success and on failure - when the scripts exits. So I had to define some a variable that contains one specified value on success and another value on failure. Due to the forementioned fact that busybox lets me just do a single command in the trap, I wasn't able to check for the value of this variable, e.g. the following code didn't work:
[ "$VARIABLE" = "0" ] && do_something
Busybox only evalutes $VARIABLE and then returns from my trap, do_something was never called.
Finally I came to this solution:
ignore()
{
}

errordlg()
{
  $SCRIPT_OK /usr/bin/dialog --title "LXTC" --clear --msgbox "$*" 8 51
}

# Enable Error Reporting
set -e
SCRIPT_OK=

trap 'errordlg Error while loading keyboard layout!' 0

echo -n "Loading keyboard layout $KEYLAYOUT..."
try /bin/loadkeys $KEYLAYOUT

SCRIPT_OK=ignore
That worked fine and should be self-explanatory.
Currently no comments to this entry (http://tuxx-home.at/archives/2005/05/13/T13_15_48/index.html)


Your comment (HTML tags will be stripped !!):

To verify You are not a bot, type down text from this image.

Your try: