@@ -303,3 +303,109 @@ function setup() {
303303 # check that the cgroups v2 path is the same for both processes
304304 [[ " $run_cgroup " == " $exec_cgroup " ]]
305305}
306+
307+ @test " runc exec should refuse a paused container" {
308+ if [[ " $ROOTLESS " -ne 0 ]]; then
309+ requires rootless_cgroup
310+ fi
311+ requires cgroups_freezer
312+
313+ set_cgroups_path
314+
315+ runc run -d --console-socket " $CONSOLE_SOCKET " ct1
316+ [ " $status " -eq 0 ]
317+ runc pause ct1
318+ [ " $status " -eq 0 ]
319+
320+ # Exec should not timeout or succeed.
321+ runc exec ct1 echo ok
322+ [ " $status " -eq 255 ]
323+ [[ " $output " == * " cannot exec in a paused container" * ]]
324+ }
325+
326+ @test " runc exec --ignore-paused" {
327+ if [[ " $ROOTLESS " -ne 0 ]]; then
328+ requires rootless_cgroup
329+ fi
330+ requires cgroups_freezer
331+
332+ set_cgroups_path
333+
334+ runc run -d --console-socket " $CONSOLE_SOCKET " ct1
335+ [ " $status " -eq 0 ]
336+ runc pause ct1
337+ [ " $status " -eq 0 ]
338+
339+ # Resume the container a bit later.
340+ (
341+ sleep 2
342+ runc resume ct1
343+ ) &
344+
345+ # Exec should not timeout or succeed.
346+ runc exec --ignore-paused ct1 echo ok
347+ [ " $status " -eq 0 ]
348+ [ " $output " = " ok" ]
349+ }
350+
351+ @test " runc run/create should warn about a non-empty cgroup" {
352+ if [[ " $ROOTLESS " -ne 0 ]]; then
353+ requires rootless_cgroup
354+ fi
355+
356+ set_cgroups_path
357+
358+ runc run -d --console-socket " $CONSOLE_SOCKET " ct1
359+ [ " $status " -eq 0 ]
360+
361+ # Run a second container sharing the cgroup with the first one.
362+ runc --debug run -d --console-socket " $CONSOLE_SOCKET " ct2
363+ [ " $status " -eq 0 ]
364+ [[ " $output " == * " container's cgroup is not empty" * ]]
365+
366+ # Same but using runc create.
367+ runc create --console-socket " $CONSOLE_SOCKET " ct3
368+ [ " $status " -eq 0 ]
369+ [[ " $output " == * " container's cgroup is not empty" * ]]
370+ }
371+
372+ @test " runc run/create should refuse pre-existing frozen cgroup" {
373+ requires cgroups_freezer
374+ if [[ " $ROOTLESS " -ne 0 ]]; then
375+ requires rootless_cgroup
376+ fi
377+
378+ set_cgroups_path
379+
380+ case $CGROUP_UNIFIED in
381+ no)
382+ FREEZER_DIR=" ${CGROUP_FREEZER_BASE_PATH} /${REL_CGROUPS_PATH} "
383+ FREEZER=" ${FREEZER_DIR} /freezer.state"
384+ STATE=" FROZEN"
385+ ;;
386+ yes)
387+ FREEZER_DIR=" ${CGROUP_PATH} "
388+ FREEZER=" ${FREEZER_DIR} /cgroup.freeze"
389+ STATE=" 1"
390+ ;;
391+ esac
392+
393+ # Create and freeze the cgroup.
394+ mkdir -p " $FREEZER_DIR "
395+ echo " $STATE " > " $FREEZER "
396+
397+ # Start a container.
398+ runc run -d --console-socket " $CONSOLE_SOCKET " ct1
399+ [ " $status " -eq 1 ]
400+ # A warning should be printed.
401+ [[ " $output " == * " container's cgroup unexpectedly frozen" * ]]
402+
403+ # Same check for runc create.
404+ runc create --console-socket " $CONSOLE_SOCKET " ct2
405+ [ " $status " -eq 1 ]
406+ # A warning should be printed.
407+ [[ " $output " == * " container's cgroup unexpectedly frozen" * ]]
408+
409+ # Cleanup.
410+ rmdir " $FREEZER_DIR "
411+ }
0 commit comments