@@ -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,11 @@ 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
+ status int
225
+ )
221
226
defer func () {
222
227
if err != nil {
223
228
r .destroy ()
@@ -252,7 +257,15 @@ func (r *runner) run(config *specs.Process) (int, error) {
252
257
// Setting up IO is a two stage process. We need to modify process to deal
253
258
// with detaching containers, and then we get a tty after the container has
254
259
// started.
255
- handlerCh := newSignalHandler (r .enableSubreaper )
260
+ if r .enableSubreaper {
261
+ // set us as the subreaper before registering the signal handler for the container
262
+ if err := system .SetSubreaper (1 ); err != nil {
263
+ logrus .Warn (err )
264
+ }
265
+ }
266
+ if ! detach {
267
+ handlerCh = newSignalHandler ()
268
+ }
256
269
tty , err := setupIO (process , r .container , config .Terminal , detach , r .consoleSocket )
257
270
if err != nil {
258
271
return - 1 , err
@@ -297,15 +310,14 @@ func (r *runner) run(config *specs.Process) (int, error) {
297
310
return - 1 , err
298
311
}
299
312
}
300
- handler := <- handlerCh
301
- status , err := handler .forward (process , tty , detach )
302
- if err != nil {
303
- r .terminate (process )
304
- }
305
313
if detach {
306
314
return 0 , nil
307
315
}
308
- if err == nil {
316
+ // For non-detached container, we should forward signals to the container.
317
+ handler := <- handlerCh
318
+ if status , err = handler .forward (process , tty ); err != nil {
319
+ r .terminate (process )
320
+ } else {
309
321
r .destroy ()
310
322
}
311
323
return status , err
0 commit comments