summaryrefslogtreecommitdiff
path: root/usr.sbin/rbootd/rbootd.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/rbootd/rbootd.c')
-rw-r--r--usr.sbin/rbootd/rbootd.c92
1 files changed, 71 insertions, 21 deletions
diff --git a/usr.sbin/rbootd/rbootd.c b/usr.sbin/rbootd/rbootd.c
index ce990cebcdd..424b38a8e72 100644
--- a/usr.sbin/rbootd/rbootd.c
+++ b/usr.sbin/rbootd/rbootd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rbootd.c,v 1.10 2002/02/19 18:38:02 mpech Exp $ */
+/* $OpenBSD: rbootd.c,v 1.11 2002/02/19 21:04:09 miod Exp $ */
/* $NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ */
/*
@@ -55,7 +55,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "@(#)rbootd.c 8.1 (Berkeley) 6/4/93";*/
-static char rcsid[] = "$OpenBSD: rbootd.c,v 1.10 2002/02/19 18:38:02 mpech Exp $";
+static char rcsid[] = "$OpenBSD: rbootd.c,v 1.11 2002/02/19 21:04:09 miod Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -74,6 +74,22 @@ static char rcsid[] = "$OpenBSD: rbootd.c,v 1.10 2002/02/19 18:38:02 mpech Exp $
extern char *__progname; /* from crt0.o */
+volatile sig_atomic_t dodebugoff;
+volatile sig_atomic_t dodebugon;
+volatile sig_atomic_t doreconfig;
+
+void DebugOff(int);
+void DebugOn(int);
+void ReConfig(int);
+void Exit(int);
+
+void DoDebugOff(void);
+void DoDebugOn(void);
+void DoReConfig(void);
+
+void DoTimeout(void);
+CLIENT *FindClient(RMPCONN *);
+
int
main(argc, argv)
int argc;
@@ -155,7 +171,7 @@ main(argc, argv)
syslog(LOG_NOTICE, "restarted (??)");
/* BpfGetIntfName() returns safe names, using %m */
syslog(LOG_ERR, "%s", errmsg);
- Exit(0);
+ DoExit();
}
}
@@ -170,7 +186,7 @@ main(argc, argv)
*/
if (gethostname(MyHost, sizeof(MyHost)) < 0) {
syslog(LOG_ERR, "gethostname: %m");
- Exit(0);
+ DoExit();
}
MyHost[MAXHOSTNAMELEN] = '\0';
@@ -187,7 +203,7 @@ main(argc, argv)
*/
if (chdir(BootDir) < 0) {
syslog(LOG_ERR, "chdir: %m (%s)", BootDir);
- Exit(0);
+ DoExit();
}
/*
@@ -197,13 +213,13 @@ main(argc, argv)
sigaddset(&hmask, SIGHUP);
sigprocmask(SIG_BLOCK, &hmask, &omask); /* prevent reconfig's */
if (GetBootFiles() == 0) /* get list of boot files */
- Exit(0);
+ DoExit();
if (ParseConfig() == 0) /* parse config file */
- Exit(0);
+ DoExit();
/*
* Open and initialize a BPF device for the appropriate interface.
- * If an error is encountered, a message is displayed and Exit()
+ * If an error is encountered, a message is displayed and DoExit()
* is called.
*/
fd = BpfOpen();
@@ -222,6 +238,22 @@ main(argc, argv)
fd_set r;
int nsel;
+ /*
+ * Check pending actions
+ */
+ if (dodebugoff) {
+ DoDebugOff();
+ dodebugoff = 0;
+ }
+ if (dodebugon) {
+ DoDebugOn();
+ dodebugon = 0;
+ }
+ if (doreconfig) {
+ DoReConfig();
+ doreconfig = 0;
+ }
+
r = rset;
if (RmpConns == NULL) { /* timeout isnt necessary */
@@ -236,7 +268,7 @@ main(argc, argv)
if (errno == EINTR)
continue;
syslog(LOG_ERR, "select: %m");
- Exit(0);
+ DoExit();
} else if (nsel == 0) { /* timeout */
DoTimeout(); /* clear stale conns */
continue;
@@ -316,7 +348,7 @@ DoTimeout()
** FindClient -- Find client associated with a packet.
**
** Parameters:
-** rconn - the new packet.
+** rconn - the new packet.
**
** Returns:
** Pointer to client info if found, NULL otherwise.
@@ -359,12 +391,16 @@ void
Exit(sig)
int sig;
{
- /* XXX race */
- if (sig > 0)
- syslog(LOG_ERR, "going down on signal %d", sig);
- else
- syslog(LOG_ERR, "going down with fatal error");
- BpfClose();
+ struct syslog_data sdata = SYSLOG_DATA_INIT;
+
+ syslog_r(LOG_ERR, &sdata, "going down on signal %d", sig);
+ _exit(1);
+}
+
+void
+DoExit()
+{
+ syslog(LOG_ERR, "going down on fatal error");
exit(1);
}
@@ -389,16 +425,21 @@ void
ReConfig(signo)
int signo;
{
- /* XXX race */
+ doreconfig = 1;
+}
+
+void
+DoReConfig()
+{
syslog(LOG_NOTICE, "reconfiguring boot server");
FreeConns();
if (GetBootFiles() == 0)
- Exit(0);
+ DoExit();
if (ParseConfig() == 0)
- Exit(0);
+ DoExit();
}
/*
@@ -417,8 +458,12 @@ void
DebugOff(signo)
int signo;
{
- /* XXX race */
+ dodebugoff = 1;
+}
+void
+DoDebugOff()
+{
if (DbgFp != NULL)
(void) fclose(DbgFp);
@@ -442,7 +487,12 @@ void
DebugOn(signo)
int signo;
{
- /* XXX race */
+ dodebugon = 1;
+}
+
+void
+DoDebugOn()
+{
if (DbgFp == NULL) {
if ((DbgFp = fopen(DbgFile, "w")) == NULL)
syslog(LOG_ERR, "can't open debug file (%s)", DbgFile);