xref: /onnv-gate/usr/src/cmd/sendmail/src/control.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 1998-2004 Sendmail, Inc. and its suppliers.
3*0Sstevel@tonic-gate  *	All rights reserved.
4*0Sstevel@tonic-gate  *
5*0Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*0Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*0Sstevel@tonic-gate  * the sendmail distribution.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
12*0Sstevel@tonic-gate 
13*0Sstevel@tonic-gate #include <sendmail.h>
14*0Sstevel@tonic-gate 
15*0Sstevel@tonic-gate SM_RCSID("@(#)$Id: control.c,v 8.126 2004/08/04 20:54:00 ca Exp $")
16*0Sstevel@tonic-gate 
17*0Sstevel@tonic-gate #include <sm/fdset.h>
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate /* values for cmd_code */
20*0Sstevel@tonic-gate #define CMDERROR	0	/* bad command */
21*0Sstevel@tonic-gate #define CMDRESTART	1	/* restart daemon */
22*0Sstevel@tonic-gate #define CMDSHUTDOWN	2	/* end daemon */
23*0Sstevel@tonic-gate #define CMDHELP		3	/* help */
24*0Sstevel@tonic-gate #define CMDSTATUS	4	/* daemon status */
25*0Sstevel@tonic-gate #define CMDMEMDUMP	5	/* dump memory, to find memory leaks */
26*0Sstevel@tonic-gate #if _FFR_CONTROL_MSTAT
27*0Sstevel@tonic-gate # define CMDMSTAT	6	/* daemon status, more info, tagged data */
28*0Sstevel@tonic-gate #endif /* _FFR_CONTROL_MSTAT */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate struct cmd
31*0Sstevel@tonic-gate {
32*0Sstevel@tonic-gate 	char	*cmd_name;	/* command name */
33*0Sstevel@tonic-gate 	int	cmd_code;	/* internal code, see below */
34*0Sstevel@tonic-gate };
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate static struct cmd	CmdTab[] =
37*0Sstevel@tonic-gate {
38*0Sstevel@tonic-gate 	{ "help",	CMDHELP		},
39*0Sstevel@tonic-gate 	{ "restart",	CMDRESTART	},
40*0Sstevel@tonic-gate 	{ "shutdown",	CMDSHUTDOWN	},
41*0Sstevel@tonic-gate 	{ "status",	CMDSTATUS	},
42*0Sstevel@tonic-gate 	{ "memdump",	CMDMEMDUMP	},
43*0Sstevel@tonic-gate #if _FFR_CONTROL_MSTAT
44*0Sstevel@tonic-gate 	{ "mstat",	CMDMSTAT	},
45*0Sstevel@tonic-gate #endif /* _FFR_CONTROL_MSTAT */
46*0Sstevel@tonic-gate 	{ NULL,		CMDERROR	}
47*0Sstevel@tonic-gate };
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate static void	controltimeout __P((int));
52*0Sstevel@tonic-gate int ControlSocket = -1;
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate **  OPENCONTROLSOCKET -- create/open the daemon control named socket
56*0Sstevel@tonic-gate **
57*0Sstevel@tonic-gate **	Creates and opens a named socket for external control over
58*0Sstevel@tonic-gate **	the sendmail daemon.
59*0Sstevel@tonic-gate **
60*0Sstevel@tonic-gate **	Parameters:
61*0Sstevel@tonic-gate **		none.
62*0Sstevel@tonic-gate **
63*0Sstevel@tonic-gate **	Returns:
64*0Sstevel@tonic-gate **		0 if successful, -1 otherwise
65*0Sstevel@tonic-gate */
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate int
68*0Sstevel@tonic-gate opencontrolsocket()
69*0Sstevel@tonic-gate {
70*0Sstevel@tonic-gate # if NETUNIX
71*0Sstevel@tonic-gate 	int save_errno;
72*0Sstevel@tonic-gate 	int rval;
73*0Sstevel@tonic-gate 	long sff = SFF_SAFEDIRPATH|SFF_OPENASROOT|SFF_NOLINK|SFF_CREAT|SFF_MUSTOWN;
74*0Sstevel@tonic-gate 	struct sockaddr_un controladdr;
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	if (ControlSocketName == NULL || *ControlSocketName == '\0')
77*0Sstevel@tonic-gate 		return 0;
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate 	if (strlen(ControlSocketName) >= sizeof controladdr.sun_path)
80*0Sstevel@tonic-gate 	{
81*0Sstevel@tonic-gate 		errno = ENAMETOOLONG;
82*0Sstevel@tonic-gate 		return -1;
83*0Sstevel@tonic-gate 	}
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate 	rval = safefile(ControlSocketName, RunAsUid, RunAsGid, RunAsUserName,
86*0Sstevel@tonic-gate 			sff, S_IRUSR|S_IWUSR, NULL);
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 	/* if not safe, don't create */
89*0Sstevel@tonic-gate 	if (rval != 0)
90*0Sstevel@tonic-gate 	{
91*0Sstevel@tonic-gate 		errno = rval;
92*0Sstevel@tonic-gate 		return -1;
93*0Sstevel@tonic-gate 	}
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate 	ControlSocket = socket(AF_UNIX, SOCK_STREAM, 0);
96*0Sstevel@tonic-gate 	if (ControlSocket < 0)
97*0Sstevel@tonic-gate 		return -1;
98*0Sstevel@tonic-gate 	if (SM_FD_SETSIZE > 0 && ControlSocket >= SM_FD_SETSIZE)
99*0Sstevel@tonic-gate 	{
100*0Sstevel@tonic-gate 		clrcontrol();
101*0Sstevel@tonic-gate 		errno = EINVAL;
102*0Sstevel@tonic-gate 		return -1;
103*0Sstevel@tonic-gate 	}
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 	(void) unlink(ControlSocketName);
106*0Sstevel@tonic-gate 	memset(&controladdr, '\0', sizeof controladdr);
107*0Sstevel@tonic-gate 	controladdr.sun_family = AF_UNIX;
108*0Sstevel@tonic-gate 	(void) sm_strlcpy(controladdr.sun_path, ControlSocketName,
109*0Sstevel@tonic-gate 			  sizeof controladdr.sun_path);
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 	if (bind(ControlSocket, (struct sockaddr *) &controladdr,
112*0Sstevel@tonic-gate 		 sizeof controladdr) < 0)
113*0Sstevel@tonic-gate 	{
114*0Sstevel@tonic-gate 		save_errno = errno;
115*0Sstevel@tonic-gate 		clrcontrol();
116*0Sstevel@tonic-gate 		errno = save_errno;
117*0Sstevel@tonic-gate 		return -1;
118*0Sstevel@tonic-gate 	}
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 	if (geteuid() == 0)
121*0Sstevel@tonic-gate 	{
122*0Sstevel@tonic-gate 		uid_t u = 0;
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate 		if (RunAsUid != 0)
125*0Sstevel@tonic-gate 			u = RunAsUid;
126*0Sstevel@tonic-gate 		else if (TrustedUid != 0)
127*0Sstevel@tonic-gate 			u = TrustedUid;
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 		if (u != 0 &&
130*0Sstevel@tonic-gate 		    chown(ControlSocketName, u, -1) < 0)
131*0Sstevel@tonic-gate 		{
132*0Sstevel@tonic-gate 			save_errno = errno;
133*0Sstevel@tonic-gate 			sm_syslog(LOG_ALERT, NOQID,
134*0Sstevel@tonic-gate 				  "ownership change on %s to uid %d failed: %s",
135*0Sstevel@tonic-gate 				  ControlSocketName, (int) u,
136*0Sstevel@tonic-gate 				  sm_errstring(save_errno));
137*0Sstevel@tonic-gate 			message("050 ownership change on %s to uid %d failed: %s",
138*0Sstevel@tonic-gate 				ControlSocketName, (int) u,
139*0Sstevel@tonic-gate 				sm_errstring(save_errno));
140*0Sstevel@tonic-gate 			closecontrolsocket(true);
141*0Sstevel@tonic-gate 			errno = save_errno;
142*0Sstevel@tonic-gate 			return -1;
143*0Sstevel@tonic-gate 		}
144*0Sstevel@tonic-gate 	}
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate 	if (chmod(ControlSocketName, S_IRUSR|S_IWUSR) < 0)
147*0Sstevel@tonic-gate 	{
148*0Sstevel@tonic-gate 		save_errno = errno;
149*0Sstevel@tonic-gate 		closecontrolsocket(true);
150*0Sstevel@tonic-gate 		errno = save_errno;
151*0Sstevel@tonic-gate 		return -1;
152*0Sstevel@tonic-gate 	}
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 	if (listen(ControlSocket, 8) < 0)
155*0Sstevel@tonic-gate 	{
156*0Sstevel@tonic-gate 		save_errno = errno;
157*0Sstevel@tonic-gate 		closecontrolsocket(true);
158*0Sstevel@tonic-gate 		errno = save_errno;
159*0Sstevel@tonic-gate 		return -1;
160*0Sstevel@tonic-gate 	}
161*0Sstevel@tonic-gate # endif /* NETUNIX */
162*0Sstevel@tonic-gate 	return 0;
163*0Sstevel@tonic-gate }
164*0Sstevel@tonic-gate /*
165*0Sstevel@tonic-gate **  CLOSECONTROLSOCKET -- close the daemon control named socket
166*0Sstevel@tonic-gate **
167*0Sstevel@tonic-gate **	Close a named socket.
168*0Sstevel@tonic-gate **
169*0Sstevel@tonic-gate **	Parameters:
170*0Sstevel@tonic-gate **		fullclose -- if set, close the socket and remove it;
171*0Sstevel@tonic-gate **			     otherwise, just remove it
172*0Sstevel@tonic-gate **
173*0Sstevel@tonic-gate **	Returns:
174*0Sstevel@tonic-gate **		none.
175*0Sstevel@tonic-gate */
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate void
178*0Sstevel@tonic-gate closecontrolsocket(fullclose)
179*0Sstevel@tonic-gate 	bool fullclose;
180*0Sstevel@tonic-gate {
181*0Sstevel@tonic-gate # if NETUNIX
182*0Sstevel@tonic-gate 	long sff = SFF_SAFEDIRPATH|SFF_OPENASROOT|SFF_NOLINK|SFF_CREAT|SFF_MUSTOWN;
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate 	if (ControlSocket >= 0)
185*0Sstevel@tonic-gate 	{
186*0Sstevel@tonic-gate 		int rval;
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 		if (fullclose)
189*0Sstevel@tonic-gate 		{
190*0Sstevel@tonic-gate 			(void) close(ControlSocket);
191*0Sstevel@tonic-gate 			ControlSocket = -1;
192*0Sstevel@tonic-gate 		}
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 		rval = safefile(ControlSocketName, RunAsUid, RunAsGid,
195*0Sstevel@tonic-gate 				RunAsUserName, sff, S_IRUSR|S_IWUSR, NULL);
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 		/* if not safe, don't unlink */
198*0Sstevel@tonic-gate 		if (rval != 0)
199*0Sstevel@tonic-gate 			return;
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate 		if (unlink(ControlSocketName) < 0)
202*0Sstevel@tonic-gate 		{
203*0Sstevel@tonic-gate 			sm_syslog(LOG_WARNING, NOQID,
204*0Sstevel@tonic-gate 				  "Could not remove control socket: %s",
205*0Sstevel@tonic-gate 				  sm_errstring(errno));
206*0Sstevel@tonic-gate 			return;
207*0Sstevel@tonic-gate 		}
208*0Sstevel@tonic-gate 	}
209*0Sstevel@tonic-gate # endif /* NETUNIX */
210*0Sstevel@tonic-gate 	return;
211*0Sstevel@tonic-gate }
212*0Sstevel@tonic-gate /*
213*0Sstevel@tonic-gate **  CLRCONTROL -- reset the control connection
214*0Sstevel@tonic-gate **
215*0Sstevel@tonic-gate **	Parameters:
216*0Sstevel@tonic-gate **		none.
217*0Sstevel@tonic-gate **
218*0Sstevel@tonic-gate **	Returns:
219*0Sstevel@tonic-gate **		none.
220*0Sstevel@tonic-gate **
221*0Sstevel@tonic-gate **	Side Effects:
222*0Sstevel@tonic-gate **		releases any resources used by the control interface.
223*0Sstevel@tonic-gate */
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate void
226*0Sstevel@tonic-gate clrcontrol()
227*0Sstevel@tonic-gate {
228*0Sstevel@tonic-gate # if NETUNIX
229*0Sstevel@tonic-gate 	if (ControlSocket >= 0)
230*0Sstevel@tonic-gate 		(void) close(ControlSocket);
231*0Sstevel@tonic-gate 	ControlSocket = -1;
232*0Sstevel@tonic-gate # endif /* NETUNIX */
233*0Sstevel@tonic-gate }
234*0Sstevel@tonic-gate /*
235*0Sstevel@tonic-gate **  CONTROL_COMMAND -- read and process command from named socket
236*0Sstevel@tonic-gate **
237*0Sstevel@tonic-gate **	Read and process the command from the opened socket.
238*0Sstevel@tonic-gate **	Exits when done since it is running in a forked child.
239*0Sstevel@tonic-gate **
240*0Sstevel@tonic-gate **	Parameters:
241*0Sstevel@tonic-gate **		sock -- the opened socket from getrequests()
242*0Sstevel@tonic-gate **		e -- the current envelope
243*0Sstevel@tonic-gate **
244*0Sstevel@tonic-gate **	Returns:
245*0Sstevel@tonic-gate **		none.
246*0Sstevel@tonic-gate */
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate static jmp_buf	CtxControlTimeout;
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate /* ARGSUSED0 */
251*0Sstevel@tonic-gate static void
252*0Sstevel@tonic-gate controltimeout(timeout)
253*0Sstevel@tonic-gate 	int timeout;
254*0Sstevel@tonic-gate {
255*0Sstevel@tonic-gate 	/*
256*0Sstevel@tonic-gate 	**  NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER.  DO NOT ADD
257*0Sstevel@tonic-gate 	**	ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
258*0Sstevel@tonic-gate 	**	DOING.
259*0Sstevel@tonic-gate 	*/
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate 	errno = ETIMEDOUT;
262*0Sstevel@tonic-gate 	longjmp(CtxControlTimeout, 1);
263*0Sstevel@tonic-gate }
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate void
266*0Sstevel@tonic-gate control_command(sock, e)
267*0Sstevel@tonic-gate 	int sock;
268*0Sstevel@tonic-gate 	ENVELOPE *e;
269*0Sstevel@tonic-gate {
270*0Sstevel@tonic-gate 	volatile int exitstat = EX_OK;
271*0Sstevel@tonic-gate 	SM_FILE_T *s = NULL;
272*0Sstevel@tonic-gate 	SM_EVENT *ev = NULL;
273*0Sstevel@tonic-gate 	SM_FILE_T *traffic;
274*0Sstevel@tonic-gate 	SM_FILE_T *oldout;
275*0Sstevel@tonic-gate 	char *cmd;
276*0Sstevel@tonic-gate 	char *p;
277*0Sstevel@tonic-gate 	struct cmd *c;
278*0Sstevel@tonic-gate 	char cmdbuf[MAXLINE];
279*0Sstevel@tonic-gate 	char inp[MAXLINE];
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate 	sm_setproctitle(false, e, "control cmd read");
282*0Sstevel@tonic-gate 
283*0Sstevel@tonic-gate 	if (TimeOuts.to_control > 0)
284*0Sstevel@tonic-gate 	{
285*0Sstevel@tonic-gate 		/* handle possible input timeout */
286*0Sstevel@tonic-gate 		if (setjmp(CtxControlTimeout) != 0)
287*0Sstevel@tonic-gate 		{
288*0Sstevel@tonic-gate 			if (LogLevel > 2)
289*0Sstevel@tonic-gate 				sm_syslog(LOG_NOTICE, e->e_id,
290*0Sstevel@tonic-gate 					  "timeout waiting for input during control command");
291*0Sstevel@tonic-gate 			exit(EX_IOERR);
292*0Sstevel@tonic-gate 		}
293*0Sstevel@tonic-gate 		ev = sm_setevent(TimeOuts.to_control, controltimeout,
294*0Sstevel@tonic-gate 				 TimeOuts.to_control);
295*0Sstevel@tonic-gate 	}
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	s = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT, (void *) &sock,
298*0Sstevel@tonic-gate 		       SM_IO_RDWR, NULL);
299*0Sstevel@tonic-gate 	if (s == NULL)
300*0Sstevel@tonic-gate 	{
301*0Sstevel@tonic-gate 		int save_errno = errno;
302*0Sstevel@tonic-gate 
303*0Sstevel@tonic-gate 		(void) close(sock);
304*0Sstevel@tonic-gate 		errno = save_errno;
305*0Sstevel@tonic-gate 		exit(EX_IOERR);
306*0Sstevel@tonic-gate 	}
307*0Sstevel@tonic-gate 	(void) sm_io_setvbuf(s, SM_TIME_DEFAULT, NULL,
308*0Sstevel@tonic-gate 			     SM_IO_NBF, SM_IO_BUFSIZ);
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate 	if (sm_io_fgets(s, SM_TIME_DEFAULT, inp, sizeof inp) == NULL)
311*0Sstevel@tonic-gate 	{
312*0Sstevel@tonic-gate 		(void) sm_io_close(s, SM_TIME_DEFAULT);
313*0Sstevel@tonic-gate 		exit(EX_IOERR);
314*0Sstevel@tonic-gate 	}
315*0Sstevel@tonic-gate 	(void) sm_io_flush(s, SM_TIME_DEFAULT);
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 	/* clean up end of line */
318*0Sstevel@tonic-gate 	fixcrlf(inp, true);
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 	sm_setproctitle(false, e, "control: %s", inp);
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate 	/* break off command */
323*0Sstevel@tonic-gate 	for (p = inp; isascii(*p) && isspace(*p); p++)
324*0Sstevel@tonic-gate 		continue;
325*0Sstevel@tonic-gate 	cmd = cmdbuf;
326*0Sstevel@tonic-gate 	while (*p != '\0' &&
327*0Sstevel@tonic-gate 	       !(isascii(*p) && isspace(*p)) &&
328*0Sstevel@tonic-gate 	       cmd < &cmdbuf[sizeof cmdbuf - 2])
329*0Sstevel@tonic-gate 		*cmd++ = *p++;
330*0Sstevel@tonic-gate 	*cmd = '\0';
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	/* throw away leading whitespace */
333*0Sstevel@tonic-gate 	while (isascii(*p) && isspace(*p))
334*0Sstevel@tonic-gate 		p++;
335*0Sstevel@tonic-gate 
336*0Sstevel@tonic-gate 	/* decode command */
337*0Sstevel@tonic-gate 	for (c = CmdTab; c->cmd_name != NULL; c++)
338*0Sstevel@tonic-gate 	{
339*0Sstevel@tonic-gate 		if (sm_strcasecmp(c->cmd_name, cmdbuf) == 0)
340*0Sstevel@tonic-gate 			break;
341*0Sstevel@tonic-gate 	}
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate 	switch (c->cmd_code)
344*0Sstevel@tonic-gate 	{
345*0Sstevel@tonic-gate 	  case CMDHELP:		/* get help */
346*0Sstevel@tonic-gate 		traffic = TrafficLogFile;
347*0Sstevel@tonic-gate 		TrafficLogFile = NULL;
348*0Sstevel@tonic-gate 		oldout = OutChannel;
349*0Sstevel@tonic-gate 		OutChannel = s;
350*0Sstevel@tonic-gate 		help("control", e);
351*0Sstevel@tonic-gate 		TrafficLogFile = traffic;
352*0Sstevel@tonic-gate 		OutChannel = oldout;
353*0Sstevel@tonic-gate 		break;
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 	  case CMDRESTART:	/* restart the daemon */
356*0Sstevel@tonic-gate 		(void) sm_io_fprintf(s, SM_TIME_DEFAULT, "OK\r\n");
357*0Sstevel@tonic-gate 		exitstat = EX_RESTART;
358*0Sstevel@tonic-gate 		break;
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate 	  case CMDSHUTDOWN:	/* kill the daemon */
361*0Sstevel@tonic-gate 		(void) sm_io_fprintf(s, SM_TIME_DEFAULT, "OK\r\n");
362*0Sstevel@tonic-gate 		exitstat = EX_SHUTDOWN;
363*0Sstevel@tonic-gate 		break;
364*0Sstevel@tonic-gate 
365*0Sstevel@tonic-gate 	  case CMDSTATUS:	/* daemon status */
366*0Sstevel@tonic-gate 		proc_list_probe();
367*0Sstevel@tonic-gate 		{
368*0Sstevel@tonic-gate 			int qgrp;
369*0Sstevel@tonic-gate 			long bsize;
370*0Sstevel@tonic-gate 			long free;
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate 			/* XXX need to deal with different partitions */
373*0Sstevel@tonic-gate 			qgrp = e->e_qgrp;
374*0Sstevel@tonic-gate 			if (!ISVALIDQGRP(qgrp))
375*0Sstevel@tonic-gate 				qgrp = 0;
376*0Sstevel@tonic-gate 			free = freediskspace(Queue[qgrp]->qg_qdir, &bsize);
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate 			/*
379*0Sstevel@tonic-gate 			**  Prevent overflow and don't lose
380*0Sstevel@tonic-gate 			**  precision (if bsize == 512)
381*0Sstevel@tonic-gate 			*/
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate 			if (free > 0)
384*0Sstevel@tonic-gate 				free = (long)((double) free *
385*0Sstevel@tonic-gate 					      ((double) bsize / 1024));
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate 			(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
388*0Sstevel@tonic-gate 					     "%d/%d/%ld/%d\r\n",
389*0Sstevel@tonic-gate 					     CurChildren, MaxChildren,
390*0Sstevel@tonic-gate 					     free, getla());
391*0Sstevel@tonic-gate 		}
392*0Sstevel@tonic-gate 		proc_list_display(s, "");
393*0Sstevel@tonic-gate 		break;
394*0Sstevel@tonic-gate 
395*0Sstevel@tonic-gate # if _FFR_CONTROL_MSTAT
396*0Sstevel@tonic-gate 	  case CMDMSTAT:	/* daemon status, extended, tagged format */
397*0Sstevel@tonic-gate 		proc_list_probe();
398*0Sstevel@tonic-gate 		(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
399*0Sstevel@tonic-gate 				     "C:%d\r\nM:%d\r\nL:%d\r\n",
400*0Sstevel@tonic-gate 				     CurChildren, MaxChildren,
401*0Sstevel@tonic-gate 				     getla());
402*0Sstevel@tonic-gate 		printnqe(s, "Q:");
403*0Sstevel@tonic-gate 		disk_status(s, "D:");
404*0Sstevel@tonic-gate 		proc_list_display(s, "P:");
405*0Sstevel@tonic-gate 		break;
406*0Sstevel@tonic-gate # endif /* _FFR_CONTROL_MSTAT */
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate 	  case CMDMEMDUMP:	/* daemon memory dump, to find memory leaks */
409*0Sstevel@tonic-gate # if SM_HEAP_CHECK
410*0Sstevel@tonic-gate 		/* dump the heap, if we are checking for memory leaks */
411*0Sstevel@tonic-gate 		if (sm_debug_active(&SmHeapCheck, 2))
412*0Sstevel@tonic-gate 		{
413*0Sstevel@tonic-gate 			sm_heap_report(s, sm_debug_level(&SmHeapCheck) - 1);
414*0Sstevel@tonic-gate 		}
415*0Sstevel@tonic-gate 		else
416*0Sstevel@tonic-gate 		{
417*0Sstevel@tonic-gate 			(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
418*0Sstevel@tonic-gate 					     "Memory dump unavailable.\r\n");
419*0Sstevel@tonic-gate 			(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
420*0Sstevel@tonic-gate 					     "To fix, run sendmail with -dsm_check_heap.4\r\n");
421*0Sstevel@tonic-gate 		}
422*0Sstevel@tonic-gate # else /* SM_HEAP_CHECK */
423*0Sstevel@tonic-gate 		(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
424*0Sstevel@tonic-gate 				     "Memory dump unavailable.\r\n");
425*0Sstevel@tonic-gate 		(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
426*0Sstevel@tonic-gate 				     "To fix, rebuild with -DSM_HEAP_CHECK\r\n");
427*0Sstevel@tonic-gate # endif /* SM_HEAP_CHECK */
428*0Sstevel@tonic-gate 		break;
429*0Sstevel@tonic-gate 
430*0Sstevel@tonic-gate 	  case CMDERROR:	/* unknown command */
431*0Sstevel@tonic-gate 		(void) sm_io_fprintf(s, SM_TIME_DEFAULT,
432*0Sstevel@tonic-gate 				     "Bad command (%s)\r\n", cmdbuf);
433*0Sstevel@tonic-gate 		break;
434*0Sstevel@tonic-gate 	}
435*0Sstevel@tonic-gate 	(void) sm_io_close(s, SM_TIME_DEFAULT);
436*0Sstevel@tonic-gate 	if (ev != NULL)
437*0Sstevel@tonic-gate 		sm_clrevent(ev);
438*0Sstevel@tonic-gate 	exit(exitstat);
439*0Sstevel@tonic-gate }
440