summaryrefslogtreecommitdiff
path: root/tools/hi-q.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/hi-q.c')
-rw-r--r--tools/hi-q.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c
index 0f7e444..f0e107a 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -134,16 +134,8 @@ int main(int argc, char** argv, char const * const * env) {
#endif
- const char* spamc_args[] = {"/usr/local/bin/spamc", "-Z", "7", 0};
- const char* qq_args[] = {"/var/qmail/bin/qmail-queue", 0};
- const char** joblist[] = {
- spamc_args,
- qq_args,
- 0 // required: zero terminates the list
- };
-
typedef vector<string> VS;
- vector<VS> filters;
+ vector<VS> filter;
if (argc != 2) {
cerr << "Usage: hi-q filter.conf" << endl;
exit(1);
@@ -169,10 +161,10 @@ int main(int argc, char** argv, char const * const * env) {
if (token[0] == '#') break;
job.push_back(token);
}
- if (job.size()) filters.push_back(job);
+ if (job.size()) filter.push_back(job);
}
- if (verbose) for (vector<VS>::const_iterator job = filters.begin();
- job != filters.end(); job++) {
+ if (verbose) for (vector<VS>::const_iterator job = filter.begin();
+ job != filter.end(); job++) {
for (VS::const_iterator token = job->begin();
token != job->end(); token++){
cerr << *token << " ";
@@ -180,21 +172,18 @@ int main(int argc, char** argv, char const * const * env) {
cerr << endl;
}
- int nkids;
- pid_t* kidpid; // indexed by kid number
-
- for (nkids = 0; joblist[nkids]; nkids++) {} // count 'em
- kidpid = (pid_t*) malloc(nkids * sizeof(pid_t));
+ int nkids = filter.size();
+ vector<pid_t> kidpid(nkids); // indexed by kid number
-// At this point, there is some loop invariants;
+// At this point, there are some loop invariants;
// (a) fd0 is open and ready for the next child to read, and
// (b) fd1 is open but is something children can (and should)
// throw away as soon as convenient.
- {int ii; for (ii=0; joblist[ii]; ii++){ /* loop over all kids */
+ {int ii; for (ii=0; ii < nkids; ii++){ /* loop over all kids */
int datapipe[2];
int kid_end;
- int lastkid = !joblist[ii+1];
+ int lastkid = (ii == nkids-1);
#define flip(a,b) (lastkid ? b : a)
//xx fprintf(stderr, "Top of loop %d loose: %d\n", ii, loose_end);
@@ -222,7 +211,6 @@ int main(int argc, char** argv, char const * const * env) {
kidpid[ii] = fork();
if (!kidpid[ii]) { /*** child code ***/
- const char ** prog;
// Now that we are through creating pipes, get rid
// of the placeholder:
@@ -242,7 +230,12 @@ int main(int argc, char** argv, char const * const * env) {
// and write fd1 (except last kid reads fd1).
//// probe_fd();
- prog = joblist[ii];
+ int ntok = filter[ii].size();
+ const char* prog[1+ntok];
+ for (int jj = 0; jj < ntok; jj++){
+ prog[jj] = filter[ii][jj].c_str();
+ }
+ prog[ntok] = 0;
rslt = Execve(prog[0], prog, env);
fprintf(stderr, "hi-q: failed to exec '%s': ", prog[0]);
perror(0);