summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Spooren2019-08-05 16:07:45 +0000
committerHans Dedecker2019-08-05 19:44:23 +0000
commit832369078d818d19ab64051fdc8da9e06c90ad88 (patch)
treefab9840ba19e20701cae4ece1904920ce27ff88a
parent31f0765afd61f55b1dd2cdb62ec1968efca19690 (diff)
downloadprocd-832369078d818d19ab64051fdc8da9e06c90ad88.tar.gz
state: fix shutdown when running in a container (FS#2425)
Applies patch from @mikma [0] to fix Docker shutdown. Added detection to state.c if running in a container or not. Tested with a x86/64 Docker image. Fixes FS#2425 CC: Mikael Magnusson <mikma@users.sourceforge.net> CC: Petr Štetiar <ynezz@true.cz> [0]: https://github.com/mikma/lxd-openwrt/blob/master/patches/procd-master/0003-docker-fix-problem-stopping-container.patch Signed-off-by: Paul Spooren <mail@aparcar.org> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> [coding style aligment]
-rw-r--r--state.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/state.c b/state.c
index ccf4104..4737d01 100644
--- a/state.c
+++ b/state.c
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <signal.h>
+#include "container.h"
#include "procd.h"
#include "syslog.h"
#include "plug/hotplug.h"
@@ -157,18 +158,22 @@ static void state_enter(void)
else
LOG("- reboot -\n");
- /* Allow time for last message to reach serial console, etc */
- sleep(1);
-
- /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
- * in linux/kernel/sys.c, which can cause the machine to panic when
- * the init process exits... */
- if (!vfork( )) { /* child */
- reboot(reboot_event);
- _exit(EXIT_SUCCESS);
- }
- while (1)
+ if (!is_container()) {
+ /* Allow time for last message to reach serial console, etc */
sleep(1);
+
+ /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
+ * in linux/kernel/sys.c, which can cause the machine to panic when
+ * the init process exits... */
+ if (!vfork( )) { /* child */
+ reboot(reboot_event);
+ _exit(EXIT_SUCCESS);
+ }
+
+ while (1)
+ sleep(1);
+ } else
+ exit(0);
#else
exit(0);
#endif