# sh trap handling upon reboot



## Seeker (Jun 13, 2012)

This is my trap:

```
trap -- 'echo
echo Going down!
exit "$_CODE"' EXIT
trap -- 'echo
echo Going down!
exit "$_CODE"' HUP
trap -- 'echo
echo Going down!
exit "$_CODE"' INT
trap -- 'echo
echo Going down!
exit "$_CODE"' QUIT
trap -- 'echo
echo Going down!
exit "$_CODE"' TERM
```
It has been set up at script's start.
Now sh code:

```
echo Regular code ...
reboot
```

Once it hits a reboot, the trap never gets executed! 
Advice? :stud


----------



## Seeker (Jun 13, 2012)

Additionally, which var holds, received signal code?


----------



## jilles@ (Jun 17, 2012)

Traps are not executed while the shell is waiting for a foreground process to terminate, and a successful reboot(8)() never terminates (it eventually calls reboot(2)() which does not return control).

There is no way to access si_code or any other siginfo_t member in a shell script.


----------



## Seeker (Jun 17, 2012)

Yes, that is why I've replaced it with:
[CMD="shutdown"]... +1[/CMD]


----------

