Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ypbind Add a SIGHUP handler; upon SIGHUP do an extr...
details: https://anonhg.NetBSD.org/src/rev/06b4cdc7fa53
branches: trunk
changeset: 329814:06b4cdc7fa53
user: dholland <dholland%NetBSD.org@localhost>
date: Tue Jun 10 17:19:36 2014 +0000
description:
Add a SIGHUP handler; upon SIGHUP do an extra nag_servers on any
domain that's in DEAD state. This lets you explicitly rescue ypbind
from its exponential backoff when you know the world's back up.
diffstat:
usr.sbin/ypbind/ypbind.c | 71 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 4 deletions(-)
diffs (129 lines):
diff -r 796b3e4dd37f -r 06b4cdc7fa53 usr.sbin/ypbind/ypbind.c
--- a/usr.sbin/ypbind/ypbind.c Tue Jun 10 17:19:22 2014 +0000
+++ b/usr.sbin/ypbind/ypbind.c Tue Jun 10 17:19:36 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ypbind.c,v 1.96 2014/06/10 17:19:22 dholland Exp $ */
+/* $NetBSD: ypbind.c,v 1.97 2014/06/10 17:19:36 dholland Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt%fsa.ca@localhost>
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef LINT
-__RCSID("$NetBSD: ypbind.c,v 1.96 2014/06/10 17:19:22 dholland Exp $");
+__RCSID("$NetBSD: ypbind.c,v 1.97 2014/06/10 17:19:36 dholland Exp $");
#endif
#include <sys/types.h>
@@ -50,6 +50,7 @@
#include <ifaddrs.h>
#include <limits.h>
#include <netdb.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -133,6 +134,9 @@
/* The ypbind service transports */
static SVCXPRT *udptransp, *tcptransp;
+/* set if we get SIGHUP */
+static sig_atomic_t hupped;
+
////////////////////////////////////////////////////////////
// utilities
@@ -1533,6 +1537,51 @@
}
}
+/*
+ * Process a hangup signal.
+ *
+ * Do an extra nag_servers() for any domains that are DEAD. This way
+ * if you know things are back up you can restore service by sending
+ * ypbind a SIGHUP rather than waiting for the timeout period.
+ */
+static void
+dohup(void)
+{
+ struct domain *dom;
+
+ hupped = 0;
+ for (dom = domains; dom != NULL; dom = dom->dom_next) {
+ if (dom->dom_state == DOM_DEAD) {
+ (void)nag_servers(dom);
+ }
+ }
+}
+
+/*
+ * Receive a hangup signal.
+ */
+static void
+hup(int __unused sig)
+{
+ hupped = 1;
+}
+
+/*
+ * Initialize hangup processing.
+ */
+static void
+starthup(void)
+{
+ struct sigaction sa;
+
+ sa.sa_handler = hup;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART;
+ if (sigaction(SIGHUP, &sa, NULL) == -1) {
+ err(1, "sigaction");
+ }
+}
+
////////////////////////////////////////////////////////////
// main
@@ -1615,6 +1664,9 @@
if (lockfd == -1)
err(1, "Cannot create %s", _PATH_YPBIND_LOCK);
+ /* Accept hangups. */
+ starthup();
+
/* Initialize sunrpc stuff. */
sunrpc_setup();
@@ -1672,12 +1724,24 @@
switch (select(width, &fdsr, NULL, NULL, &tv)) {
case 0:
/* select timed out - check for timer-based work */
+ if (hupped) {
+ dohup();
+ }
checkwork();
break;
case -1:
- yp_log(LOG_WARNING, "select: %s", strerror(errno));
+ if (hupped) {
+ dohup();
+ }
+ if (errno != EINTR) {
+ yp_log(LOG_WARNING, "select: %s",
+ strerror(errno));
+ }
break;
default:
+ if (hupped) {
+ dohup();
+ }
/* incoming of our own; read it */
if (FD_ISSET(rpcsock, &fdsr))
(void)handle_replies();
@@ -1716,4 +1780,3 @@
}
}
}
-
Home |
Main Index |
Thread Index |
Old Index