Skip to content

Commit 542cce0

Browse files
committed
libct: Signal: slight refactor
Let's use c.hasInit and c.isPaused where needed instead of c.curentStatus for simplicity. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent d9f2a24 commit 542cce0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

libcontainer/container_linux.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,8 @@ func (c *Container) start(process *Process) (retErr error) {
364364
func (c *Container) Signal(s os.Signal) error {
365365
c.m.Lock()
366366
defer c.m.Unlock()
367-
status, err := c.currentStatus()
368-
if err != nil {
369-
return err
370-
}
371367
// To avoid a PID reuse attack, don't kill non-running container.
372-
switch status {
373-
case Running, Created, Paused:
374-
default:
368+
if !c.hasInit() {
375369
return ErrNotRunning
376370
}
377371

@@ -382,6 +376,7 @@ func (c *Container) Signal(s os.Signal) error {
382376
//
383377
// OTOH, if PID namespace is shared, we should kill all pids to avoid
384378
// leftover processes.
379+
var err error
385380
if s == unix.SIGKILL && !c.config.Namespaces.IsPrivate(configs.NEWPID) {
386381
err = signalAllProcesses(c.cgroupManager, unix.SIGKILL)
387382
} else {
@@ -390,11 +385,13 @@ func (c *Container) Signal(s os.Signal) error {
390385
if err != nil {
391386
return fmt.Errorf("unable to signal init: %w", err)
392387
}
393-
if status == Paused && s == unix.SIGKILL {
388+
if s == unix.SIGKILL {
394389
// For cgroup v1, killing a process in a frozen cgroup
395390
// does nothing until it's thawed. Only thaw the cgroup
396391
// for SIGKILL.
397-
_ = c.cgroupManager.Freeze(configs.Thawed)
392+
if paused, _ := c.isPaused(); paused {
393+
_ = c.cgroupManager.Freeze(configs.Thawed)
394+
}
398395
}
399396
return nil
400397
}

0 commit comments

Comments
 (0)