#include #include #include #include #include #include #include #include #include #include #include "dccif.h" #include "dcc_clnt.h" #include "dcc_paths.h" void do_dcc(void) __attribute__ ((noreturn)); #define NPROCS 10 int verbose = 0; typedef struct { pid_t pid; } childInfo_t; childInfo_t childInfo[NPROCS]; unsigned int goodexits, badexits; void do_dcc(void) { DCC_EMSG emsg; const char *srvr_addr; u_char result; const char *body_text = "From: xxx@yyy.foo.bar\nMessage-Id: a12345@9999\nReceived: a12345@9999\nSRPair: tester@vwiz.co.uk|testmailer@yyy.foo.bar\nTo: help.me@foo.bar\nSubject: SomeTestMail\n\n\nHello this is some test mail\n"; char *out_buf = malloc(4096); if (!out_buf) { fprintf(stderr, "Out of memory\n"); exit(1); } emsg[0] = 0; srvr_addr = 0; out_buf[0] = 0; result = dccif(emsg, -1, &out_buf, "header query", 0, 0, 0, 0, 0, -1, body_text, srvr_addr); exit(0); } int main(void) { pid_t pid; int i; int status; srand(time(0) & getpid()); while (1) { for (i = 0; i < NPROCS; i++) { /* If there are any slots free, fork a new child and send it on its way */ if (childInfo[i].pid == 0) { if ((pid = fork()) == -1) { perror("Fork failed : "); exit(1); } if (pid) { childInfo[i].pid = pid; } else { do_dcc(); /* NOTREACHED */ } } } /* Now the slots are full, wait for one to die. */ pid = wait(&status); for (i = 0; i < NPROCS; i++) { if (childInfo[i].pid == pid) { status ? badexits++ : goodexits++; fprintf(stderr, "\rReqs:%-8u", goodexits); childInfo[i].pid = 0; } } } }