@@ -12,6 +12,17 @@ function setup() {
1212
1313function teardown() {
1414 teardown_busybox
15+ local pid fd
16+
17+ for pid in " ${PIDS_TO_KILL[@]} " ; do
18+ kill -9 $pid || true
19+ done
20+ PIDS_TO_KILL=()
21+
22+ for fd in " ${FDS_TO_CLOSE[@]} " ; do
23+ exec {fd}>& -
24+ done
25+ FDS_TO_CLOSE=()
1526}
1627
1728function setup_pipes() {
@@ -21,22 +32,23 @@ function setup_pipes() {
2132
2233 # Create two sets of pipes
2334 # for stdout/stderr
24- exec 52 <> <( :)
25- exec 50 < /proc/self/fd/52
26- exec 51 > /proc/self/fd/52
27- exec 52 >& -
35+ exec {pipe} <> <( :)
36+ exec {out_r} < /proc/self/fd/$pipe
37+ exec {out_w} > /proc/self/fd/$pipe
38+ exec {pipe} >& -
2839 # ... and stdin
29- exec 62<> <( :)
30- exec 60< /proc/self/fd/62
31- exec 61> /proc/self/fd/62
32- exec 62>& -
40+ exec {pipe}<> <( :)
41+ exec {in_r}< /proc/self/fd/$pipe
42+ exec {in_w}> /proc/self/fd/$pipe
43+ exec {pipe}>& -
44+ FDS_TO_CLOSE=($in_r $in_w $out_r $out_w )
3345}
3446
3547function check_pipes() {
36- echo Ping >&61
37- exec 61 >& -
38- exec 51 >& -
39- run cat < & 50
48+ echo Ping >& ${in_w}
49+ exec {in_w} >& -
50+ exec {out_w} >& -
51+ run cat < & ${out_r}
4052 [ " $status " -eq 0 ]
4153 [[ " ${output} " == * " ponG Ping" * ]]
4254}
@@ -84,7 +96,7 @@ function simple_cr() {
8496 setup_pipes
8597
8698 # run busybox
87- __runc run -d test_busybox < & 60 >&51 2>&51
99+ __runc run -d test_busybox < & ${in_r} >& ${out_w} 2>& ${out_w}
88100 [ $? -eq 0 ]
89101
90102 testcontainer test_busybox running
@@ -108,7 +120,7 @@ function simple_cr() {
108120 testcontainer test_busybox checkpointed
109121
110122 # restore from checkpoint
111- __runc --criu " $CRIU " restore -d --work-path ./work-dir --image-path ./image-dir test_busybox < & 60 >&51 2>&51
123+ __runc --criu " $CRIU " restore -d --work-path ./work-dir --image-path ./image-dir test_busybox < & ${in_r} >& ${out_w} 2>& ${out_w}
112124 ret=$?
113125 cat ./work-dir/restore.log | grep -B 5 Error || true
114126 [ $ret -eq 0 ]
@@ -139,7 +151,7 @@ function simple_cr() {
139151 port=27277
140152
141153 # run busybox
142- __runc run -d test_busybox < & 60 >&51 2>&51
154+ __runc run -d test_busybox < & ${in_r} >& ${out_w} 2>& ${out_w}
143155 [ $? -eq 0 ]
144156
145157 testcontainer test_busybox running
@@ -150,16 +162,18 @@ function simple_cr() {
150162
151163 # For lazy migration we need to know when CRIU is ready to serve
152164 # the memory pages via TCP.
153- exec 72<> <( :)
154- exec 70< /proc/self/fd/72 71> /proc/self/fd/72
155- exec 72>& -
165+ exec {pipe}<> <( :)
166+ exec {lazy_r}< /proc/self/fd/$pipe {lazy_w}> /proc/self/fd/$pipe
167+ exec {pipe}>& -
168+ FDS_TO_CLOSE+=($lazy_r $lazy_w )
156169
157- __runc --criu " $CRIU " checkpoint --lazy-pages --page-server 0.0.0.0:${port} --status-fd 71 --work-path ./work-dir --image-path ./image-dir test_busybox &
170+ __runc --criu " $CRIU " checkpoint --lazy-pages --page-server 0.0.0.0:${port} --status-fd ${lazy_w} --work-path ./work-dir --image-path ./image-dir test_busybox &
158171 cpt_pid=$!
172+ PIDS_TO_KILL=($cpt_pid )
159173
160174 # wait for lazy page server to be ready
161- out=$( timeout 2 dd if=/proc/self/fd/70 bs=1 count=1 2> /dev/null | od)
162- exec 71 >& -
175+ out=$( timeout 2 dd if=/proc/self/fd/${lazy_r} bs=1 count=1 2> /dev/null | od)
176+ exec {lazy_w} >& -
163177 out=$( echo $out ) # rm newlines
164178 # show errors if there are any before we fail
165179 grep -B5 Error ./work-dir/dump.log || true
@@ -172,14 +186,15 @@ function simple_cr() {
172186 # Start CRIU in lazy-daemon mode
173187 ${CRIU} lazy-pages --page-server --address 127.0.0.1 --port ${port} -D image-dir &
174188 lp_pid=$!
189+ PIDS_TO_KILL+=($lp_pid )
175190
176191 # Restore lazily from checkpoint.
177192 # The restored container needs a different name as the checkpointed
178193 # container is not yet destroyed. It is only destroyed at that point
179194 # in time when the last page is lazily transferred to the destination.
180195 # Killing the CRIU on the checkpoint side will let the container
181196 # continue to run if the migration failed at some point.
182- __runc --criu " $CRIU " restore -d --work-path ./image-dir --image-path ./image-dir --lazy-pages test_busybox_restore < & 60 >&51 2>&51
197+ __runc --criu " $CRIU " restore -d --work-path ./image-dir --image-path ./image-dir --lazy-pages test_busybox_restore < & ${in_r} >& ${out_w} 2>& ${out_w}
183198 ret=$?
184199 cat ./work-dir/restore.log | grep -B 5 Error || true
185200 [ $ret -eq 0 ]
@@ -196,6 +211,7 @@ function simple_cr() {
196211
197212 wait $lp_pid
198213 [ $? -eq 0 ]
214+ PIDS_TO_KILL=()
199215
200216 check_pipes
201217}
0 commit comments