[CRIU] [PATCH] zdtm: print correct errno messages from err() and fail()

Andrey Vagin avagin at openvz.org
Thu Feb 12 11:35:53 PST 2015


"%m" can't be used to print strerror(errno), because test_msg()
calls gettimeofday() which can overwrite errno.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/lib/zdtmtst.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index cea7d35..28ee536 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -91,6 +91,7 @@ extern int parse_opt_string(char *param, void *arg);
 
 #include <stdio.h>
 #include <errno.h>
+#include <string.h>
 
 #define __stringify_1(x)        #x
 #define __stringify(x)          __stringify_1(x)
@@ -99,11 +100,11 @@ extern int parse_opt_string(char *param, void *arg);
 extern void setup_outfile(void);
 extern int test_log_init(const char *outfile, const char *suffix);
 #define err(format, arg...)	\
-	test_msg("ERR: %s:%d: " format " (errno = %d (%m))\n", \
-		__FILE__, __LINE__, ## arg, errno)
+	test_msg("ERR: %s:%d: " format " (errno = %d (%s))\n", \
+		__FILE__, __LINE__, ## arg, errno, strerror(errno))
 #define fail(format, arg...)	\
-	test_msg("FAIL: %s:%d: " format " (errno = %d (%m))\n", \
-		 __FILE__, __LINE__, ## arg, errno)
+	test_msg("FAIL: %s:%d: " format " (errno = %d (%s))\n", \
+		 __FILE__, __LINE__, ## arg, errno, strerror(errno))
 #define skip(format, arg...)	\
 	test_msg("SKIP: %s:%d: " format "\n", \
 		 __FILE__, __LINE__, ## arg)
-- 
1.9.3



More information about the CRIU mailing list