ref: 30cae77283e7835928d0f3e1e67eca5c1efa2b18
parent: 003cf74c555835ee8941a3e37b3ad265cc8c50de
author: Quentin Rameau <quinq@fifth.space>
date: Wed Jun 15 11:57:49 EDT 2016
[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!
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -196,7 +196,7 @@
{
struct tool *t = &tools[tool];
int i, fds[2];
- static int fdin;
+ static int fdin = -1;
switch (tool) {
case TEEIR:
@@ -233,9 +233,9 @@
break;
}
- if (fdin) {
+ if (fdin > -1) {
t->in = fdin;
- fdin = 0;
+ fdin = -1;
} else if (infile) {
addarg(tool, xstrdup(infile));
}
@@ -261,9 +261,9 @@
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",
@@ -270,9 +270,9 @@
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;
}
@@ -317,8 +317,8 @@
t->nargs = t->nparams;
t->pid = 0;
t->error = 0;
- t->in = 0;
- t->out = 0;
+ t->in = -1;
+ t->out = -1;
}
}
}