Description: fix init program 
 docker-ce (5:20.10.3-19) buster; urgency=low
   * Version: 20.10.3-19
   * fix init program 
Author: wanghuaiqing <wanghuaiqing@loongson.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2022-07-11

--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/cli/cli/command/container/opts.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/cli/cli/command/container/opts.go
@@ -124,6 +124,7 @@ type containerOptions struct {
 	runtime            string
 	autoRemove         bool
 	init               bool
+	initDebug          bool
 
 	Image string
 	Args  []string
@@ -297,6 +298,7 @@ func addFlags(flags *pflag.FlagSet) *con
 	flags.StringVar(&copts.runtime, "runtime", "", "Runtime to use for this container")
 
 	flags.BoolVar(&copts.init, "init", false, "Run an init inside the container that forwards signals and reaps processes")
+	flags.BoolVar(&copts.initDebug, "initDebug", false, "enable init debug")
 	flags.SetAnnotation("init", "version", []string{"1.25"})
 	return copts
 }
@@ -660,6 +662,9 @@ func parse(flags *pflag.FlagSet, copts *
 	// only set this value if the user provided the flag, else it should default to nil
 	if flags.Changed("init") {
 		hostConfig.Init = &copts.init
+		if flags.Changed("initDebug") {
+			hostConfig.InitDebug = &copts.initDebug
+		}
 	}
 
 	// When allocating stdin in attached mode, close stdin at client disconnect
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/cli/vendor/github.com/docker/docker/api/types/container/host_config.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/cli/vendor/github.com/docker/docker/api/types/container/host_config.go
@@ -444,4 +444,7 @@ type HostConfig struct {
 
 	// Run a custom init inside the container, if null, use the daemon's configured settings
 	Init *bool `json:",omitempty"`
+
+	// enable init debug
+	InitDebug *bool `json:",omitempty"`
 }
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/api/types/container/host_config.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/api/types/container/host_config.go
@@ -444,4 +444,7 @@ type HostConfig struct {
 
 	// Run a custom init inside the container, if null, use the daemon's configured settings
 	Init *bool `json:",omitempty"`
+
+	// enable init debug
+	InitDebug *bool `json:",omitempty"`
 }
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/cmd/dockerd/config_unix.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/cmd/dockerd/config_unix.go
@@ -55,6 +55,7 @@ func installConfigFlags(conf *config.Con
 	flags.BoolVar(&conf.LiveRestoreEnabled, "live-restore", false, "Enable live restore of docker when containers are still running")
 	flags.IntVar(&conf.OOMScoreAdjust, "oom-score-adjust", 0, "Set the oom_score_adj for the daemon")
 	flags.BoolVar(&conf.Init, "init", false, "Run an init in the container to forward signals and reap processes")
+	flags.BoolVar(&conf.Init, "init-debug", false, "Enable init debug info")
 	flags.StringVar(&conf.InitPath, "init-path", "", "Path to the docker-init binary")
 	flags.Int64Var(&conf.CPURealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds for the parent cgroup for all containers")
 	flags.Int64Var(&conf.CPURealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds for the parent cgroup for all containers")
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/daemon/config/config_unix.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/daemon/config/config_unix.go
@@ -32,6 +32,7 @@ type Config struct {
 	CPURealtimeRuntime   int64                    `json:"cpu-rt-runtime,omitempty"`
 	OOMScoreAdjust       int                      `json:"oom-score-adjust,omitempty"`
 	Init                 bool                     `json:"init,omitempty"`
+	InitDebug            bool                     `json:"init-debug,omitempty"`
 	InitPath             string                   `json:"init-path,omitempty"`
 	SeccompProfile       string                   `json:"seccomp-profile,omitempty"`
 	ShmSize              opts.MemBytes            `json:"default-shm-size,omitempty"`
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/daemon/oci_linux.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/daemon/oci_linux.go
@@ -734,10 +734,15 @@ func WithCommonOptions(daemon *Daemon, c
 		// only add the custom init if it is specified and the container is running in its
 		// own private pid namespace.  It does not make sense to add if it is running in the
 		// host namespace or another container's pid namespace where we already have an init
-		if c.HostConfig.PidMode.IsPrivate() {
+		//if c.HostConfig.PidMode.IsPrivate() {
 			if (c.HostConfig.Init != nil && *c.HostConfig.Init) ||
 				(c.HostConfig.Init == nil && daemon.configStore.Init) {
-				s.Process.Args = append([]string{inContainerInitPath, "--", c.Path}, c.Args...)
+				if (c.HostConfig.InitDebug != nil && *c.HostConfig.InitDebug) ||
+					(c.HostConfig.InitDebug == nil && daemon.configStore.InitDebug) {
+					s.Process.Args = append([]string{inContainerInitPath, "-s", "-vvv", "--", c.Path}, c.Args...)
+				} else {
+					s.Process.Args = append([]string{inContainerInitPath, "-s", "--", c.Path}, c.Args...)
+				}
 				path := daemon.configStore.InitPath
 				if path == "" {
 					path, err = exec.LookPath(daemonconfig.DefaultInitBinary)
@@ -752,7 +757,7 @@ func WithCommonOptions(daemon *Daemon, c
 					Options:     []string{"bind", "ro"},
 				})
 			}
-		}
+		//}
 		s.Process.Cwd = cwd
 		s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv)
 		s.Process.Terminal = c.Config.Tty
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/tini/src/tini.c
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/tini/src/tini.c
@@ -550,7 +550,7 @@ int reap_zombies(const pid_t child_pid,
 			case -1:
 				if (errno == ECHILD) {
 					PRINT_TRACE("No child to wait");
-					break;
+					return 1;
 				}
 				PRINT_FATAL("Error while waiting for pids: '%s'", strerror(errno));
 				return 1;
@@ -674,8 +674,8 @@ int main(int argc, char *argv[]) {
 		}
 
 		if (child_exitcode != -1) {
-			PRINT_TRACE("Exiting: child has exited");
-			return child_exitcode;
+			PRINT_TRACE("Exiting: main child has exited");
+			//return child_exitcode;
 		}
 	}
 }
