[CRIU] [PATCH v2 1/2] test: replace cat in Makefiles with awk

Vitaly Ostrosablin vostrosablin at virtuozzo.com
Thu Jan 12 01:02:26 PST 2017


cat *.pid works when we have only one running process at any moment.
That's because pidfiles contain no newlines and cat will just
concatenate content of all files present in directory. So, e.g., if we
have pidfiles:

31338
31359
31880
31884
31889

cat will build following string from those pidfiles:

3133831359318803188431889

Obviously, kill would fail to send signals to processes, because it's
now a single big number, which cannot be unambigously split back in
general case.

That's where awk comes in. We don't need to modify C part of tests to
print newlines at end of file. We just order awk to print content of
each file, which adds a newline at end - problem solved, kill can once
again parse, which PIDs it get and send proper signals to them. Also,
should be completely safe for zdtm.py, because it doesn't use Makefiles
and sends signals on it's own.

Signed-off-by: Vitaly Ostrosablin <vostrosablin at virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov at openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov at virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/static/Makefile     | 4 ++--
 test/zdtm/transition/Makefile | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index af1254f5..8fe9d953 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -338,7 +338,7 @@ start:	$(PID) $(STATE)
 check_start:	$(PID:%.pid=%.is_running)
 
 stop:	$(STATE_OUT)
-	-kill -TERM `cat *.pid`
+	-kill -TERM `awk '{print}' *.pid`
 
 WAIT_TIME=240
 %.stop:	%.pid %
@@ -356,7 +356,7 @@ WAIT_TIME=240
 wait_stop:
 		i=0; \
 		while [ $$i -lt $(WAIT_TIME) ] ; do \
-		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
+		kill -0 `awk '{print}' *.pid 2>/dev/null` 2>/dev/null || break; \
 		sleep 1; \
 		i=`expr $$i + 1`; \
 	done
diff --git a/test/zdtm/transition/Makefile b/test/zdtm/transition/Makefile
index 7ddb2384..dfc10ef5 100644
--- a/test/zdtm/transition/Makefile
+++ b/test/zdtm/transition/Makefile
@@ -65,12 +65,12 @@ start:	$(PID)
 check_start:	$(PID:%.pid=%.is_running)
 
 stop:
-	-kill -TERM `cat *.pid`
+	-kill -TERM `awk '{print}' *.pid`
 
 WAIT_TIME=10
 wait_stop:
 	-for i in `seq 1 $(WAIT_TIME)`; do \
-		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
+		kill -0 `awk '{print}' *.pid 2>/dev/null` 2>/dev/null || break; \
 		sleep 1; \
 	done
 
-- 
2.11.0



More information about the CRIU mailing list