From: Ralph Corderoy Date: Sat, 9 Sep 2017 10:32:01 +0000 (+0100) Subject: Only call fork(2) once, not up to five times on failure. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/e107c0d8298ccd64484270e4f2f76c1514c90313?hp=5977791e005446f4cd8b2f04bfb14c8cd265df8a Only call fork(2) once, not up to five times on failure. The existing loop that slept five seconds between each attempt was copy-pasted widely. Those days are gone. Just call it once. --- diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index 1b92db9f..f340e1ee 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -307,9 +307,7 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl, return sm_ierror ("no pipes"); } - for (i = 0; (sm_child = fork ()) == NOTOK && i < 5; i++) - sleep (5); - + sm_child = fork(); switch (sm_child) { case NOTOK: close (pdo[0]); diff --git a/sbr/push.c b/sbr/push.c index d77e3754..6708db47 100644 --- a/sbr/push.c +++ b/sbr/push.c @@ -14,11 +14,8 @@ void push(void) { pid_t pid; - int i; - - for (i = 0; (pid = fork()) == -1 && i < 5; i++) - sleep (5); + pid = fork(); switch (pid) { case -1: /* fork error */ diff --git a/uip/forw.c b/uip/forw.c index 5e7db30b..153b7953 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -484,7 +484,7 @@ mhl_draft (int out, char *digest, int volume, int issue, char *file, char *filter, int dashstuff) { pid_t child_id; - int i, msgnum, pd[2]; + int msgnum, pd[2]; char buf1[BUFSIZ]; char buf2[BUFSIZ]; char *program; @@ -495,9 +495,7 @@ mhl_draft (int out, char *digest, int volume, int issue, argsplit_msgarg(&vec, mhlproc, &program); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to"); diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 118b82b7..9c5bd92a 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -1221,7 +1221,7 @@ compose_content (CT ct, int verbose) default: if (!ce->ce_file) { pid_t child_id; - int i, xstdout, len, buflen; + int xstdout, len, buflen; char *bp, *cp; char *vec[4], buffer[BUFSIZ]; FILE *out; @@ -1321,8 +1321,7 @@ raw: if ((out = fopen (ce->ce_file, "w")) == NULL) adios (ce->ce_file, "unable to open for writing"); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to fork"); diff --git a/uip/mhparse.c b/uip/mhparse.c index fda2de0b..716f3900 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -2556,7 +2556,7 @@ openFTP (CT ct, char **file) } { - int child_id, i, vecp; + int child_id, vecp; char *vec[9]; vecp = 0; @@ -2573,8 +2573,7 @@ openFTP (CT ct, char **file) fflush (stdout); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to"); @@ -2652,7 +2651,7 @@ InitMail (CT ct) static int openMail (CT ct, char **file) { - int child_id, fd, i, vecp; + int child_id, fd, vecp; int len, buflen; char *bp, buffer[BUFSIZ], *vec[7]; struct exbody *e = ct->c_ctexbody; @@ -2708,8 +2707,7 @@ openMail (CT ct, char **file) vec[vecp++] = e->eb_body; vec[vecp] = NULL; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: advise ("fork", "unable to"); diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index d0102044..3b54a4c7 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -193,7 +193,7 @@ static void DisplayMsgHeader (CT ct, char *form, int concatsw) { pid_t child_id; - int i, vecp; + int vecp; char **vec; char *file; @@ -217,9 +217,7 @@ DisplayMsgHeader (CT ct, char *form, int concatsw) fflush (stdout); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to"); @@ -396,7 +394,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, int fd, int xlist, int xstdin, struct format *fmt) { pid_t child_id; - int i, vecp; + int vecp; char **vec, *file; if (debugsw || cracked) { @@ -466,8 +464,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, fflush (stdout); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: advise ("fork", "unable to"); diff --git a/uip/post.c b/uip/post.c index ec85d93c..f7726885 100644 --- a/uip/post.c +++ b/uip/post.c @@ -1512,8 +1512,7 @@ make_bcc_file (int dashstuff) * of MIME encapsulation. */ if (filter != NULL) { - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to"); @@ -1669,7 +1668,7 @@ static void post (char *file, int bccque, int talk, int eai, char *envelope, int oauth_flag, char *auth_svc) { - int retval, i; + int retval; pid_t child_id; if (verbose) { @@ -1686,8 +1685,7 @@ post (char *file, int bccque, int talk, int eai, char *envelope, char **argp, *program; int argc; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to"); @@ -1982,7 +1980,7 @@ static void fcc (char *file, char *folder) { pid_t child_id; - int i, status, argp; + int status, argp; char fold[BUFSIZ]; char **arglist, *program; @@ -1990,9 +1988,7 @@ fcc (char *file, char *folder) printf (" %sFcc %s: ", msgstate == RESENT ? "Resent-" : "", folder); fflush (stdout); - for (i = 0; (child_id = fork ()) == NOTOK && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case NOTOK: if (!verbose) diff --git a/uip/rcvdist.c b/uip/rcvdist.c index a123f8e9..35bbfb7c 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -41,7 +41,7 @@ int main (int argc, char **argv) { pid_t child_id; - int i, vecp; + int vecp; char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ], *program; char **argp, **arguments, **vec; FILE *fp; @@ -124,8 +124,7 @@ main (int argc, char **argv) vec[vecp++] = drft; vec[vecp] = NULL; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: inform("unable to fork, continuing..."); diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 41060100..0d13b528 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -424,7 +424,7 @@ static int sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) { pid_t child_id; - int i, status, fd, fd2; + int status, fd, fd2; char backup[BUFSIZ], buf[BUFSIZ]; fd = pushsw ? tmp_fd () : NOTOK; @@ -445,9 +445,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) done (1); vec[vecp] = NULL; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case -1: /* oops -- fork error */ @@ -514,14 +512,12 @@ static void alert (char *file, int out) { pid_t child_id; - int i, in, argp; + int in, argp; char buf[BUFSIZ]; char *program; char **arglist; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case NOTOK: /* oops -- fork error */ diff --git a/uip/slocal.c b/uip/slocal.c index bd751a1f..d8568036 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -1046,7 +1046,7 @@ usr_pipe (int fd_arg, char *cmd, char *pgm, char **vec, int suppress) { volatile int fd = fd_arg; pid_t child_id; - int i, bytes, seconds, status; + int bytes, seconds, status; struct stat st; if (verbose && !suppress) @@ -1054,9 +1054,7 @@ usr_pipe (int fd_arg, char *cmd, char *pgm, char **vec, int suppress) lseek(fd, 0, SEEK_SET); - for (i = 0; (child_id = fork()) == -1 && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case -1: /* fork error */ diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index fe1b2f7e..f06d4b3a 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -801,7 +801,7 @@ static int sendfile (char **arg, char *file, int pushsw) { pid_t child_id; - int i, vecp; + int vecp; char *cp, *sp, **vec, *program; /* @@ -818,8 +818,7 @@ sendfile (char **arg, char *file, int pushsw) context_save (); /* save the context file */ fflush (stdout); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: inform("unable to fork, so sending directly..."); diff --git a/uip/whom.c b/uip/whom.c index d172f946..542e67ff 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -58,7 +58,7 @@ int main (int argc, char **argv) { pid_t child_id = OK; - int i, status, isdf = 0; + int status, isdf = 0; int distsw = 0, vecp = 0; char *cp, *dfolder = NULL, *dmsg = NULL; char *msg = NULL, **ap, **argp, backup[BUFSIZ]; @@ -180,10 +180,8 @@ main (int argc, char **argv) closefds (3); - if (distsw) { - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - } + if (distsw) + child_id = fork(); switch (distsw ? child_id : OK) { case NOTOK: