xref: /freebsd/libexec/rbootd/rbootd.c (revision 0b8224d1cc9dc6c9778ba04a75b2c8d47e5d7481)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
4ea022d16SRodney W. Grimes  * Copyright (c) 1988, 1992 The University of Utah and the Center
5ea022d16SRodney W. Grimes  *	for Software Science (CSS).
6ea022d16SRodney W. Grimes  * Copyright (c) 1992, 1993
7ea022d16SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
8ea022d16SRodney W. Grimes  *
9ea022d16SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
10ea022d16SRodney W. Grimes  * the Center for Software Science of the University of Utah Computer
11ea022d16SRodney W. Grimes  * Science Department.  CSS requests users of this software to return
12ea022d16SRodney W. Grimes  * to css-dist@cs.utah.edu any improvements that they make and grant
13ea022d16SRodney W. Grimes  * CSS redistribution rights.
14ea022d16SRodney W. Grimes  *
15ea022d16SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
16ea022d16SRodney W. Grimes  * modification, are permitted provided that the following conditions
17ea022d16SRodney W. Grimes  * are met:
18ea022d16SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
19ea022d16SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
20ea022d16SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
21ea022d16SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
22ea022d16SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
235efaea4cSChristian Brueffer  * 3. Neither the name of the University nor the names of its contributors
24ea022d16SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
25ea022d16SRodney W. Grimes  *    without specific prior written permission.
26ea022d16SRodney W. Grimes  *
27ea022d16SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28ea022d16SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29ea022d16SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30ea022d16SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31ea022d16SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32ea022d16SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33ea022d16SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34ea022d16SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35ea022d16SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36ea022d16SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37ea022d16SRodney W. Grimes  * SUCH DAMAGE.
38ea022d16SRodney W. Grimes  *
395c8709fdSSteve Price  * From: Utah Hdr: rbootd.c 3.1 92/07/06
40ea022d16SRodney W. Grimes  * Author: Jeff Forys, University of Utah CSS
41ea022d16SRodney W. Grimes  */
42ea022d16SRodney W. Grimes 
43ea022d16SRodney W. Grimes #include <sys/param.h>
44ea022d16SRodney W. Grimes #include <sys/time.h>
45ea022d16SRodney W. Grimes #include <ctype.h>
465c8709fdSSteve Price #include <err.h>
47ea022d16SRodney W. Grimes #include <errno.h>
48ea022d16SRodney W. Grimes #include <fcntl.h>
49ea022d16SRodney W. Grimes #include <signal.h>
50ea022d16SRodney W. Grimes #include <stdio.h>
51ea022d16SRodney W. Grimes #include <stdlib.h>
52ea022d16SRodney W. Grimes #include <string.h>
53ea022d16SRodney W. Grimes #include <syslog.h>
54ea022d16SRodney W. Grimes #include <unistd.h>
55ea022d16SRodney W. Grimes #include "defs.h"
56ea022d16SRodney W. Grimes 
57*69c0fb2aSAlfonso Gregory static void usage(void) __dead2;
58ea022d16SRodney W. Grimes 
59ea022d16SRodney W. Grimes int
main(int argc,char * argv[])60266ebcd3SWarner Losh main(int argc, char *argv[])
61ea022d16SRodney W. Grimes {
62ea022d16SRodney W. Grimes 	int c, fd, omask, maxfds;
63ea022d16SRodney W. Grimes 	fd_set rset;
64ea022d16SRodney W. Grimes 
65ea022d16SRodney W. Grimes 	/*
66ea022d16SRodney W. Grimes 	 *  Close any open file descriptors.
67ea022d16SRodney W. Grimes 	 *  Temporarily leave stdin & stdout open for `-d',
68ea022d16SRodney W. Grimes 	 *  and stderr open for any pre-syslog error messages.
69ea022d16SRodney W. Grimes 	 */
70ea022d16SRodney W. Grimes 	{
71ea022d16SRodney W. Grimes 		int i, nfds = getdtablesize();
72ea022d16SRodney W. Grimes 
73ea022d16SRodney W. Grimes 		for (i = 0; i < nfds; i++)
74ea022d16SRodney W. Grimes 			if (i != fileno(stdin) && i != fileno(stdout) &&
75ea022d16SRodney W. Grimes 			    i != fileno(stderr))
76ea022d16SRodney W. Grimes 				(void) close(i);
77ea022d16SRodney W. Grimes 	}
78ea022d16SRodney W. Grimes 
79ea022d16SRodney W. Grimes 	/*
80ea022d16SRodney W. Grimes 	 *  Parse any arguments.
81ea022d16SRodney W. Grimes 	 */
8291477cc4SWarner Losh 	while ((c = getopt(argc, argv, "adi:")) != -1)
83ea022d16SRodney W. Grimes 		switch(c) {
84ea022d16SRodney W. Grimes 		    case 'a':
85ea022d16SRodney W. Grimes 			BootAny++;
86ea022d16SRodney W. Grimes 			break;
87ea022d16SRodney W. Grimes 		    case 'd':
88ea022d16SRodney W. Grimes 			DebugFlg++;
89ea022d16SRodney W. Grimes 			break;
90ea022d16SRodney W. Grimes 		    case 'i':
91ea022d16SRodney W. Grimes 			IntfName = optarg;
92ea022d16SRodney W. Grimes 			break;
93eb0b8290SPhilippe Charnier 		    default:
94eb0b8290SPhilippe Charnier 			usage();
95ea022d16SRodney W. Grimes 		}
96ea022d16SRodney W. Grimes 	for (; optind < argc; optind++) {
97ea022d16SRodney W. Grimes 		if (ConfigFile == NULL)
98ea022d16SRodney W. Grimes 			ConfigFile = argv[optind];
99ea022d16SRodney W. Grimes 		else {
100eb0b8290SPhilippe Charnier 			warnx("too many config files (`%s' ignored)",
1015c8709fdSSteve Price 			    argv[optind]);
102ea022d16SRodney W. Grimes 		}
103ea022d16SRodney W. Grimes 	}
104ea022d16SRodney W. Grimes 
105ea022d16SRodney W. Grimes 	if (ConfigFile == NULL)			/* use default config file */
106ea022d16SRodney W. Grimes 		ConfigFile = DfltConfig;
107ea022d16SRodney W. Grimes 
108ea022d16SRodney W. Grimes 	if (DebugFlg) {
109ea022d16SRodney W. Grimes 		DbgFp = stdout;				/* output to stdout */
110ea022d16SRodney W. Grimes 
111ea022d16SRodney W. Grimes 		(void) signal(SIGUSR1, SIG_IGN);	/* dont muck w/DbgFp */
112ea022d16SRodney W. Grimes 		(void) signal(SIGUSR2, SIG_IGN);
1135c8709fdSSteve Price 		(void) fclose(stderr);			/* finished with it */
114ea022d16SRodney W. Grimes 	} else {
1155c8709fdSSteve Price 		if (daemon(0, 0))
1165c8709fdSSteve Price 			err(1, "can't detach from terminal");
117ea022d16SRodney W. Grimes 
118ea022d16SRodney W. Grimes 		(void) signal(SIGUSR1, DebugOn);
119ea022d16SRodney W. Grimes 		(void) signal(SIGUSR2, DebugOff);
120ea022d16SRodney W. Grimes 	}
121ea022d16SRodney W. Grimes 
122eb0b8290SPhilippe Charnier 	openlog("rbootd", LOG_PID, LOG_DAEMON);
123ea022d16SRodney W. Grimes 
124ea022d16SRodney W. Grimes 	/*
125ea022d16SRodney W. Grimes 	 *  If no interface was specified, get one now.
126ea022d16SRodney W. Grimes 	 *
127ea022d16SRodney W. Grimes 	 *  This is convoluted because we want to get the default interface
128ea022d16SRodney W. Grimes 	 *  name for the syslog("restarted") message.  If BpfGetIntfName()
129ea022d16SRodney W. Grimes 	 *  runs into an error, it will return a syslog-able error message
130ea022d16SRodney W. Grimes 	 *  (in `errmsg') which will be displayed here.
131ea022d16SRodney W. Grimes 	 */
132ea022d16SRodney W. Grimes 	if (IntfName == NULL) {
133ea022d16SRodney W. Grimes 		char *errmsg;
134ea022d16SRodney W. Grimes 
135ea022d16SRodney W. Grimes 		if ((IntfName = BpfGetIntfName(&errmsg)) == NULL) {
1369f09e3bbSMaxim Konovalov 			/* Backslash to avoid trigraph '??)'. */
1379f09e3bbSMaxim Konovalov 			syslog(LOG_NOTICE, "restarted (?\?)");
138b601f693SKris Kennaway 			/* BpfGetIntfName() returns safe names, using %m */
139b601f693SKris Kennaway 			syslog(LOG_ERR, "%s", errmsg);
140ea022d16SRodney W. Grimes 			Exit(0);
141ea022d16SRodney W. Grimes 		}
142ea022d16SRodney W. Grimes 	}
143ea022d16SRodney W. Grimes 
144ea022d16SRodney W. Grimes 	syslog(LOG_NOTICE, "restarted (%s)", IntfName);
145ea022d16SRodney W. Grimes 
146ea022d16SRodney W. Grimes 	(void) signal(SIGHUP, ReConfig);
147ea022d16SRodney W. Grimes 	(void) signal(SIGINT, Exit);
148ea022d16SRodney W. Grimes 	(void) signal(SIGTERM, Exit);
149ea022d16SRodney W. Grimes 
150ea022d16SRodney W. Grimes 	/*
151ea022d16SRodney W. Grimes 	 *  Grab our host name and pid.
152ea022d16SRodney W. Grimes 	 */
1539e9a43bdSBrian Somers 	if (gethostname(MyHost, MAXHOSTNAMELEN - 1) < 0) {
154ea022d16SRodney W. Grimes 		syslog(LOG_ERR, "gethostname: %m");
155ea022d16SRodney W. Grimes 		Exit(0);
156ea022d16SRodney W. Grimes 	}
1579e9a43bdSBrian Somers 	MyHost[MAXHOSTNAMELEN - 1] = '\0';
158ea022d16SRodney W. Grimes 
159ea022d16SRodney W. Grimes 	MyPid = getpid();
160ea022d16SRodney W. Grimes 
161ea022d16SRodney W. Grimes 	/*
162ea022d16SRodney W. Grimes 	 *  Write proc's pid to a file.
163ea022d16SRodney W. Grimes 	 */
164ea022d16SRodney W. Grimes 	{
165ea022d16SRodney W. Grimes 		FILE *fp;
166ea022d16SRodney W. Grimes 
167ea022d16SRodney W. Grimes 		if ((fp = fopen(PidFile, "w")) != NULL) {
1685c8709fdSSteve Price 			(void) fprintf(fp, "%d\n", (int) MyPid);
169ea022d16SRodney W. Grimes 			(void) fclose(fp);
170ea022d16SRodney W. Grimes 		} else {
171ea022d16SRodney W. Grimes 			syslog(LOG_WARNING, "fopen: failed (%s)", PidFile);
172ea022d16SRodney W. Grimes 		}
173ea022d16SRodney W. Grimes 	}
174ea022d16SRodney W. Grimes 
175ea022d16SRodney W. Grimes 	/*
176ea022d16SRodney W. Grimes 	 *  All boot files are relative to the boot directory, we might
177ea022d16SRodney W. Grimes 	 *  as well chdir() there to make life easier.
178ea022d16SRodney W. Grimes 	 */
179ea022d16SRodney W. Grimes 	if (chdir(BootDir) < 0) {
180ea022d16SRodney W. Grimes 		syslog(LOG_ERR, "chdir: %m (%s)", BootDir);
181ea022d16SRodney W. Grimes 		Exit(0);
182ea022d16SRodney W. Grimes 	}
183ea022d16SRodney W. Grimes 
184ea022d16SRodney W. Grimes 	/*
185ea022d16SRodney W. Grimes 	 *  Initial configuration.
186ea022d16SRodney W. Grimes 	 */
187ea022d16SRodney W. Grimes 	omask = sigblock(sigmask(SIGHUP));	/* prevent reconfig's */
188ea022d16SRodney W. Grimes 	if (GetBootFiles() == 0)		/* get list of boot files */
189ea022d16SRodney W. Grimes 		Exit(0);
190ea022d16SRodney W. Grimes 	if (ParseConfig() == 0)			/* parse config file */
191ea022d16SRodney W. Grimes 		Exit(0);
192ea022d16SRodney W. Grimes 
193ea022d16SRodney W. Grimes 	/*
194ea022d16SRodney W. Grimes 	 *  Open and initialize a BPF device for the appropriate interface.
195ea022d16SRodney W. Grimes 	 *  If an error is encountered, a message is displayed and Exit()
196ea022d16SRodney W. Grimes 	 *  is called.
197ea022d16SRodney W. Grimes 	 */
198ea022d16SRodney W. Grimes 	fd = BpfOpen();
199ea022d16SRodney W. Grimes 
200ea022d16SRodney W. Grimes 	(void) sigsetmask(omask);		/* allow reconfig's */
201ea022d16SRodney W. Grimes 
202ea022d16SRodney W. Grimes 	/*
203ea022d16SRodney W. Grimes 	 *  Main loop: receive a packet, determine where it came from,
204ea022d16SRodney W. Grimes 	 *  and if we service this host, call routine to handle request.
205ea022d16SRodney W. Grimes 	 */
206ea022d16SRodney W. Grimes 	maxfds = fd + 1;
207ea022d16SRodney W. Grimes 	FD_ZERO(&rset);
208ea022d16SRodney W. Grimes 	FD_SET(fd, &rset);
209ea022d16SRodney W. Grimes 	for (;;) {
210ea022d16SRodney W. Grimes 		struct timeval timeout;
211ea022d16SRodney W. Grimes 		fd_set r;
212ea022d16SRodney W. Grimes 		int nsel;
213ea022d16SRodney W. Grimes 
214ea022d16SRodney W. Grimes 		r = rset;
215ea022d16SRodney W. Grimes 
2161acf0dbaSUlrich Spörlein 		if (RmpConns == NULL) {		/* timeout isn't necessary */
2175c8709fdSSteve Price 			nsel = select(maxfds, &r, NULL, NULL, NULL);
218ea022d16SRodney W. Grimes 		} else {
219ea022d16SRodney W. Grimes 			timeout.tv_sec = RMP_TIMEOUT;
220ea022d16SRodney W. Grimes 			timeout.tv_usec = 0;
2215c8709fdSSteve Price 			nsel = select(maxfds, &r, NULL, NULL, &timeout);
222ea022d16SRodney W. Grimes 		}
223ea022d16SRodney W. Grimes 
224ea022d16SRodney W. Grimes 		if (nsel < 0) {
225ea022d16SRodney W. Grimes 			if (errno == EINTR)
226ea022d16SRodney W. Grimes 				continue;
227ea022d16SRodney W. Grimes 			syslog(LOG_ERR, "select: %m");
228ea022d16SRodney W. Grimes 			Exit(0);
229ea022d16SRodney W. Grimes 		} else if (nsel == 0) {		/* timeout */
230ea022d16SRodney W. Grimes 			DoTimeout();			/* clear stale conns */
231ea022d16SRodney W. Grimes 			continue;
232ea022d16SRodney W. Grimes 		}
233ea022d16SRodney W. Grimes 
234ea022d16SRodney W. Grimes 		if (FD_ISSET(fd, &r)) {
235ea022d16SRodney W. Grimes 			RMPCONN rconn;
236eae7dd0fSJohn Baldwin 			CLIENT *client;
237ea022d16SRodney W. Grimes 			int doread = 1;
238ea022d16SRodney W. Grimes 
239ea022d16SRodney W. Grimes 			while (BpfRead(&rconn, doread)) {
240ea022d16SRodney W. Grimes 				doread = 0;
241ea022d16SRodney W. Grimes 
242ea022d16SRodney W. Grimes 				if (DbgFp != NULL)	/* display packet */
243ea022d16SRodney W. Grimes 					DispPkt(&rconn,DIR_RCVD);
244ea022d16SRodney W. Grimes 
245ea022d16SRodney W. Grimes 				omask = sigblock(sigmask(SIGHUP));
246ea022d16SRodney W. Grimes 
247ea022d16SRodney W. Grimes 				/*
248ea022d16SRodney W. Grimes 				 *  If we do not restrict service, set the
249ea022d16SRodney W. Grimes 				 *  client to NULL (ProcessPacket() handles
250ea022d16SRodney W. Grimes 				 *  this).  Otherwise, check that we can
251ea022d16SRodney W. Grimes 				 *  service this host; if not, log a message
252ea022d16SRodney W. Grimes 				 *  and ignore the packet.
253ea022d16SRodney W. Grimes 				 */
254ea022d16SRodney W. Grimes 				if (BootAny) {
255ea022d16SRodney W. Grimes 					client = NULL;
256ea022d16SRodney W. Grimes 				} else if ((client=FindClient(&rconn))==NULL) {
257ea022d16SRodney W. Grimes 					syslog(LOG_INFO,
258ea022d16SRodney W. Grimes 					       "%s: boot packet ignored",
259ea022d16SRodney W. Grimes 					       EnetStr(&rconn));
260ea022d16SRodney W. Grimes 					(void) sigsetmask(omask);
261ea022d16SRodney W. Grimes 					continue;
262ea022d16SRodney W. Grimes 				}
263ea022d16SRodney W. Grimes 
264ea022d16SRodney W. Grimes 				ProcessPacket(&rconn,client);
265ea022d16SRodney W. Grimes 
266ea022d16SRodney W. Grimes 				(void) sigsetmask(omask);
267ea022d16SRodney W. Grimes 			}
268ea022d16SRodney W. Grimes 		}
269ea022d16SRodney W. Grimes 	}
270ea022d16SRodney W. Grimes }
271ea022d16SRodney W. Grimes 
272eb0b8290SPhilippe Charnier static void
usage(void)273266ebcd3SWarner Losh usage(void)
274eb0b8290SPhilippe Charnier {
275eb0b8290SPhilippe Charnier 	fprintf(stderr, "usage: rbootd [-ad] [-i interface] [config_file]\n");
276eb0b8290SPhilippe Charnier 	exit (1);
277eb0b8290SPhilippe Charnier }
278eb0b8290SPhilippe Charnier 
279ea022d16SRodney W. Grimes /*
280ea022d16SRodney W. Grimes **  DoTimeout -- Free any connections that have timed out.
281ea022d16SRodney W. Grimes **
282ea022d16SRodney W. Grimes **	Parameters:
283ea022d16SRodney W. Grimes **		None.
284ea022d16SRodney W. Grimes **
285ea022d16SRodney W. Grimes **	Returns:
286ea022d16SRodney W. Grimes **		Nothing.
287ea022d16SRodney W. Grimes **
288ea022d16SRodney W. Grimes **	Side Effects:
289ea022d16SRodney W. Grimes **		- Timed out connections in `RmpConns' will be freed.
290ea022d16SRodney W. Grimes */
291ea022d16SRodney W. Grimes void
DoTimeout(void)292266ebcd3SWarner Losh DoTimeout(void)
293ea022d16SRodney W. Grimes {
29411fe7d5eSSteve Price 	RMPCONN *rtmp;
295902d9eafSEd Schouten 	time_t now;
296ea022d16SRodney W. Grimes 
297ea022d16SRodney W. Grimes 	/*
298ea022d16SRodney W. Grimes 	 *  For each active connection, if RMP_TIMEOUT seconds have passed
299ea022d16SRodney W. Grimes 	 *  since the last packet was sent, delete the connection.
300ea022d16SRodney W. Grimes 	 */
301902d9eafSEd Schouten 	now = time(NULL);
302ea022d16SRodney W. Grimes 	for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next)
303902d9eafSEd Schouten 		if ((rtmp->tstamp.tv_sec + RMP_TIMEOUT) < now) {
304ea022d16SRodney W. Grimes 			syslog(LOG_WARNING, "%s: connection timed out (%u)",
305ea022d16SRodney W. Grimes 			       EnetStr(rtmp), rtmp->rmp.r_type);
306ea022d16SRodney W. Grimes 			RemoveConn(rtmp);
307ea022d16SRodney W. Grimes 		}
308ea022d16SRodney W. Grimes }
309ea022d16SRodney W. Grimes 
310ea022d16SRodney W. Grimes /*
311ea022d16SRodney W. Grimes **  FindClient -- Find client associated with a packet.
312ea022d16SRodney W. Grimes **
313ea022d16SRodney W. Grimes **	Parameters:
314ea022d16SRodney W. Grimes **		rconn - the new packet.
315ea022d16SRodney W. Grimes **
316ea022d16SRodney W. Grimes **	Returns:
317ea022d16SRodney W. Grimes **		Pointer to client info if found, NULL otherwise.
318ea022d16SRodney W. Grimes **
319ea022d16SRodney W. Grimes **	Side Effects:
320ea022d16SRodney W. Grimes **		None.
321ea022d16SRodney W. Grimes **
322ea022d16SRodney W. Grimes **	Warnings:
323ea022d16SRodney W. Grimes **		- This routine must be called with SIGHUP blocked since
324ea022d16SRodney W. Grimes **		  a reconfigure can invalidate the information returned.
325ea022d16SRodney W. Grimes */
326ea022d16SRodney W. Grimes 
327ea022d16SRodney W. Grimes CLIENT *
FindClient(RMPCONN * rconn)328266ebcd3SWarner Losh FindClient(RMPCONN *rconn)
329ea022d16SRodney W. Grimes {
33011fe7d5eSSteve Price 	CLIENT *ctmp;
331ea022d16SRodney W. Grimes 
332ea022d16SRodney W. Grimes 	for (ctmp = Clients; ctmp != NULL; ctmp = ctmp->next)
333ea022d16SRodney W. Grimes 		if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0],
334ea022d16SRodney W. Grimes 		         (char *)&ctmp->addr[0], RMP_ADDRLEN) == 0)
335ea022d16SRodney W. Grimes 			break;
336ea022d16SRodney W. Grimes 
337ea022d16SRodney W. Grimes 	return(ctmp);
338ea022d16SRodney W. Grimes }
339ea022d16SRodney W. Grimes 
340ea022d16SRodney W. Grimes /*
341ea022d16SRodney W. Grimes **  Exit -- Log an error message and exit.
342ea022d16SRodney W. Grimes **
343ea022d16SRodney W. Grimes **	Parameters:
344ea022d16SRodney W. Grimes **		sig - caught signal (or zero if not dying on a signal).
345ea022d16SRodney W. Grimes **
346ea022d16SRodney W. Grimes **	Returns:
347ea022d16SRodney W. Grimes **		Does not return.
348ea022d16SRodney W. Grimes **
349ea022d16SRodney W. Grimes **	Side Effects:
350ea022d16SRodney W. Grimes **		- This process ceases to exist.
351ea022d16SRodney W. Grimes */
352ea022d16SRodney W. Grimes void
Exit(int sig)353266ebcd3SWarner Losh Exit(int sig)
354ea022d16SRodney W. Grimes {
355ea022d16SRodney W. Grimes 	if (sig > 0)
356ea022d16SRodney W. Grimes 		syslog(LOG_ERR, "going down on signal %d", sig);
357ea022d16SRodney W. Grimes 	else
358ea022d16SRodney W. Grimes 		syslog(LOG_ERR, "going down with fatal error");
359ea022d16SRodney W. Grimes 	BpfClose();
360ea022d16SRodney W. Grimes 	exit(1);
361ea022d16SRodney W. Grimes }
362ea022d16SRodney W. Grimes 
363ea022d16SRodney W. Grimes /*
364ea022d16SRodney W. Grimes **  ReConfig -- Get new list of boot files and reread config files.
365ea022d16SRodney W. Grimes **
366ea022d16SRodney W. Grimes **	Parameters:
367ea022d16SRodney W. Grimes **		None.
368ea022d16SRodney W. Grimes **
369ea022d16SRodney W. Grimes **	Returns:
370ea022d16SRodney W. Grimes **		Nothing.
371ea022d16SRodney W. Grimes **
372ea022d16SRodney W. Grimes **	Side Effects:
373ea022d16SRodney W. Grimes **		- All active connections are dropped.
374ea022d16SRodney W. Grimes **		- List of boot-able files is changed.
375ea022d16SRodney W. Grimes **		- List of clients is changed.
376ea022d16SRodney W. Grimes **
377ea022d16SRodney W. Grimes **	Warnings:
378ea022d16SRodney W. Grimes **		- This routine must be called with SIGHUP blocked.
379ea022d16SRodney W. Grimes */
380ea022d16SRodney W. Grimes void
ReConfig(int signo __unused)38143d4d555SPhilippe Charnier ReConfig(int signo __unused)
382ea022d16SRodney W. Grimes {
383ea022d16SRodney W. Grimes 	syslog(LOG_NOTICE, "reconfiguring boot server");
384ea022d16SRodney W. Grimes 
385ea022d16SRodney W. Grimes 	FreeConns();
386ea022d16SRodney W. Grimes 
387ea022d16SRodney W. Grimes 	if (GetBootFiles() == 0)
388ea022d16SRodney W. Grimes 		Exit(0);
389ea022d16SRodney W. Grimes 
390ea022d16SRodney W. Grimes 	if (ParseConfig() == 0)
391ea022d16SRodney W. Grimes 		Exit(0);
392ea022d16SRodney W. Grimes }
393ea022d16SRodney W. Grimes 
394ea022d16SRodney W. Grimes /*
395ea022d16SRodney W. Grimes **  DebugOff -- Turn off debugging.
396ea022d16SRodney W. Grimes **
397ea022d16SRodney W. Grimes **	Parameters:
398ea022d16SRodney W. Grimes **		None.
399ea022d16SRodney W. Grimes **
400ea022d16SRodney W. Grimes **	Returns:
401ea022d16SRodney W. Grimes **		Nothing.
402ea022d16SRodney W. Grimes **
403ea022d16SRodney W. Grimes **	Side Effects:
404ea022d16SRodney W. Grimes **		- Debug file is closed.
405ea022d16SRodney W. Grimes */
406ea022d16SRodney W. Grimes void
DebugOff(int signo __unused)40743d4d555SPhilippe Charnier DebugOff(int signo __unused)
408ea022d16SRodney W. Grimes {
409ea022d16SRodney W. Grimes 	if (DbgFp != NULL)
410ea022d16SRodney W. Grimes 		(void) fclose(DbgFp);
411ea022d16SRodney W. Grimes 
412ea022d16SRodney W. Grimes 	DbgFp = NULL;
413ea022d16SRodney W. Grimes }
414ea022d16SRodney W. Grimes 
415ea022d16SRodney W. Grimes /*
416ea022d16SRodney W. Grimes **  DebugOn -- Turn on debugging.
417ea022d16SRodney W. Grimes **
418ea022d16SRodney W. Grimes **	Parameters:
419ea022d16SRodney W. Grimes **		None.
420ea022d16SRodney W. Grimes **
421ea022d16SRodney W. Grimes **	Returns:
422ea022d16SRodney W. Grimes **		Nothing.
423ea022d16SRodney W. Grimes **
424ea022d16SRodney W. Grimes **	Side Effects:
425ea022d16SRodney W. Grimes **		- Debug file is opened/truncated if not already opened,
426ea022d16SRodney W. Grimes **		  otherwise do nothing.
427ea022d16SRodney W. Grimes */
428ea022d16SRodney W. Grimes void
DebugOn(int signo __unused)42943d4d555SPhilippe Charnier DebugOn(int signo __unused)
430ea022d16SRodney W. Grimes {
431ea022d16SRodney W. Grimes 	if (DbgFp == NULL) {
432ea022d16SRodney W. Grimes 		if ((DbgFp = fopen(DbgFile, "w")) == NULL)
433ea022d16SRodney W. Grimes 			syslog(LOG_ERR, "can't open debug file (%s)", DbgFile);
434ea022d16SRodney W. Grimes 	}
435ea022d16SRodney W. Grimes }
436