ref: 07a329b7e6b3703b47b98fd6a954d68b8d36bb08
parent: f7b4596d49179ac58320567da18a594515d24121
author: Quentin Rameau <[email protected]>
date: Thu Jun 2 13:45:27 EDT 2016
[driver] remove temporary files for failed tools Keep the files that has been correctly generated, but remove those from the failed tool and subsequente ones.
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -30,7 +30,6 @@
char cmd[PATH_MAX];
char *args[NARGS];
char bin[16];
- char *outfile;
int nargs, in, out;
pid_t pid;
} tools[NR_TOOLS] = {
@@ -43,8 +42,22 @@
char *argv0;
static char *arch;
+static char *outfiles[NR_TOOLS];
+static int failedtool = NR_TOOLS;
static int Eflag, Sflag, kflag;
+void
+cleanup(void)
+{
+ int i;
+
+ for (i = 0; i < NR_TOOLS; ++i) {
+ if (i > failedtool && outfiles[i])
+ unlink(outfiles[i]);
+ free(outfiles[i]);
+ }
+}
+
static void
terminate(void)
{
@@ -54,6 +67,8 @@
if (tools[i].pid)
kill(tools[i].pid, SIGTERM);
}
+
+ cleanup();
}
int
@@ -137,8 +152,8 @@
case AS:
ext = "as"; break;
}
- t->outfile = newfileext(input, ext);
- t->args[1] = t->outfile;
+ outfiles[output] = newfileext(input, ext);
+ t->args[1] = outfiles[output];
break;
default:
break;
@@ -230,18 +245,23 @@
}
spawn(settool(inittool(tool), file, out));
-
- free(tools[tool].outfile);
}
+
for (i = 0; i < NR_TOOLS; ++i) {
if ((pid = tools[i].pid) == 0)
continue;
- if (waitpid(pid, &st, 0) < 0)
+ if (waitpid(pid, &st, 0) < 0) {
+ failedtool = i;
exit(-1);
+ }
tools[i].pid = 0;
- if (!WIFEXITED(st) || WEXITSTATUS(st) != 0)
+ if (!WIFEXITED(st) || WEXITSTATUS(st) != 0) {
+ failedtool = i;
exit(-1);
+ }
}
+
+ cleanup();
}
static void