summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/hi-q.c32
-rw-r--r--tools/hi-test.c20
-rwxr-xr-xtools/hi-test4.conf10
3 files changed, 55 insertions, 7 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c
index 8766b08..39c68e3 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -425,13 +425,31 @@ bar
// For N-1 kids, the loose end feeds forward.
// It will be written by this kid and read by the next kid.
- // For the last kid, the loose end connects to hi-q.
- // It will be written by hi-q and read by the last kid.
-
- int lastkid = (ii == nkids-1);
- #define flip(a,b) (lastkid ? b : a)
- loose_end = datapipe[flip(rEnd, wEnd)];
- kid_end = datapipe[flip(wEnd, rEnd)];
+ // For the special kid, the loose end will be its nonstandard input.
+ // It will be written by us (hi-q) and read by the last kid.
+
+ switch (filter[ii].mode) {
+ case series:
+ case sa:
+ loose_end = datapipe[rEnd];
+ kid_end = datapipe[wEnd];
+ break;
+ case qq:
+ loose_end = datapipe[wEnd]; // reverse of normal "series" case
+ kid_end = datapipe[rEnd]; // reverse of normal "series" case
+ break;
+ case postspam:
+ case stub: // didn't need a connection at all
+ cerr << "ignoring fd " << datapipe[wEnd]
+ << " and " << datapipe[rEnd]
+ << endl;
+ xclose(datapipe[wEnd]);
+ xclose(datapipe[rEnd]);
+ break;
+ case fail:
+ cerr << "should never happen: invalid filter" << endl;
+ exeunt(ex_syserr);
+ }
}
kidpid[ii] = fork();
diff --git a/tools/hi-test.c b/tools/hi-test.c
index 47128a9..e2626cc 100644
--- a/tools/hi-test.c
+++ b/tools/hi-test.c
@@ -50,10 +50,22 @@ void dump(const string var){
else cerr << " is not set." << endl;
}
+void countsome(const int unit){
+ char buf[3000];
+ int total(0);
+ for (;;) {
+ int rslt = read(unit, buf, sizeof(buf));
+ if (rslt <= 0) break;
+ total += rslt;
+ }
+ cerr << "read " << total << " bytes from unit " << unit << endl;
+}
+
int main(int _argc, const char** _argv){
int snooze(0);
int status(0);
int killmode(0);
+ int countmode(0);
int argc(_argc);
const char **argv(_argv);
progname = *argv; argv++; argc--;
@@ -84,6 +96,10 @@ int main(int _argc, const char** _argv){
killmode++;
continue;
}
+ if (prefix(arg, "-count")) {
+ countmode++;
+ continue;
+ }
if (arg.substr(0,1) == "x") {
continue;
}
@@ -103,6 +119,10 @@ int main(int _argc, const char** _argv){
if (foo) cerr << " HI_Q_GROUP: " << foo;
cerr << endl;
sleep(snooze);
+ if (countmode) {
+ countsome(0);
+ countsome(1);
+ }
if (killmode) exeunt(status);
exit(status);
}
diff --git a/tools/hi-test4.conf b/tools/hi-test4.conf
new file mode 100755
index 0000000..caabbd2
--- /dev/null
+++ b/tools/hi-test4.conf
@@ -0,0 +1,10 @@
+#!/usr/local/bin/bash-c set -x ; /bin/echo "a b c" | 1</tmp/a /usr/src/qmail/tools/hi-q $0 ; echo $?
+#..............................................................................................................................|||
+#0000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223
+#1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+#! /usr/local/bin/bash-c set -x ; /bin/echo "a b c " | 1</tmp/a TCPREMOTEHOST=asf TCPREMOTEIP=1.2.3.4 /var/qmail/bin/hi-q $0 ; echo $?
+
+series /bin/cat
+stub hi-test x0 -snooze 1
+series /bin/cat
+qq hi-test -count