summaryrefslogtreecommitdiff
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
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)
-rw-r--r--source3/nsswitch/winbindd.c9
-rw-r--r--source3/smbd/process.c12
-rw-r--r--source3/smbd/server.c91
3 files changed, 62 insertions, 50 deletions
diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c
index a9abcd3e6e..9058fa4174 100644
--- a/source3/nsswitch/winbindd.c
+++ b/source3/nsswitch/winbindd.c
@@ -649,13 +649,14 @@ struct winbindd_state server_state; /* Server state information */
int main(int argc, char **argv)
{
+ extern BOOL AllowDebugChange;
extern pstring global_myname;
extern fstring global_myworkgroup;
extern BOOL append_log;
pstring logfile;
int accept_sock;
BOOL interactive = False;
- int opt, new_debuglevel = -1;
+ int opt;
/* glibc (?) likes to print "User defined signal 1" and exit if a
SIGUSR2 is received before a handler is installed */
@@ -698,7 +699,8 @@ int main(int argc, char **argv)
/* Run with specified debug level */
case 'd':
- new_debuglevel = atoi(optarg);
+ DEBUGLEVEL = atoi(optarg);
+ AllowDebugChange = False;
break;
/* Load a different smb.conf file */
@@ -740,9 +742,6 @@ int main(int argc, char **argv)
fstrcpy(global_myworkgroup, lp_workgroup());
- if (new_debuglevel != -1)
- DEBUGLEVEL = new_debuglevel;
-
if (!interactive)
become_daemon();
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 8c037b4706..007621f6bb 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -43,6 +43,7 @@ extern int global_oplock_break;
extern userdom_struct current_user_info;
extern int smb_read_error;
extern VOLATILE sig_atomic_t reload_after_sighup;
+extern VOLATILE sig_atomic_t got_sig_term;
extern BOOL global_machine_password_needs_changing;
extern fstring global_myworkgroup;
extern pstring global_myname;
@@ -104,9 +105,10 @@ BOOL push_oplock_pending_smb_message(char *buf, int msg_len)
}
/****************************************************************************
-do all async processing in here. This includes UDB oplock messages, kernel
-oplock messages, change notify events etc.
+ Do all async processing in here. This includes UDB oplock messages, kernel
+ oplock messages, change notify events etc.
****************************************************************************/
+
static void async_processing(fd_set *fds, char *buffer, int buffer_len)
{
/* check for oplock messages (both UDP and kernel) */
@@ -114,6 +116,10 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len)
process_local_message(buffer, buffer_len);
}
+ if (got_sig_term) {
+ exit_server("Caught TERM signal");
+ }
+
/* check for async change notify events */
process_pending_change_notify_queue(0);
@@ -122,7 +128,7 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len)
change_to_root_user();
DEBUG(1,("Reloading services after SIGHUP\n"));
reload_services(False);
- reload_after_sighup = False;
+ reload_after_sighup = 0;
}
}
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)) {