[PATCH libinput v2] test: check getcwd() and system() return values in litest

Jon A. Cruz jonc at osg.samsung.com
Mon Jun 1 12:55:21 PDT 2015


Added code to check for errors in getcwd() and system() that
were previously ignored and silently dropped.

Signed-off-by: Jon A. Cruz <jonc at osg.samsung.com>
---
 test/litest.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/test/litest.c b/test/litest.c
index 30d3056..ac66c45 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -85,7 +85,11 @@ litest_backtrace_get_lineno(const char *executable,
 	unsigned int i;
 
 	if (!cwd[0])
-		getcwd(cwd, sizeof(cwd));
+		if (getcwd(cwd, sizeof(cwd)) == NULL) {
+			cwd[0] = 0; /* contents otherwise undefined. */
+			litest_log("getcwd failed: (%s)\n", strerror(errno));
+			return false;
+		}
 
 	sprintf (buffer,
 		 ADDR2LINE " -C -e %s -i %lx",
@@ -375,7 +379,15 @@ static struct list all_tests;
 static void
 litest_reload_udev_rules(void)
 {
-	system("udevadm control --reload-rules");
+	int ret = system("udevadm control --reload-rules");
+	if (ret == -1) {
+		litest_log("Failed to execute: udevadm\n");
+	} else if (WIFEXITED(ret)) {
+		if (WEXITSTATUS(ret))
+			litest_log("udevadm failed with %d", WEXITSTATUS(ret));
+	} else if (WIFSIGNALED(ret)) {
+		litest_log("udevadm terminated with signal %d", WTERMSIG(ret));
+	}
 }
 
 static int
-- 
2.1.0



More information about the wayland-devel mailing list