summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/hi-q.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c
index 6d73b9b..0dc66d7 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -51,7 +51,7 @@ void slurp(const int inch, const int ouch){
while (todo) {
ssize_t sent = write(ouch, buf, todo);
if (sent < 0 && errno != EINTR) {
- fprintf(stderr, "hi-q: output error: ");
+ fprintf(stderr, "hi-q: output error on fd%d : ", ouch);
perror(0);
panic(ex_comerr);
}
@@ -121,6 +121,11 @@ void dump(const string var){
else cerr << "hi-q: " << var << " is not set." << endl;
}
+int xclose(int arg){
+ cerr << "closing " << arg << endl;
+ return close(arg);
+}
+
int main(int argc, char** argv, char const * const * env) {
int verbose(1);
int kidstatus;
@@ -289,7 +294,8 @@ int main(int argc, char** argv, char const * const * env) {
<< " starts" << endl;
#endif
- close(resync[wEnd]);
+ close(resync[wEnd]); // send resync
+
// ... now we must wait for everybody else, because ...
// ... if we do the exec(), the new process group becomes invalid ...
// Close synchronization is released when the *last* guy closes.
@@ -304,9 +310,6 @@ int main(int argc, char** argv, char const * const * env) {
}
}
-//###### usleep(50000);
-
-
// Now that we are through creating pipes, we don't
// need to continue blocking fd1:
close(1);
@@ -333,6 +336,9 @@ int main(int argc, char** argv, char const * const * env) {
prog[jj] = filter[ii][jj].c_str();
}
prog[ntok] = 0;
+ close(resync[rEnd]);
+ close(sync[rEnd]);
+ close(sync[wEnd]);
rslt = Execve(prog[0], prog, env);
fprintf(stderr, "hi-q: failed to exec '%s': ", prog[0]);
perror(0);
@@ -368,8 +374,11 @@ int main(int argc, char** argv, char const * const * env) {
// here with the whole pipeline of kids launched
- close(resync[wEnd]);
- close(resync[rEnd]);
+ close(resync[wEnd]); // important, so that block gets released
+ close(resync[rEnd]); // less important, just housecleaning
+
+ close(sync[wEnd]); // more housecleaning
+ close(sync[rEnd]);
close(0); // the reading end of stdin was
// delegated to the first child