[hackers] [scc] [driver] set unassigned fds to -1 || Quentin Rameau
commit fd8427efdb2eb026dcc042d85a53af51d5d9e37d
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Wed Jun 15 15:57:49 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Wed Jun 15 18:50:46 2016 +0200
[driver] set unassigned fds to -1
Although pipe() would never return fds < 2 in our case, it's more
correct to check against negative fd.
Thanks to Hiltjo for the suggestion!
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index a81eef4..92a14b0 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -196,7 +196,7 @@ settool(int tool, char *infile, int nexttool)
{
struct tool *t = &tools[tool];
int i, fds[2];
- static int fdin;
+ static int fdin = -1;
switch (tool) {
case TEEIR:
_AT_@ -233,9 +233,9 @@ settool(int tool, char *infile, int nexttool)
break;
}
- if (fdin) {
+ if (fdin > -1) {
t->in = fdin;
- fdin = 0;
+ fdin = -1;
} else if (infile) {
addarg(tool, xstrdup(infile));
}
_AT_@ -261,18 +261,18 @@ spawn(int tool)
case -1:
die("scc: %s: %s", t->bin, strerror(errno));
case 0:
- if (t->out)
+ if (t->out > -1)
dup2(t->out, 1);
- if (t->in)
+ if (t->in > -1)
dup2(t->in, 0);
execvp(t->cmd, t->args);
fprintf(stderr, "scc: execvp %s: %s\n",
t->cmd, strerror(errno));
_exit(1);
default:
- if (t->in)
+ if (t->in > -1)
close(t->in);
- if (t->out)
+ if (t->out > -1)
close(t->out);
break;
}
_AT_@ -317,8 +317,8 @@ validatetools(void)
t->nargs = t->nparams;
t->pid = 0;
t->error = 0;
- t->in = 0;
- t->out = 0;
+ t->in = -1;
+ t->out = -1;
}
}
}
Received on Wed Jun 15 2016 - 19:00:07 CEST
This archive was generated by hypermail 2.3.0
: Wed Jun 15 2016 - 19:01:01 CEST