Skip to content

Commit

Permalink
runc exec: fail if cgroup is frozen
Browse files Browse the repository at this point in the history
Currently, if a container is paused (or its cgroup is frozen), runc exec
just hangs, and it is not obvious why.

Refuse to exec in a frozen container. Add a test case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Aug 17, 2021
1 parent f4a42d5 commit d3169d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func execProcess(context *cli.Context) (int, error) {
if err != nil {
return -1, err
}
if status == libcontainer.Stopped {
return -1, errors.New("cannot exec a container that has stopped")
if status == libcontainer.Stopped || status == libcontainer.Paused {
return -1, fmt.Errorf("cannot exec in a %s container", status)
}
path := context.String("process")
if path == "" && len(context.Args()) == 1 {
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,22 @@ function setup() {
[ "$status" -eq 0 ]
[ "$(wc -l <<<"$output")" -eq 1 ]
}

@test "runc exec should refuse a frozen cgroup" {
if [[ "$ROOTLESS" -ne 0 ]]; then
requires rootless_cgroup
fi
requires cgroups_freezer

set_cgroups_path

runc run -d --console-socket "$CONSOLE_SOCKET" ct1
[ "$status" -eq 0 ]
runc pause ct1
[ "$status" -eq 0 ]

# Exec should not timeout or succeed.
runc exec ct1 echo ok
[ "$status" -eq 255 ]
[[ "$output" == *"container cgroup is frozen"* ]]
}

0 comments on commit d3169d8

Please sign in to comment.