summaryrefslogtreecommitdiff
path: root/source3/smbd/server.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-03-14 02:15:08 +0000
committerJeremy Allison <jra@samba.org>2002-03-14 02:15:08 +0000
commit840279f3424eb92d1c4b55e1f9a1aca938b087ca (patch)
tree35e6fa5ea11c55aacca70834748812a919962dfa /source3/smbd/server.c
parent57bd576445e42a55887c41d270f2230f5136b873 (diff)
downloadsamba-840279f3424eb92d1c4b55e1f9a1aca938b087ca.tar.gz
samba-840279f3424eb92d1c4b55e1f9a1aca938b087ca.tar.bz2
samba-840279f3424eb92d1c4b55e1f9a1aca938b087ca.zip
Now we have reliable signals take SIGTERM inband.
Jeremy. (This used to be commit cad82926a8baf7605cef81f0e0d4daa8e527e6ee)
Diffstat (limited to 'source3/smbd/server.c')
-rw-r--r--source3/smbd/server.c91
1 files changed, 49 insertions, 42 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 02f52e2392..8a5983d784 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -60,26 +60,43 @@ void smbd_set_server_fd(int fd)
}
/****************************************************************************
- when exiting, take the whole family
+ Terminate signal.
****************************************************************************/
-static void *dflt_sig(void)
+
+VOLATILE sig_atomic_t got_sig_term = 0;
+
+static void sig_term(void)
+{
+ got_sig_term = 1;
+ sys_select_signal();
+}
+
+/****************************************************************************
+ Catch a sighup.
+****************************************************************************/
+
+VOLATILE sig_atomic_t reload_after_sighup = 0;
+
+static void sig_hup(int sig)
{
- exit_server("caught signal");
- return NULL;
+ reload_after_sighup = 1;
+ sys_select_signal();
}
/****************************************************************************
Send a SIGTERM to our process group.
*****************************************************************************/
+
static void killkids(void)
{
if(am_parent) kill(0,SIGTERM);
}
/****************************************************************************
- process a sam sync message - not sure whether to do this here or
- somewhere else
+ Process a sam sync message - not sure whether to do this here or
+ somewhere else.
****************************************************************************/
+
static void msg_sam_sync(int UNUSED(msg_type), pid_t UNUSED(pid),
void *UNUSED(buf), size_t UNUSED(len))
{
@@ -87,9 +104,10 @@ static void msg_sam_sync(int UNUSED(msg_type), pid_t UNUSED(pid),
}
/****************************************************************************
- process a sam sync replicate message - not sure whether to do this here or
- somewhere else
+ Process a sam sync replicate message - not sure whether to do this here or
+ somewhere else.
****************************************************************************/
+
static void msg_sam_repl(int msg_type, pid_t pid, void *buf, size_t len)
{
uint32 low_serial;
@@ -104,8 +122,9 @@ static void msg_sam_repl(int msg_type, pid_t pid, void *buf, size_t len)
}
/****************************************************************************
- open the socket communication
+ Open the socket communication - inetd.
****************************************************************************/
+
static BOOL open_sockets_inetd(void)
{
/* Started from inetd. fd 0 is the socket. */
@@ -124,8 +143,9 @@ static BOOL open_sockets_inetd(void)
/****************************************************************************
- open the socket communication
+ Open the socket communication.
****************************************************************************/
+
static BOOL open_sockets(BOOL is_daemon,int port)
{
int num_interfaces = iface_count();
@@ -242,14 +262,16 @@ max can be %d\n",
num = sys_select(FD_SETSIZE,&lfds,NULL,NULL,NULL);
if (num == -1 && errno == EINTR) {
- extern VOLATILE sig_atomic_t reload_after_sighup;
+ if (got_sig_term) {
+ exit_server("Caught TERM signal");
+ }
/* check for sighup processing */
if (reload_after_sighup) {
change_to_root_user();
DEBUG(1,("Reloading services after SIGHUP\n"));
reload_services(False);
- reload_after_sighup = False;
+ reload_after_sighup = 0;
}
continue;
@@ -347,8 +369,9 @@ max can be %d\n",
}
/****************************************************************************
- reload the services file
- **************************************************************************/
+ Reload the services file.
+**************************************************************************/
+
BOOL reload_services(BOOL test)
{
BOOL ret;
@@ -398,26 +421,6 @@ BOOL reload_services(BOOL test)
return(ret);
}
-
-
-/****************************************************************************
- Catch a sighup.
-****************************************************************************/
-
-VOLATILE sig_atomic_t reload_after_sighup = False;
-
-static void sig_hup(int sig)
-{
- BlockSignals(True,SIGHUP);
- DEBUG(0,("Got SIGHUP\n"));
-
- sys_select_signal();
- reload_after_sighup = True;
- BlockSignals(False,SIGHUP);
-}
-
-
-
#if DUMP_CORE
/*******************************************************************
prepare to dump a core file - carefully!
@@ -472,8 +475,9 @@ static void decrement_smbd_process_count(void)
}
/****************************************************************************
-exit the server
+ Exit the server.
****************************************************************************/
+
void exit_server(char *reason)
{
static int firsttime=1;
@@ -527,8 +531,9 @@ void exit_server(char *reason)
}
/****************************************************************************
- initialise connect, service and file structs
+ Initialise connect, service and file structs.
****************************************************************************/
+
static void init_structs(void )
{
/*
@@ -560,8 +565,9 @@ static void init_structs(void )
}
/****************************************************************************
-usage on the program
+ Usage on the program.
****************************************************************************/
+
static void usage(char *pname)
{
@@ -584,8 +590,9 @@ static void usage(char *pname)
}
/****************************************************************************
- main program
+ main program.
****************************************************************************/
+
int main(int argc,char *argv[])
{
extern BOOL append_log;
@@ -704,8 +711,9 @@ static void usage(char *pname)
gain_root_group_privilege();
fault_setup((void (*)(void *))exit_server);
- CatchSignal(SIGTERM , SIGNAL_CAST dflt_sig);
-
+ CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
+ CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
+
/* we are never interested in SIGPIPE */
BlockSignals(True,SIGPIPE);
@@ -723,6 +731,7 @@ static void usage(char *pname)
* these signals masked, we will have problems, as we won't recieve them. */
BlockSignals(False, SIGHUP);
BlockSignals(False, SIGUSR1);
+ BlockSignals(False, SIGTERM);
/* we want total control over the permissions on created files,
so set our umask to 0 */
@@ -778,8 +787,6 @@ static void usage(char *pname)
fstrcpy(global_myworkgroup, lp_workgroup());
- CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
-
DEBUG(3,( "loaded services\n"));
if (!is_daemon && !is_a_socket(0)) {