summaryrefslogtreecommitdiffstats
path: root/recipes-containers/runc/runc-docker/0001-runc-docker-SIGUSR1-daemonize.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-containers/runc/runc-docker/0001-runc-docker-SIGUSR1-daemonize.patch')
-rw-r--r--recipes-containers/runc/runc-docker/0001-runc-docker-SIGUSR1-daemonize.patch133
1 files changed, 0 insertions, 133 deletions
diff --git a/recipes-containers/runc/runc-docker/0001-runc-docker-SIGUSR1-daemonize.patch b/recipes-containers/runc/runc-docker/0001-runc-docker-SIGUSR1-daemonize.patch
deleted file mode 100644
index d3d1134b..00000000
--- a/recipes-containers/runc/runc-docker/0001-runc-docker-SIGUSR1-daemonize.patch
+++ /dev/null
@@ -1,133 +0,0 @@
1From cd7d76a6d1ecb1856f6ed666fb5c30dc105aa94e Mon Sep 17 00:00:00 2001
2From: Jason Wessel <jason.wessel@windriver.com>
3Date: Tue, 5 Dec 2017 18:28:28 -0800
4Subject: [PATCH] runc-docker: Allow "run start ..." to daemonize with $SIGUSR1_PARENT_PID
5
6The runc-docker has all the code in it to properly run a stop hook if
7you use it in the foreground. It doesn't work in the back ground
8because there is no way for a golang application to fork a child exit
9out of the parent process because all the golang threads stay with the
10parent.
11
12This patch has three parts that happen ONLY when $SIGUSR1_PARENT_PID
13is set.
14
151) The code was copied which performs the normal the signal handling
16 block which is used for the foreground operation of runc.
17
182) At the point where runc start would normally exit, it closes
19 stdin/stdout/stderr so it would be possible to daemonize "runc start ...".
20
213) The code to send a SIGUSR1 to the parent process was added. The
22 idea being that a parent process would simply exit at that point
23 because it was blocking until runc performed everything it was
24 required to perform.
25
26Upstream-Status: Inappropriate [embedded specific]
27
28Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
29---
30 signals.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
31 utils_linux.go | 2 +-
32 2 files changed, 51 insertions(+), 5 deletions(-)
33
34Index: git/src/import/signals.go
35===================================================================
36--- git.orig/src/import/signals.go
37+++ git/src/import/signals.go
38@@ -5,7 +5,9 @@
39 import (
40 "os"
41 "os/signal"
42+ "syscall" // only for Signal
43
44+ "strconv"
45 "github.com/opencontainers/runc/libcontainer"
46 "github.com/opencontainers/runc/libcontainer/system"
47 "github.com/opencontainers/runc/libcontainer/utils"
48@@ -55,9 +57,6 @@
49 func (h *signalHandler) forward(process *libcontainer.Process, tty *tty, detach bool) (int, error) {
50 // make sure we know the pid of our main process so that we can return
51 // after it dies.
52- if detach && h.notifySocket == nil {
53- return 0, nil
54- }
55
56 pid1, err := process.Pid()
57 if err != nil {
58@@ -67,12 +66,61 @@
59 if h.notifySocket != nil {
60 if detach {
61 _ = h.notifySocket.run(pid1)
62- return 0, nil
63 }
64 _ = h.notifySocket.run(os.Getpid())
65 go func() { _ = h.notifySocket.run(0) }()
66 }
67
68+ if (detach) {
69+ // This allows the parent process to daemonize this process
70+ // so long as stdin/stderr/stdout are closed
71+ if envVal := os.Getenv("SIGUSR1_PARENT_PID"); envVal != "" {
72+ // Close stdin/stdout/stderr
73+ os.Stdin.Close()
74+ os.Stdout.Close()
75+ os.Stderr.Close()
76+ // Notify parent to detach
77+ i, err := strconv.Atoi(envVal)
78+ if (err != nil) {
79+ return 0, nil
80+ }
81+ unix.Kill(i, unix.SIGUSR1)
82+ // Loop waiting on the child to signal or exit,
83+ // after which all stop hooks will be run
84+ for s := range h.signals {
85+ switch s {
86+ case unix.SIGCHLD:
87+ exits, err := h.reap()
88+ if err != nil {
89+ logrus.Error(err)
90+ }
91+ for _, e := range exits {
92+ logrus.WithFields(logrus.Fields{
93+ "pid": e.pid,
94+ "status": e.status,
95+ }).Debug("process exited")
96+ if e.pid == pid1 {
97+ // call Wait() on the process even though we already have the exit
98+ // status because we must ensure that any of the go specific process
99+ // fun such as flushing pipes are complete before we return.
100+ process.Wait()
101+ if h.notifySocket != nil {
102+ h.notifySocket.Close()
103+ }
104+ return e.status, nil
105+ }
106+ }
107+ default:
108+ logrus.Debugf("sending signal to process %s", s)
109+ if err := unix.Kill(pid1, s.(syscall.Signal)); err != nil {
110+ logrus.Error(err)
111+ }
112+ }
113+ }
114+ }
115+ return 0, nil
116+ }
117+
118 // Perform the initial tty resize. Always ignore errors resizing because
119 // stdout might have disappeared (due to races with when SIGHUP is sent).
120 _ = tty.resize()
121Index: git/src/import/utils_linux.go
122===================================================================
123--- git.orig/src/import/utils_linux.go
124+++ git/src/import/utils_linux.go
125@@ -345,7 +345,7 @@
126 if err != nil {
127 r.terminate(process)
128 }
129- if detach {
130+ if (detach && os.Getenv("SIGUSR1_PARENT_PID") == "") {
131 return 0, nil
132 }
133 if err == nil {