@@ -18,6 +18,7 @@ import (
18
18
"github.com/opencontainers/runc/libcontainer"
19
19
"github.com/opencontainers/runc/libcontainer/configs"
20
20
"github.com/opencontainers/runc/libcontainer/specconv"
21
+ "github.com/opencontainers/runc/libcontainer/system"
21
22
"github.com/opencontainers/runc/libcontainer/system/kernelversion"
22
23
"github.com/opencontainers/runc/libcontainer/utils"
23
24
)
@@ -217,7 +218,10 @@ type runner struct {
217
218
}
218
219
219
220
func (r * runner ) run (config * specs.Process ) (int , error ) {
220
- var err error
221
+ var (
222
+ err error
223
+ handlerCh chan * signalHandler
224
+ )
221
225
defer func () {
222
226
if err != nil {
223
227
r .destroy ()
@@ -252,7 +256,15 @@ func (r *runner) run(config *specs.Process) (int, error) {
252
256
// Setting up IO is a two stage process. We need to modify process to deal
253
257
// with detaching containers, and then we get a tty after the container has
254
258
// started.
255
- handlerCh := newSignalHandler (r .enableSubreaper )
259
+ if r .enableSubreaper {
260
+ // set us as the subreaper before registering the signal handler for the container
261
+ if err := system .SetSubreaper (1 ); err != nil {
262
+ logrus .Warn (err )
263
+ }
264
+ }
265
+ if ! detach {
266
+ handlerCh = newSignalHandler ()
267
+ }
256
268
tty , err := setupIO (process , r .container , config .Terminal , detach , r .consoleSocket )
257
269
if err != nil {
258
270
return - 1 , err
@@ -297,14 +309,14 @@ func (r *runner) run(config *specs.Process) (int, error) {
297
309
return - 1 , err
298
310
}
299
311
}
312
+ if detach {
313
+ return 0 , nil
314
+ }
300
315
handler := <- handlerCh
301
- status , err := handler .forward (process , tty , detach )
316
+ status , err := handler .forward (process , tty )
302
317
if err != nil {
303
318
r .terminate (process )
304
319
}
305
- if detach {
306
- return 0 , nil
307
- }
308
320
if err == nil {
309
321
r .destroy ()
310
322
}
0 commit comments