mirror of
https://github.com/samba-team/samba.git
synced 2025-02-10 13:57:47 +03:00
s3:nmbd: handle SIG_TERM and SIGHUP via tevent
metze
This commit is contained in:
parent
2630d4a252
commit
d361e332a8
@ -85,6 +85,69 @@ static void terminate(void)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void nmbd_sig_term_handler(struct tevent_context *ev,
|
||||||
|
struct tevent_signal *se,
|
||||||
|
int signum,
|
||||||
|
int count,
|
||||||
|
void *siginfo,
|
||||||
|
void *private_data)
|
||||||
|
{
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 bool nmbd_setup_sig_hup_handler(void)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************** **
|
/**************************************************************************** **
|
||||||
Handle a SHUTDOWN message from smbcontrol.
|
Handle a SHUTDOWN message from smbcontrol.
|
||||||
**************************************************************************** */
|
**************************************************************************** */
|
||||||
@ -98,30 +161,6 @@ static void nmbd_terminate(struct messaging_context *msg,
|
|||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************** **
|
|
||||||
Catch a SIGTERM signal.
|
|
||||||
**************************************************************************** */
|
|
||||||
|
|
||||||
static SIG_ATOMIC_T got_sig_term;
|
|
||||||
|
|
||||||
static void sig_term(int sig)
|
|
||||||
{
|
|
||||||
got_sig_term = 1;
|
|
||||||
sys_select_signal(SIGTERM);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************** **
|
|
||||||
Catch a SIGHUP signal.
|
|
||||||
**************************************************************************** */
|
|
||||||
|
|
||||||
static SIG_ATOMIC_T reload_after_sighup;
|
|
||||||
|
|
||||||
static void sig_hup(int sig)
|
|
||||||
{
|
|
||||||
reload_after_sighup = 1;
|
|
||||||
sys_select_signal(SIGHUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************** **
|
/**************************************************************************** **
|
||||||
Possibly continue after a fault.
|
Possibly continue after a fault.
|
||||||
**************************************************************************** */
|
**************************************************************************** */
|
||||||
@ -451,15 +490,6 @@ static void process(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Handle termination inband.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (got_sig_term) {
|
|
||||||
got_sig_term = 0;
|
|
||||||
terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process all incoming packets
|
* Process all incoming packets
|
||||||
* read above. This calls the success and
|
* read above. This calls the success and
|
||||||
@ -629,19 +659,6 @@ static void process(void)
|
|||||||
|
|
||||||
clear_unexpected(t);
|
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 */
|
/* check for new network interfaces */
|
||||||
|
|
||||||
reload_interfaces(t);
|
reload_interfaces(t);
|
||||||
@ -808,9 +825,6 @@ static bool open_sockets(bool isdaemon, int port)
|
|||||||
BlockSignals(False, SIGUSR1);
|
BlockSignals(False, SIGUSR1);
|
||||||
BlockSignals(False, SIGTERM);
|
BlockSignals(False, SIGTERM);
|
||||||
|
|
||||||
CatchSignal( SIGHUP, SIGNAL_CAST sig_hup );
|
|
||||||
CatchSignal( SIGTERM, SIGNAL_CAST sig_term );
|
|
||||||
|
|
||||||
#if defined(SIGFPE)
|
#if defined(SIGFPE)
|
||||||
/* we are never interested in SIGFPE */
|
/* we are never interested in SIGFPE */
|
||||||
BlockSignals(True,SIGFPE);
|
BlockSignals(True,SIGFPE);
|
||||||
@ -905,6 +919,11 @@ static bool open_sockets(bool isdaemon, int port)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nmbd_setup_sig_term_handler())
|
||||||
|
exit(1);
|
||||||
|
if (!nmbd_setup_sig_hup_handler())
|
||||||
|
exit(1);
|
||||||
|
|
||||||
/* get broadcast messages */
|
/* get broadcast messages */
|
||||||
claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP);
|
claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user