[hackers] [sbase][PATCH 3/6] find: Fix spawn() return value

From: Tavian Barnes <tavianator_AT_tavianator.com>
Date: Fri, 14 Feb 2025 11:25:06 -0500

---
 find.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/find.c b/find.c
index ce551e5..71488da 100644
--- a/find.c
+++ b/find.c
_AT_@ -244,6 +244,7 @@ spawn(char *argv[])
 	switch((pid = fork())) {
 	case -1:
 		eprintf("fork:");
+		return -1;
 	case 0:
 		execvp(*argv, argv);
 		weprintf("exec %s failed:", *argv);
_AT_@ -252,7 +253,7 @@ spawn(char *argv[])
 
 	/* FIXME: proper course of action for waitpid() on EINTR? */
 	waitpid(pid, &status, 0);
-	return status;
+	return WIFEXITED(status) && WEXITSTATUS(status) == 0 ? 0 : -1;
 }
 
 static int
-- 
2.48.1
Received on Fri Feb 14 2025 - 17:25:06 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 14 2025 - 18:24:39 CET