Skip to content

Commit

Permalink
libct: criuSwrk: only iterate over CriuOpts if debug is set
Browse files Browse the repository at this point in the history
In case log level is less than debug, this code does nothing,
so let's add a condition and skip it entirely.

Add a test case to make sure this code path is hit.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Feb 13, 2021
1 parent a186be1 commit ccd1524
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,8 +1523,9 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *
// should be empty. For older CRIU versions it still will be
// available but empty. criurpc.CriuReqType_VERSION actually
// has no req.GetOpts().
if !(req.GetType() == criurpc.CriuReqType_FEATURE_CHECK ||
req.GetType() == criurpc.CriuReqType_VERSION) {
if logrus.GetLevel() >= logrus.DebugLevel &&
!(req.GetType() == criurpc.CriuReqType_FEATURE_CHECK ||
req.GetType() == criurpc.CriuReqType_VERSION) {

val := reflect.ValueOf(req.GetOpts())
v := reflect.Indirect(val)
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ function simple_cr() {

for _ in $(seq 2); do
# checkpoint the running container
runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox
runc --criu "$CRIU" "$@" checkpoint --work-path ./work-dir test_busybox
grep -B 5 Error ./work-dir/dump.log || true
[ "$status" -eq 0 ]

# after checkpoint busybox is no longer running
testcontainer test_busybox checkpointed

# restore from checkpoint
runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
runc --criu "$CRIU" "$@" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
grep -B 5 Error ./work-dir/restore.log || true
[ "$status" -eq 0 ]

Expand All @@ -120,6 +120,10 @@ function simple_cr() {
simple_cr
}

@test "checkpoint and restore (with --debug)" {
simple_cr --debug
}

@test "checkpoint and restore (cgroupns)" {
# cgroupv2 already enables cgroupns so this case was tested above already
requires cgroups_v1 cgroupns
Expand Down
5 changes: 3 additions & 2 deletions vendor/github.com/checkpoint-restore/go-criu/v4/rpc/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ccd1524

Please sign in to comment.