summaryrefslogtreecommitdiff
path: root/tools/hi-q.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-15 09:35:13 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-15 09:35:13 (GMT)
commitfb370451e736c934bbc7644da114c796afb1b735 (patch)
treeb2af780be521db4aaa5aebcab1fd1f53ea01bc96 /tools/hi-q.c
parentc7bfbf600424d10d7c464dc84a25611470da5d1f (diff)
probably working
Diffstat (limited to 'tools/hi-q.c')
-rw-r--r--tools/hi-q.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c
index b2a4c7c..f2da44d 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -212,7 +212,9 @@ int main(int argc, char** argv, char const * const * env) {
const int rEnd(0); // end of a pipe for reading
const int wEnd(1); // end of a pipe for writing
int sync[2];
+ int resync[2];
if (pipe(sync) != 0) cerr << "sync pipe failed" << endl;
+ if (pipe(resync) != 0) cerr << "resync pipe failed" << endl;
// At this point, there are some loop invariants;
// (a) fd0 is open (standard input) and has the email msg,
@@ -272,6 +274,7 @@ int main(int argc, char** argv, char const * const * env) {
cerr << "*** kid " << ii << " setpgid OK" << endl;
}
+// everybody else has to wait for us to get this far
if (ii == 0) {
int junk(1);
write(sync[wEnd], &junk, 1);
@@ -283,7 +286,22 @@ int main(int argc, char** argv, char const * const * env) {
<< " pgid: " << getpgid(0)
<< " starts" << endl;
#endif
- usleep(50000);
+ close(resync[wEnd]);
+// Now we wait for everybody else:
+ if (ii==0) {
+ int junk;
+ cerr << "about to read resync" << endl;
+ ssize_t rslt = read(resync[rEnd], &junk, 1);
+ if (rslt != 1) {
+ cerr << "bad sync ... 1 != " << rslt << endl;
+ } else {
+ cerr << "back from read resync, good: " << rslt << endl;
+ }
+ }
+
+//###### usleep(50000);
+
+
// Now that we are through creating pipes, we don't
// need to continue blocking fd1:
close(1);
@@ -324,18 +342,18 @@ int main(int argc, char** argv, char const * const * env) {
}
close(kid_end);
+// Let kid #0 run a little ways:
if (ii==0) {
int junk;
cerr << "about to read sync" << endl;
ssize_t rslt = read(sync[rEnd], &junk, 1);
- if (rslt != 1) {
+ if (rslt < 0) {
cerr << "bad sync ... 1 != " << rslt << endl;
} else {
cerr << "back from read sync, good: " << rslt << endl;
}
}
-
// it is important to let kid#0 run a while;
// otherwise it won't fully exist when the other kids start,
// and depending race conditions, the setpgid could fail
@@ -351,6 +369,8 @@ int main(int argc, char** argv, char const * const * env) {
// here with the whole pipeline of kids launched
+ close(resync[wEnd]);
+
close(0); // the reading end of stdin was
// delegated to the first child