Re: [OpenWrt-Devel] [PATCH] procd: fix shutdown when running in a container

2019-08-07 Thread Hans Dedecker
On Mon, Aug 5, 2019 at 6:09 PM Paul Spooren  wrote:
>
> Applies patch from @mikma [0] to fix Docker shutdown. Added detection to
> state.c if running in a containre or not.
>
> Tested with a x86/64 Docker image.
>
> Fixes FS#2425
>
> CC: Mikael Magnusson 
> CC: Petr Štetiar 
>
> [0]: 
> https://github.com/mikma/lxd-openwrt/blob/master/patches/procd-master/0003-docker-fix-problem-stopping-container.patch
>
> Signed-off-by: Paul Spooren 
Patch applied with some style changes

Hans
> ---
>  state.c | 25 +++--
>  1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/state.c b/state.c
> index ccf4104..b7cba88 100644
> --- a/state.c
> +++ b/state.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>
> +#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);
> +   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);
> +   /* 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);
> }
> -   while (1)
> -   sleep(1);
>  #else
> exit(0);
>  #endif
> --
> 2.20.1
>
>
> ___
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] procd: fix shutdown when running in a container

2019-08-05 Thread Paul Spooren
Applies patch from @mikma [0] to fix Docker shutdown. Added detection to
state.c if running in a containre or not.

Tested with a x86/64 Docker image.

Fixes FS#2425

CC: Mikael Magnusson 
CC: Petr Štetiar 

[0]: 
https://github.com/mikma/lxd-openwrt/blob/master/patches/procd-master/0003-docker-fix-problem-stopping-container.patch

Signed-off-by: Paul Spooren 
---
 state.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/state.c b/state.c
index ccf4104..b7cba88 100644
--- a/state.c
+++ b/state.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 
+#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);
+   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);
+   /* 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);
}
-   while (1)
-   sleep(1);
 #else
exit(0);
 #endif
-- 
2.20.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel