--- main.c 2014-08-20 09:45:52.585530000 -0700 +++ main.c 2014-08-22 11:29:54.792973000 -0700 @@ -169,6 +169,7 @@ char warn_f_flag = '\0'; bool run_in_foreground = false; /* -bD mode */ bool queuerun = false, debug = false; + bool queueintvl = false; struct passwd *pw; struct hostent *hp; char *nullserver = NULL; @@ -482,6 +483,8 @@ case 'q': /* just check if it is there */ queuerun = true; + if (optarg[0]) + queueintvl = true; break; } } @@ -707,6 +710,25 @@ /* version */ macdefine(&BlankEnvelope.e_macro, A_PERM, 'v', Version); + /* + * We have to fork early if starting as a daemon to + * prevent resolver lookup problems (e.g. no net available) + * from stalling the rc boot. + */ + if (OpMode == MD_DAEMON || queueintvl == true) { + /* put us in background */ + i = fork(); + if (i < 0) + syserr("daemon: cannot fork"); + if (i != 0) + { + finis(false, true, EX_OK); + /* NOTREACHED */ + } + disconnect(2, CurEnv); + CurrentPid = getpid(); + } + /* hostname */ hp = myhostname(jbuf, sizeof(jbuf)); if (jbuf[0] != '\0') @@ -2305,6 +2327,7 @@ ** doing it in background. ** We check for any errors that might have happened ** during startup. + ** We have ALREADY forked if a daemon. */ if (OpMode == MD_DAEMON || QueueIntvl > 0) @@ -2315,6 +2338,7 @@ DaemonPid = 0; if (!run_in_foreground && !tTd(99, 100)) { +#if 0 /* put us in background */ i = fork(); if (i < 0) @@ -2324,6 +2348,7 @@ finis(false, true, EX_OK); /* NOTREACHED */ } +#endif /* ** Initialize exception stack and default exception @@ -2563,9 +2588,12 @@ macdefine(&BlankEnvelope.e_macro, A_TEMP, '_', authinfo); /* at this point we are in a child: reset state */ - sm_rpool_free(MainEnvelope.e_rpool); - (void) newenvelope(&MainEnvelope, &MainEnvelope, - sm_rpool_new_x(NULL)); + { + SM_RPOOL_T *opool = MainEnvelope.e_rpool; + (void) newenvelope(&MainEnvelope, &MainEnvelope, + sm_rpool_new_x(NULL)); + sm_rpool_free(opool); + } } if (LogLevel > 9)