Wanna see this logo while booting your 2.6 kernel? Click here!

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:

  $SCRIPT_OK /usr/bin/dialog --title "LXTC" --clear --msgbox "$*" 8 51

# Enable Error Reporting
set -e

trap 'errordlg Error while loading keyboard layout!' 0

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

That worked fine and should be self-explanatory.