[hackers] [scc] [driver] remove temporary files for failed tools || Quentin Rameau

From: <git_AT_suckless.org>
Date: Thu, 2 Jun 2016 18:27:00 +0200 (CEST)

commit 2cc10bb10f465b64b0dfcbf34a17d0c55a099b2b
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Jun 2 17:45:27 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Thu Jun 2 18:23:35 2016 +0200

    [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.

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index 4301b46..bb6bda8 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -30,7 +30,6 @@ static struct tool {
         char cmd[PATH_MAX];
         char *args[NARGS];
         char bin[16];
- char *outfile;
         int nargs, in, out;
         pid_t pid;
 } tools[NR_TOOLS] = {
_AT_@ -43,8 +42,22 @@ static struct tool {
 
 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)
 {
_AT_@ -54,6 +67,8 @@ terminate(void)
                 if (tools[i].pid)
                         kill(tools[i].pid, SIGTERM);
         }
+
+ cleanup();
 }
 
 int
_AT_@ -137,8 +152,8 @@ settool(int tool, char *input, int output)
                 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;
_AT_@ -230,18 +245,23 @@ build(char *file)
                 }
 
                 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
Received on Thu Jun 02 2016 - 18:27:00 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 02 2016 - 18:36:19 CEST