state: fix reboot causing shutdown inside LXC container
authorPetr Štetiar <ynezz@true.cz>
Wed, 15 Jan 2020 19:28:38 +0000 (20:28 +0100)
committerPetr Štetiar <ynezz@true.cz>
Tue, 21 Jan 2020 14:42:23 +0000 (15:42 +0100)
commit856b5f8be04620c785b1af35cc16bc3f6d625a61
tree9c072e54706b1649e0a6a4fd67b06ce7a3604bac
parentb44417c20c7fca5a7f7c581c04ac67bf5316e56e
state: fix reboot causing shutdown inside LXC container

Executing `reboot` command in OpenWrt system runing inside LXC container
results in a shutdown of the container instead of rebooting the
container.

This appears to have been caused by commit 832369078d81 ("state: fix
shutdown when running in a container (FS#2425)"), which exits the pid
einz instead of the reboot().

While at it, refactor the halting code into separate function to shorten
the switch/case block and make it clearer, decrease the indentation
level by reversing the container if condition, replace magic 0 with
EXIT_SUCCESS constant in exit() and make it wait 1s for reboot message
delivery in both container/host cases as well.

Ref: FS#2666
Cc: Paul Spooren <mail@aparcar.org>
Fixes: 832369078d81 ("state: fix shutdown when running in a container (FS#2425)")
Tested-by: Baptiste Jonglez <lede@bitsofnetworks.org>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
state.c