1 # include "sendmail.h"
2 
3 static char	SccsId[] =	"@(#)daemon.c	3.4	11/08/81";
4 
5 /*
6 **  DAEMON.C -- routines to use when running as a daemon.
7 */
8 /*
9 **  GETREQUESTS -- open mail IPC port and get requests.
10 **
11 **	Parameters:
12 **		none.
13 **
14 **	Returns:
15 **		none.
16 **
17 **	Side Effects:
18 **		Waits until some interesting activity occurs.  When
19 **		it does, a child is created to process it, and the
20 **		parent waits for completion.  Return from this
21 **		routine is always in the child.
22 */
23 
24 getrequests()
25 {
26 	syserr("Daemon mode not yet implemented");
27 	exit(EX_USAGE);
28 
29 	for (;;)
30 	{
31 		register int pid;
32 		auto int st;
33 
34 		/*
35 		**  Wait for a connection.
36 		*/
37 
38 		/* MailPort = getconnection(); */
39 
40 		pid = fork();
41 		if (pid < 0)
42 		{
43 			syserr("daemon: cannot fork");
44 			sleep(10);
45 			continue;
46 		}
47 
48 		if (pid == 0)
49 		{
50 			/*
51 			**  CHILD -- return to caller.
52 			**	Verify calling user id if possible here.
53 			*/
54 
55 			initsys();
56 			return;
57 		}
58 
59 		/*
60 		**  PARENT -- wait for child to terminate.
61 		**	Perhaps we should allow concurrent processing?
62 		*/
63 
64 		(void) wait(&st);
65 	}
66 }
67