diff options
Diffstat (limited to 'usr.sbin/sendmail/src/queue.c')
| -rw-r--r-- | usr.sbin/sendmail/src/queue.c | 86 | 
1 files changed, 65 insertions, 21 deletions
diff --git a/usr.sbin/sendmail/src/queue.c b/usr.sbin/sendmail/src/queue.c index 299a0167ef9c..5d00b9f73c26 100644 --- a/usr.sbin/sendmail/src/queue.c +++ b/usr.sbin/sendmail/src/queue.c @@ -35,17 +35,17 @@  # include "sendmail.h"  #ifndef lint -#ifdef QUEUE -static char sccsid[] = "@(#)queue.c	8.131 (Berkeley) 11/8/96 (with queueing)"; +#if QUEUE +static char sccsid[] = "@(#)queue.c	8.145 (Berkeley) 12/2/96 (with queueing)";  #else -static char sccsid[] = "@(#)queue.c	8.131 (Berkeley) 11/8/96 (without queueing)"; +static char sccsid[] = "@(#)queue.c	8.145 (Berkeley) 12/2/96 (without queueing)";  #endif  #endif /* not lint */  # include <errno.h>  # include <dirent.h> -# ifdef QUEUE +# if QUEUE  /*  **  Work queue. @@ -195,7 +195,7 @@ queueup(e, announce)  	if (!bitset(EF_HAS_DF, e->e_flags))  	{ -		register FILE *dfp; +		register FILE *dfp = NULL;  		char dfname[20];  		struct stat stbuf; @@ -300,8 +300,9 @@ queueup(e, announce)  		{  #if XDEBUG  			if (bitset(QQUEUEUP, q->q_flags)) -				syslog(LOG_DEBUG, "%s: q_flags = %x", -					e->e_id, q->q_flags); +				syslog(LOG_DEBUG, +					"dropenvelope: %s: q_flags = %x, paddr = %s", +					e->e_id, q->q_flags, q->q_paddr);  #endif  			continue;  		} @@ -474,7 +475,6 @@ printctladdr(a, tfp)  {  	char *uname;  	char *paddr; -	register struct passwd *pw;  	register ADDRESS *q;  	uid_t uid;  	gid_t gid; @@ -531,9 +531,10 @@ printctladdr(a, tfp)  **		forkflag -- TRUE if the queue scanning should be done in  **			a child process.  We double-fork so it is not our  **			child and we don't have to clean up after it. +**		verbose -- if TRUE, print out status information.  **  **	Returns: -**		none. +**		TRUE if the queue run successfully began.  **  **	Side Effects:  **		runs things in the mail queue. @@ -541,15 +542,17 @@ printctladdr(a, tfp)  ENVELOPE	QueueEnvelope;		/* the queue run envelope */ -void -runqueue(forkflag) +bool +runqueue(forkflag, verbose)  	bool forkflag; +	bool verbose;  {  	register ENVELOPE *e;  	int njobs;  	int sequenceno = 0;  	extern ENVELOPE BlankEnvelope;  	extern void clrdaemon __P((void)); +	extern void runqueueevent __P((bool));  	/*  	**  If no work will ever be selected, don't even bother reading @@ -562,15 +565,15 @@ runqueue(forkflag)  	{  		char *msg = "Skipping queue run -- load average too high"; -		if (Verbose) -			printf("%s\n", msg); +		if (verbose) +			message("458 %s\n", msg);  #ifdef LOG  		if (LogLevel > 8)  			syslog(LOG_INFO, "runqueue: %s", msg);  #endif  		if (forkflag && QueueIntvl != 0) -			(void) setevent(QueueIntvl, runqueue, TRUE); -		return; +			(void) setevent(QueueIntvl, runqueueevent, TRUE); +		return FALSE;  	}  	/* @@ -584,27 +587,49 @@ runqueue(forkflag)  #ifdef SIGCHLD  		extern void reapchild(); +		blocksignal(SIGCHLD);  		(void) setsignal(SIGCHLD, reapchild);  #endif  		pid = dofork(); +		if (pid == -1) +		{ +			const char *msg = "Skipping queue run -- fork() failed"; +			const char *err = errstring(errno); + +			if (verbose) +				message("458 %s: %s\n", msg, err); +#ifdef LOG +			if (LogLevel > 8) +				syslog(LOG_INFO, "runqueue: %s: %s", msg, err); +#endif +			if (QueueIntvl != 0) +				(void) setevent(QueueIntvl, runqueueevent, TRUE); +			(void) releasesignal(SIGCHLD); +			return FALSE; +		}  		if (pid != 0)  		{  			/* parent -- pick up intermediate zombie */  #ifndef SIGCHLD  			(void) waitfor(pid);  #else +			(void) blocksignal(SIGALRM);  			proc_list_add(pid); +			(void) releasesignal(SIGALRM); +			releasesignal(SIGCHLD);  #endif /* SIGCHLD */  			if (QueueIntvl != 0) -				(void) setevent(QueueIntvl, runqueue, TRUE); -			return; +				(void) setevent(QueueIntvl, runqueueevent, TRUE); +			return TRUE;  		}  		/* child -- double fork and clean up signals */ +		proc_list_clear();  #ifndef SIGCHLD  		if (fork() != 0)  			exit(EX_OK);  #else /* SIGCHLD */ +		releasesignal(SIGCHLD);  		(void) setsignal(SIGCHLD, SIG_DFL);  #endif /* SIGCHLD */  		(void) setsignal(SIGHUP, intsig); @@ -623,7 +648,7 @@ runqueue(forkflag)  	**  Release any resources used by the daemon code.  	*/ -# ifdef DAEMON +# if DAEMON  	clrdaemon();  # endif /* DAEMON */ @@ -660,7 +685,10 @@ runqueue(forkflag)  	if (QueueLimitId != NULL || QueueLimitSender != NULL ||  	    QueueLimitRecipient != NULL) -		HostStatDir = NULL; +	{ +		IgnoreHostStatus = TRUE; +		MinQueueAge = 0; +	}  	/*  	**  Start making passes through the queue. @@ -719,6 +747,20 @@ runqueue(forkflag)  	/* exit without the usual cleanup */  	e->e_id = NULL;  	finis(); +	/*NOTREACHED*/ +	return TRUE; +} + + +/* +**  RUNQUEUEEVENT -- stub for use in setevent +*/ + +void +runqueueevent(forkflag) +	bool forkflag; +{ +	(void) runqueue(forkflag, FALSE);  }  /*  **  ORDERQ -- order the work queue. @@ -1257,7 +1299,7 @@ workcmpf3(a, b)  	if (a->w_ctime > b->w_ctime)  		return 1;  	else if (a->w_ctime < b->w_ctime) -		return 1; +		return -1;  	else  		return 0;  } @@ -1340,6 +1382,7 @@ dowork(id, forkflag, requeueflag, e)  			disconnect(1, e);  			OpMode = MD_DELIVER;  		} +		setproctitle("%s: from queue", id);  # ifdef LOG  		if (LogLevel > 76)  			syslog(LOG_DEBUG, "%s: dowork, pid=%d", e->e_id, @@ -2054,7 +2097,8 @@ queuename(e, type)  		e->e_id = newstr(&qf[2]);  		define('i', e->e_id, e);  		if (tTd(7, 1)) -			printf("queuename: assigned id %s, env=%x\n", e->e_id, e); +			printf("queuename: assigned id %s, env=%lx\n", +			       e->e_id, (u_long) e);  		if (tTd(7, 9))  		{  			printf("  lockfd=");  | 
