summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-03-06 17:43:25 -0800
committerJeremy Allison <jra@samba.org>2008-03-06 17:43:25 -0800
commit868c5c986aa2a83ad9adcd1c03a75ccfec68fdff (patch)
treec4a4643cb56e89e89dcdd06f63bbd74e218a88ab /source3
parent6f4cd6df77e723ff033cc1ccd68955e605ed8c16 (diff)
downloadsamba-868c5c986aa2a83ad9adcd1c03a75ccfec68fdff.tar.gz
samba-868c5c986aa2a83ad9adcd1c03a75ccfec68fdff.tar.bz2
samba-868c5c986aa2a83ad9adcd1c03a75ccfec68fdff.zip
Fix bug #5267 - nmbd shuts down when network interfaces go down.
Cause nmbd to wait for an interface, in a mode where SIGTERM will kills us (same way we wait on startup for an interface). Jeremy. (This used to be commit 5440c752ff270cc674d46f2dfa2ceb47dac030f6)
Diffstat (limited to 'source3')
-rw-r--r--source3/nmbd/nmbd.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 378b6f3dbe..00d252940a 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -163,23 +163,31 @@ static void expire_names_and_servers(time_t t)
/************************************************************************** **
Reload the list of network interfaces.
+ Doesn't return until a network interface is up.
************************************************************************** */
-static bool reload_interfaces(time_t t)
+static void reload_interfaces(time_t t)
{
static time_t lastt;
int n;
struct subnet_record *subrec;
- if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return False;
+ if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) {
+ return;
+ }
+
lastt = t;
- if (!interfaces_changed()) return False;
+ if (!interfaces_changed()) {
+ return;
+ }
/* the list of probed interfaces has changed, we may need to add/remove
some subnets */
load_interfaces();
+ try_again:
+
/* find any interfaces that need adding */
for (n=iface_count() - 1; n >= 0; n--) {
char str[INET6_ADDRSTRLEN];
@@ -268,12 +276,33 @@ static bool reload_interfaces(time_t t)
rescan_listen_set = True;
- /* We need to shutdown if there are no subnets... */
+ /* We need to wait if there are no subnets... */
if (FIRST_SUBNET == NULL) {
- DEBUG(0,("reload_interfaces: No subnets to listen to. Shutting down...\n"));
- return True;
+ void (*saved_handler)(int);
+
+ DEBUG(0,("reload_interfaces: "
+ "No subnets to listen to. Waiting..\n"));
+
+ /*
+ * Whilst we're waiting for an interface, allow SIGTERM to
+ * cause us to exit.
+ */
+
+ saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );
+
+ /* We only count IPv4 interfaces here. */
+ while (iface_count_v4() == 0) {
+ sleep(5);
+ load_interfaces();
+ }
+
+ /*
+ * We got an interface, restore our normal term handler.
+ */
+
+ CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
+ goto try_again;
}
- return False;
}
/**************************************************************************** **
@@ -310,8 +339,6 @@ static bool reload_nmbd_services(bool test)
/**************************************************************************** **
* React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP
- * We use buf here to return bool result to process() when reload_interfaces()
- * detects that there are no subnets.
**************************************************************************** */
static void msg_reload_nmbd_services(struct messaging_context *msg,
@@ -324,14 +351,7 @@ static void msg_reload_nmbd_services(struct messaging_context *msg,
dump_all_namelists();
reload_nmbd_services( True );
reopen_logs();
-
- if (data->data) {
- /* We were called from process() */
- /* If reload_interfaces() returned True */
- /* we need to shutdown if there are no subnets... */
- /* pass this info back to process() */
- *((bool *)data->data) = reload_interfaces(0);
- }
+ reload_interfaces(0);
}
static void msg_nmbd_send_packet(struct messaging_context *msg,
@@ -401,7 +421,6 @@ static void msg_nmbd_send_packet(struct messaging_context *msg,
static void process(void)
{
bool run_election;
- bool no_subnets;
while( True ) {
time_t t = time(NULL);
@@ -612,26 +631,17 @@ static void process(void)
*/
if(reload_after_sighup) {
- DATA_BLOB blob = data_blob_const(&no_subnets,
- sizeof(no_subnets));
DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) );
msg_reload_nmbd_services(nmbd_messaging_context(),
NULL, MSG_SMB_CONF_UPDATED,
- procid_self(), &blob);
+ procid_self(), NULL);
- if(no_subnets) {
- TALLOC_FREE(frame);
- return;
- }
reload_after_sighup = 0;
}
/* check for new network interfaces */
- if(reload_interfaces(t)) {
- TALLOC_FREE(frame);
- return;
- }
+ reload_interfaces(t);
/* free up temp memory */
TALLOC_FREE(frame);