diff options
Diffstat (limited to 'source3/nmbd')
-rw-r--r-- | source3/nmbd/asyncdns.c | 12 | ||||
-rw-r--r-- | source3/nmbd/nmbd.c | 134 | ||||
-rw-r--r-- | source3/nmbd/nmbd_become_dmb.c | 3 | ||||
-rw-r--r-- | source3/nmbd/nmbd_packets.c | 8 | ||||
-rw-r--r-- | source3/nmbd/nmbd_subnetdb.c | 3 | ||||
-rw-r--r-- | source3/nmbd/nmbd_synclists.c | 2 |
6 files changed, 76 insertions, 86 deletions
diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index baa88bc44b..0736a66fb8 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -210,9 +210,6 @@ void run_dns_queue(void) if (fd_in == -1) return; - /* Allow SIGTERM to kill us. */ - BlockSignals(False, SIGTERM); - if (!process_exists_by_pid(child_pid)) { close(fd_in); close(fd_out); @@ -224,12 +221,9 @@ void run_dns_queue(void) if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("read from child failed: %s\n", nt_errstr(status))); fd_in = -1; - BlockSignals(True, SIGTERM); return; } - BlockSignals(True, SIGTERM); - namerec = add_dns_result(&r.name, r.result); if (dns_current) { @@ -338,14 +332,8 @@ bool queue_dns_query(struct packet_struct *p,struct nmb_name *question) DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); - /* Unblock TERM signal so we can be killed in DNS lookup. */ - BlockSignals(False, SIGTERM); - dns_ip.s_addr = interpret_addr(qname); - /* Re-block TERM signal. */ - BlockSignals(True, SIGTERM); - namerec = add_dns_result(question, dns_ip); if(namerec == NULL) { send_wins_name_query_response(NAM_ERR, p, NULL); diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 0922e455a3..adefb7d94f 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -85,41 +85,80 @@ static void terminate(void) exit(0); } -/**************************************************************************** ** - Handle a SHUTDOWN message from smbcontrol. - **************************************************************************** */ - -static void nmbd_terminate(struct messaging_context *msg, - void *private_data, - uint32_t msg_type, - struct server_id server_id, - DATA_BLOB *data) +static void nmbd_sig_term_handler(struct tevent_context *ev, + struct tevent_signal *se, + int signum, + int count, + void *siginfo, + void *private_data) { terminate(); } -/**************************************************************************** ** - Catch a SIGTERM signal. - **************************************************************************** */ +static bool nmbd_setup_sig_term_handler(void) +{ + struct tevent_signal *se; + + se = tevent_add_signal(nmbd_event_context(), + nmbd_event_context(), + SIGTERM, 0, + nmbd_sig_term_handler, + NULL); + if (!se) { + DEBUG(0,("failed to setup SIGTERM handler")); + return false; + } -static SIG_ATOMIC_T got_sig_term; + return true; +} + +static void msg_reload_nmbd_services(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data); + +static void nmbd_sig_hup_handler(struct tevent_context *ev, + struct tevent_signal *se, + int signum, + int count, + void *siginfo, + void *private_data) +{ + DEBUG(0,("Got SIGHUP dumping debug info.\n")); + msg_reload_nmbd_services(nmbd_messaging_context(), + NULL, MSG_SMB_CONF_UPDATED, + procid_self(), NULL); +} -static void sig_term(int sig) +static bool nmbd_setup_sig_hup_handler(void) { - got_sig_term = 1; - sys_select_signal(SIGTERM); + struct tevent_signal *se; + + se = tevent_add_signal(nmbd_event_context(), + nmbd_event_context(), + SIGHUP, 0, + nmbd_sig_hup_handler, + NULL); + if (!se) { + DEBUG(0,("failed to setup SIGHUP handler")); + return false; + } + + return true; } /**************************************************************************** ** - Catch a SIGHUP signal. + Handle a SHUTDOWN message from smbcontrol. **************************************************************************** */ -static SIG_ATOMIC_T reload_after_sighup; - -static void sig_hup(int sig) +static void nmbd_terminate(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { - reload_after_sighup = 1; - sys_select_signal(SIGHUP); + terminate(); } /**************************************************************************** ** @@ -282,6 +321,7 @@ static void reload_interfaces(time_t t) /* We need to wait if there are no subnets... */ if (FIRST_SUBNET == NULL) { + void (*saved_handler)(int); if (print_waiting_msg) { DEBUG(0,("reload_interfaces: " @@ -293,29 +333,20 @@ static void reload_interfaces(time_t t) * Whilst we're waiting for an interface, allow SIGTERM to * cause us to exit. */ - - BlockSignals(false, SIGTERM); + saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); /* We only count IPv4, non-loopback interfaces here. */ - while (iface_count_v4_nl() == 0 && !got_sig_term) { + while (iface_count_v4_nl() == 0) { sleep(5); load_interfaces(); } - /* - * Handle termination inband. - */ - - if (got_sig_term) { - got_sig_term = 0; - terminate(); - } + CatchSignal( SIGTERM, SIGNAL_CAST saved_handler ); /* * We got an interface, go back to blocking term. */ - BlockSignals(true, SIGTERM); goto try_again; } } @@ -460,15 +491,6 @@ static void process(void) } /* - * Handle termination inband. - */ - - if (got_sig_term) { - got_sig_term = 0; - terminate(); - } - - /* * Process all incoming packets * read above. This calls the success and * failure functions registered when response @@ -637,19 +659,6 @@ static void process(void) clear_unexpected(t); - /* - * Reload the services file if we got a sighup. - */ - - if(reload_after_sighup) { - DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); - msg_reload_nmbd_services(nmbd_messaging_context(), - NULL, MSG_SMB_CONF_UPDATED, - procid_self(), NULL); - - reload_after_sighup = 0; - } - /* check for new network interfaces */ reload_interfaces(t); @@ -815,10 +824,7 @@ static bool open_sockets(bool isdaemon, int port) BlockSignals(False, SIGHUP); BlockSignals(False, SIGUSR1); BlockSignals(False, SIGTERM); - - CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); - CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); - + #if defined(SIGFPE) /* we are never interested in SIGFPE */ BlockSignals(True,SIGFPE); @@ -913,6 +919,11 @@ static bool open_sockets(bool isdaemon, int port) exit(1); } + if (!nmbd_setup_sig_term_handler()) + exit(1); + if (!nmbd_setup_sig_hup_handler()) + exit(1); + /* get broadcast messages */ claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP); @@ -977,9 +988,6 @@ static bool open_sockets(bool isdaemon, int port) exit(1); } - /* We can only take signals in the select. */ - BlockSignals( True, SIGTERM ); - TALLOC_FREE(frame); process(); diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index a0b2ef15f8..827d56cb06 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -128,7 +128,8 @@ in workgroup %s on subnet %s\n", work->dmb_name = nmbname; - /* Pick the first interface IPv4 address as the domain master browser ip. */ + /* Pick the first interface IPv4 address as the domain master + * browser ip. */ nip = first_ipv4_iface(); if (!nip) { DEBUG(0,("become_domain_master_stage2: " diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 489034899e..f69845b346 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1794,16 +1794,8 @@ bool listen_for_packets(bool run_election) &r_fds, &w_fds, &timeout, &maxfd); } - /* Prepare for the select - allow certain signals. */ - - BlockSignals(False, SIGTERM); - selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&timeout); - /* We can only take signals when we are in the select - block them again here. */ - - BlockSignals(True, SIGTERM); - if (run_events(nmbd_event_context(), selrtn, &r_fds, &w_fds)) { return False; } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 61af0bb4a4..13bc931863 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -287,7 +287,8 @@ bool create_subnets(void) } if (lp_we_are_a_wins_server()) { - /* Pick the first interface IPv4 address as the WINS server ip. */ + /* Pick the first interface IPv4 address as the WINS server + * ip. */ const struct in_addr *nip = first_ipv4_iface(); if (!nip) { diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 3e672aef25..5da0da81e5 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -109,7 +109,7 @@ static void sync_child(char *name, int nm_type, return; } - if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { + if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, "IPC$", "IPC", "", 1))) { cli_shutdown(cli); return; } |