From 8fecb23e962d53c02c7770334190c4d73cd3d5bc Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 15 Jul 2012 03:33:12 -0700 Subject: works, cleaner --- tools/hi-q.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tools') 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 -- cgit v1.2.3