]> diplodocus.org Git - nmh/commitdiff
Only call fork(2) once, not up to five times on failure.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sat, 9 Sep 2017 10:32:01 +0000 (11:32 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sat, 9 Sep 2017 10:32:01 +0000 (11:32 +0100)
The existing loop that slept five seconds between each attempt was
copy-pasted widely.  Those days are gone.  Just call it once.

12 files changed:
mts/smtp/smtp.c
sbr/push.c
uip/forw.c
uip/mhbuildsbr.c
uip/mhparse.c
uip/mhshowsbr.c
uip/post.c
uip/rcvdist.c
uip/sendsbr.c
uip/slocal.c
uip/whatnowsbr.c
uip/whom.c

index 1b92db9f056376a054e5aa11dea7bf09c7eb57a8..f340e1ee9e9297b62b58ee164c2c3bb14f3d5a40 100644 (file)
@@ -307,9 +307,7 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl,
        return sm_ierror ("no pipes");
     }
 
        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]);
     switch (sm_child) {
        case NOTOK: 
            close (pdo[0]);
index d77e37548d939f3ff276cf060bf09f790e169e79..6708db4700a7b19857f43d00984e53fe11f8859a 100644 (file)
@@ -14,11 +14,8 @@ void
 push(void)
 {
     pid_t pid;
 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 */
     switch (pid) {
        case -1:
            /* fork error */
index 5e7db30bcc6cb9a3ddc2d8513602dc562014baa4..153b79539bb180cfbebca94fc5d24d88580f30ae 100644 (file)
@@ -484,7 +484,7 @@ mhl_draft (int out, char *digest, int volume, int issue,
             char *file, char *filter, int dashstuff)
 {
     pid_t child_id;
             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;
     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);
 
 
     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");
     switch (child_id) {
        case NOTOK: 
            adios ("fork", "unable to");
index 118b82b7d8a0e4b9f81377aec213739270c51988..9c5bd92a7cec676dca45f76e9f2d62c7c7d5a754 100644 (file)
@@ -1221,7 +1221,7 @@ compose_content (CT ct, int verbose)
     default:
        if (!ce->ce_file) {
            pid_t child_id;
     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;
            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");
 
            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");
            switch (child_id) {
            case NOTOK:
                adios ("fork", "unable to fork");
index fda2de0b3ed15794226e89bdff13dcf143a5a207..716f3900607e4059d09a220bb0114436afb58cb6 100644 (file)
@@ -2556,7 +2556,7 @@ openFTP (CT ct, char **file)
     }
 
     {
     }
 
     {
-       int child_id, i, vecp;
+       int child_id, vecp;
        char *vec[9];
 
        vecp = 0;
        char *vec[9];
 
        vecp = 0;
@@ -2573,8 +2573,7 @@ openFTP (CT ct, char **file)
 
        fflush (stdout);
 
 
        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");
        switch (child_id) {
            case NOTOK:
                adios ("fork", "unable to");
@@ -2652,7 +2651,7 @@ InitMail (CT ct)
 static int
 openMail (CT ct, char **file)
 {
 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;
     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;
 
     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");
     switch (child_id) {
        case NOTOK:
            advise ("fork", "unable to");
index d0102044ce52c91588b5d1bd84e01b43ae6f303b..3b54a4c7048fe34157b822e2adda4e220caedcad 100644 (file)
@@ -193,7 +193,7 @@ static void
 DisplayMsgHeader (CT ct, char *form, int concatsw)
 {
     pid_t child_id;
 DisplayMsgHeader (CT ct, char *form, int concatsw)
 {
     pid_t child_id;
-    int i, vecp;
+    int vecp;
     char **vec;
     char *file;
 
     char **vec;
     char *file;
 
@@ -217,9 +217,7 @@ DisplayMsgHeader (CT ct, char *form, int concatsw)
 
     fflush (stdout);
 
 
     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");
     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 fd, int xlist, int xstdin, struct format *fmt)
 {
     pid_t child_id;
-    int i, vecp;
+    int vecp;
     char **vec, *file;
 
     if (debugsw || cracked) {
     char **vec, *file;
 
     if (debugsw || cracked) {
@@ -466,8 +464,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer,
 
     fflush (stdout);
 
 
     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");
     switch (child_id) {
        case NOTOK:
            advise ("fork", "unable to");
index ec85d93ce207f9fca12b612080cc515d135047f1..f7726885c55a809c375df3651cdb5102f1abd598 100644 (file)
@@ -1512,8 +1512,7 @@ make_bcc_file (int dashstuff)
      * of MIME encapsulation.
      */
     if (filter != NULL) {
      * 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");
        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)
 {
 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) {
     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;
 
        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");
        switch (child_id) {
            case NOTOK: 
                adios ("fork", "unable to");
@@ -1982,7 +1980,7 @@ static void
 fcc (char *file, char *folder)
 {
     pid_t child_id;
 fcc (char *file, char *folder)
 {
     pid_t child_id;
-    int i, status, argp;
+    int status, argp;
     char fold[BUFSIZ];
     char **arglist, *program;
 
     char fold[BUFSIZ];
     char **arglist, *program;
 
@@ -1990,9 +1988,7 @@ fcc (char *file, char *folder)
        printf ("  %sFcc %s: ", msgstate == RESENT ? "Resent-" : "", folder);
     fflush (stdout);
 
        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)
     switch (child_id) {
        case NOTOK: 
            if (!verbose)
index a123f8e9cb1d75ed5b9e69fa25075e4507b7543d..35bbfb7cbbcb201487c4d7cf8d9a5f1499a93694 100644 (file)
@@ -41,7 +41,7 @@ int
 main (int argc, char **argv)
 {
     pid_t child_id;
 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;
     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;
 
     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...");
     switch (child_id) {
        case NOTOK: 
            inform("unable to fork, continuing...");
index 4106010078cca75bf449494ddeeb84d112b3c0df..0d13b52823eee3c6ef0fc6a3c7440760c0c6c135 100644 (file)
@@ -424,7 +424,7 @@ static int
 sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
 {
     pid_t child_id;
 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;
     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;
 
        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 */
     switch (child_id) {
     case -1:
        /* oops -- fork error */
@@ -514,14 +512,12 @@ static void
 alert (char *file, int out)
 {
     pid_t child_id;
 alert (char *file, int out)
 {
     pid_t child_id;
-    int i, in, argp;
+    int in, argp;
     char buf[BUFSIZ];
     char *program;
     char **arglist;
 
     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 */
     switch (child_id) {
        case NOTOK:
            /* oops -- fork error */
index bd751a1f5c0880574f462340a88baf9f13a7359d..d8568036f425f22abea4b5b2162bef883643d387 100644 (file)
@@ -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;
 {
     volatile int fd = fd_arg;
     pid_t child_id;
-    int i, bytes, seconds, status;
+    int bytes, seconds, status;
     struct stat st;
 
     if (verbose && !suppress)
     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);
 
 
     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 */
     switch (child_id) {
        case -1: 
            /* fork error */
index fe1b2f7ec11752b9fb84f7cc567b96f5772f131e..f06d4b3a1e0a17707078f404895862fdd5a0d651 100644 (file)
@@ -801,7 +801,7 @@ static int
 sendfile (char **arg, char *file, int pushsw)
 {
     pid_t child_id;
 sendfile (char **arg, char *file, int pushsw)
 {
     pid_t child_id;
-    int i, vecp;
+    int vecp;
     char *cp, *sp, **vec, *program;
 
     /*
     char *cp, *sp, **vec, *program;
 
     /*
@@ -818,8 +818,7 @@ sendfile (char **arg, char *file, int pushsw)
     context_save ();   /* save the context file */
     fflush (stdout);
 
     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...");
     switch (child_id) {
        case NOTOK:
            inform("unable to fork, so sending directly...");
index d172f9463b6656451f7508c31ef5ab035ec169a5..542e67ff3dac359a160ace6509a8f543916a1f7e 100644 (file)
@@ -58,7 +58,7 @@ int
 main (int argc, char **argv)
 {
     pid_t child_id = OK;
 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];
     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);
 
 
     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:
 
     switch (distsw ? child_id : OK) {
        case NOTOK: