2e03a64e1cd26e574062fe17beca9dc2933e3432
[dragonfly.git] / usr.sbin / sendmail / main.c.patch
1 --- main.c      2014-08-20 09:45:52.585530000 -0700
2 +++ main.c      2014-08-22 11:29:54.792973000 -0700
3 @@ -169,6 +169,7 @@
4         char warn_f_flag = '\0';
5         bool run_in_foreground = false; /* -bD mode */
6         bool queuerun = false, debug = false;
7 +       bool queueintvl = false;
8         struct passwd *pw;
9         struct hostent *hp;
10         char *nullserver = NULL;
11 @@ -482,6 +483,8 @@
12                   case 'q':
13                         /* just check if it is there */
14                         queuerun = true;
15 +                       if (optarg[0])
16 +                               queueintvl = true;
17                         break;
18                 }
19         }
20 @@ -707,6 +710,25 @@
21         /* version */
22         macdefine(&BlankEnvelope.e_macro, A_PERM, 'v', Version);
23  
24 +       /*
25 +        * We have to fork early if starting as a daemon to
26 +        * prevent resolver lookup problems (e.g. no net available)
27 +        * from stalling the rc boot.
28 +        */
29 +       if (OpMode == MD_DAEMON || queueintvl == true) {
30 +               /* put us in background */
31 +               i = fork();
32 +               if (i < 0)
33 +                       syserr("daemon: cannot fork");
34 +               if (i != 0)
35 +               {
36 +                       finis(false, true, EX_OK);
37 +                       /* NOTREACHED */
38 +               }
39 +               disconnect(2, CurEnv);
40 +               CurrentPid = getpid();
41 +       }
42 +
43         /* hostname */
44         hp = myhostname(jbuf, sizeof(jbuf));
45         if (jbuf[0] != '\0')
46 @@ -2305,6 +2327,7 @@
47         **              doing it in background.
48         **      We check for any errors that might have happened
49         **              during startup.
50 +       **      We have ALREADY forked if a daemon.
51         */
52  
53         if (OpMode == MD_DAEMON || QueueIntvl > 0)
54 @@ -2315,6 +2338,7 @@
55                 DaemonPid = 0;
56                 if (!run_in_foreground && !tTd(99, 100))
57                 {
58 +#if 0
59                         /* put us in background */
60                         i = fork();
61                         if (i < 0)
62 @@ -2324,6 +2348,7 @@
63                                 finis(false, true, EX_OK);
64                                 /* NOTREACHED */
65                         }
66 +#endif
67  
68                         /*
69                         **  Initialize exception stack and default exception
70 @@ -2563,9 +2588,12 @@
71                 macdefine(&BlankEnvelope.e_macro, A_TEMP, '_', authinfo);
72  
73                 /* at this point we are in a child: reset state */
74 -               sm_rpool_free(MainEnvelope.e_rpool);
75 -               (void) newenvelope(&MainEnvelope, &MainEnvelope,
76 -                                  sm_rpool_new_x(NULL));
77 +               {
78 +                       SM_RPOOL_T *opool = MainEnvelope.e_rpool;
79 +                       (void) newenvelope(&MainEnvelope, &MainEnvelope,
80 +                                          sm_rpool_new_x(NULL));
81 +                       sm_rpool_free(opool);
82 +               }
83         }
84  
85         if (LogLevel > 9)