shithub: scc

Download patch

ref: 044e2e63920d3d3c9d50b46c47108c3d013a473d
parent: 98d48074b07237716a405ce4748814e7eb939228
author: Quentin Rameau <quinq@fifth.space>
date: Sat Jun 4 08:04:04 EDT 2016

[driver] add checktool()

Move from build() the check of spawned tools to checktool()

--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -236,10 +236,27 @@
 }
 
 static void
+checktool(int tool)
+{
+	struct tool *t = &tools[tool];
+	int st;
+
+	if (!t->pid)
+		return;
+
+	if (waitpid(t->pid, &st, 0) < 0 ||
+	    !WIFEXITED(st) || WEXITSTATUS(st) != 0) {
+		failedtool = tool;
+		exit(-1);
+	}
+
+	t->pid = 0;
+}
+
+static void
 build(char *file)
 {
-	pid_t pid;
-	int i, st, tool, out, keepfile;
+	int i, tool, out, keepfile;
 	static int preout;
 
 	for (tool = toolfor(file); tool < NR_TOOLS; tool = out) {
@@ -282,19 +299,8 @@
 		spawn(settool(inittool(tool), file, out));
 	}
 
-	for (i = 0; i < NR_TOOLS; ++i) {
-		if ((pid = tools[i].pid) == 0)
-			continue;
-		if (waitpid(pid, &st, 0) < 0) {
-			failedtool = i;
-			exit(-1);
-		}
-		tools[i].pid = 0;
-		if (!WIFEXITED(st) || WEXITSTATUS(st) != 0) {
-			failedtool = i;
-			exit(-1);
-		}
-	}
+	for (i = 0; i < NR_TOOLS; ++i)
+		checktool(i);
 
 	cleanup();
 }