[CRIU] [PATCH] tests: be extra defensive about /dev and /dev/pts

Tycho Andersen tycho.andersen at canonical.com
Thu Feb 11 15:37:47 PST 2016


This avoids failures like:

$ sudo ./zdtm.py run -t zdtm/live/static/cgroupns
Checking feature cgroupns
=== Run 1/1 ================

====================== Run zdtm/live/static/cgroupns in h ======================
cc -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0  -iquote ./arch/x86/include  -c -MM -MP -o ns.d ns.c
cc -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0  -iquote ./arch/x86/include  -c -o ns.o ns.c
r - datagen.o
r - msg.o
r - parseargs.o
r - test.o
r - streamutil.o
r - lock.o
r - ns.o
r - tcp.o
r - fs.o
cc -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0  -iquote ../../lib/arch/x86/include -I../../lib   cgroupns.c ../../lib/libzdtmtst.a   -o cgroupns
Start test
Test is SUID
./cgroupns --pidfile=cgroupns.pid --outfile=cgroupns.out --dirname=cgroupns.test
Run criu dump
Run criu restore
Wait for zdtm/live/static/cgroupns to die for 0.100000
Removing dump/zdtm/live/static/cgroupns/85
===================== Test zdtm/live/static/cgroupns PASS ======================

===================== Run zdtm/live/static/cgroupns in ns ======================
Start test
Test is SUID
./cgroupns --pidfile=cgroupns.pid --outfile=cgroupns.out --dirname=cgroupns.test
mount(/dev/pts) failed: No such file or directory
The test failed (0, 1)
Makefile:277: recipe for target 'cgroupns.pid' failed
make: *** [cgroupns.pid] Error 1

and

$ sudo ./zdtm.py run -t zdtm/live/static/cgroupns
Checking feature cgroupns
=== Run 1/1 ================

====================== Run zdtm/live/static/cgroupns in h ======================
cc -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0  -iquote ./arch/x86/include  -c -MM -MP -o ns.d ns.c
cc -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0  -iquote ./arch/x86/include  -c -o ns.o ns.c
r - datagen.o
r - msg.o
r - parseargs.o
r - test.o
r - streamutil.o
r - lock.o
r - ns.o
r - tcp.o
r - fs.o
cc -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0  -iquote ../../lib/arch/x86/include -I../../lib   cgroupns.c ../../lib/libzdtmtst.a   -o cgroupns
Start test
Test is SUID
./cgroupns --pidfile=cgroupns.pid --outfile=cgroupns.out --dirname=cgroupns.test
Run criu dump
Run criu restore
Wait for zdtm/live/static/cgroupns to die for 0.100000
Removing dump/zdtm/live/static/cgroupns/85
===================== Test zdtm/live/static/cgroupns PASS ======================

===================== Run zdtm/live/static/cgroupns in ns ======================
Start test
Test is SUID
./cgroupns --pidfile=cgroupns.pid --outfile=cgroupns.out --dirname=cgroupns.test
mount(/dev) failed: No such file or directory
The test failed (0, 1)
Makefile:277: recipe for target 'cgroupns.pid' failed
make: *** [cgroupns.pid] Error 1

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 test/zdtm/lib/ns.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index bc5c395..812872a 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -93,6 +93,21 @@ static int prepare_mntns(void)
 		return -1;
 	}
 
+	if (mkdir("/dev", 0777) && errno != EEXIST) {
+		fprintf(stderr, "mkdir(/dev) failed: %m\n");
+		return -1;
+	}
+
+	if (mount("devtmpfs", "/dev", "devtmpfs", 0, NULL)) {
+		fprintf(stderr, "mount(/dev) failed: %m\n");
+		return -1;
+	}
+
+	if (mkdir("/dev/pts", 0777) && errno != EEXIST) {
+		fprintf(stderr, "mkdir(/dev) failed: %m\n");
+		return -1;
+	}
+
 	if (mount("pts", "/dev/pts", "devpts", MS_MGC_VAL, "mode=666,ptmxmode=666,newinstance")) {
 		fprintf(stderr, "mount(/dev/pts) failed: %m\n");
 		return -1;
-- 
2.6.4



More information about the CRIU mailing list