diff options
Diffstat (limited to 'source/smbd/server.c')
-rw-r--r-- | source/smbd/server.c | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/source/smbd/server.c b/source/smbd/server.c index b18921e1af3..b3b428a9b42 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -61,43 +61,26 @@ void smbd_set_server_fd(int fd) } /**************************************************************************** - Terminate signal. + when exiting, take the whole family ****************************************************************************/ - -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) +static void *dflt_sig(void) { - reload_after_sighup = 1; - sys_select_signal(); + exit_server("caught signal"); + return NULL; } /**************************************************************************** Send a SIGTERM to our process group. *****************************************************************************/ - static void killkids(void) { - if(am_parent) - kill(0,SIGTERM); + if(am_parent) kill(0,SIGTERM); } + /**************************************************************************** - Open the socket communication - inetd. + open the socket communication ****************************************************************************/ - static BOOL open_sockets_inetd(void) { /* Started from inetd. fd 0 is the socket. */ @@ -114,10 +97,10 @@ static BOOL open_sockets_inetd(void) return True; } + /**************************************************************************** - Open the socket communication. + open the socket communication ****************************************************************************/ - static BOOL open_sockets(BOOL is_daemon,BOOL interactive, int port) { int num_interfaces = iface_count(); @@ -229,13 +212,10 @@ max can be %d\n", num = sys_select(FD_SETSIZE,&lfds,NULL,NULL,NULL); if (num == -1 && errno == EINTR) { - if (got_sig_term) { - exit_server("Caught TERM signal"); - } + extern VOLATILE sig_atomic_t reload_after_sighup; /* check for sighup processing */ if (reload_after_sighup) { - DEBUG(0,("Got SIGHUP\n")); change_to_root_user(); DEBUG(1,("Reloading services after SIGHUP\n")); reload_services(False); @@ -340,9 +320,8 @@ max can be %d\n", } /**************************************************************************** - Reload the services file. - **************************************************************************/ - + reload the services file + **************************************************************************/ BOOL reload_services(BOOL test) { BOOL ret; @@ -391,11 +370,30 @@ 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 ! +prepare to dump a core file - carefully! ********************************************************************/ - static BOOL dump_core(void) { char *p; @@ -445,9 +443,8 @@ static void decrement_smbd_process_count(void) } /**************************************************************************** - Exit the server. +exit the server ****************************************************************************/ - void exit_server(char *reason) { static int firsttime=1; @@ -497,9 +494,8 @@ void exit_server(char *reason) } /**************************************************************************** - Initialise connect, service and file structs. + initialise connect, service and file structs ****************************************************************************/ - static void init_structs(void ) { /* @@ -530,9 +526,8 @@ static void init_structs(void ) } /**************************************************************************** - Usage on the program. +usage on the program ****************************************************************************/ - static void usage(char *pname) { @@ -553,14 +548,13 @@ static void usage(char *pname) printf("\n"); } + /**************************************************************************** - main program. + main program ****************************************************************************/ - int main(int argc,char *argv[]) { extern BOOL append_log; - extern BOOL AllowDebugChange; /* shall I run as a daemon */ BOOL is_daemon = False; BOOL interactive = False; @@ -617,7 +611,6 @@ static void usage(char *pname) DEBUGLEVEL = 10000; else DEBUGLEVEL = atoi(optarg); - AllowDebugChange = False; break; case 'p': @@ -673,8 +666,7 @@ static void usage(char *pname) gain_root_group_privilege(); fault_setup((void (*)(void *))exit_server); - CatchSignal(SIGTERM , SIGNAL_CAST sig_term); - CatchSignal(SIGHUP,SIGNAL_CAST sig_hup); + CatchSignal(SIGTERM , SIGNAL_CAST dflt_sig); /* we are never interested in SIGPIPE */ BlockSignals(True,SIGPIPE); @@ -693,7 +685,6 @@ 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 */ @@ -744,6 +735,8 @@ 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)) { @@ -789,11 +782,6 @@ static void usage(char *pname) if (!migrate_from_old_password_file(global_myworkgroup)) DEBUG(0,("Failed to migrate from old MAC file.\n")); - if(!pdb_generate_sam_sid()) { - DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n")); - exit(1); - } - if (!open_sockets(is_daemon,interactive,port)) exit(1); @@ -816,6 +804,11 @@ static void usage(char *pname) /* possibly reload the services file. */ reload_services(True); + if(!pdb_generate_sam_sid()) { + DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n")); + exit(1); + } + if (*lp_rootdir()) { if (sys_chroot(lp_rootdir()) == 0) DEBUG(2,("Changed root to %s\n", lp_rootdir())); |