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