summaryrefslogtreecommitdiffstats
path: root/source/smbd/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/smbd/server.c')
-rw-r--r--source/smbd/server.c99
1 files changed, 53 insertions, 46 deletions
diff --git a/source/smbd/server.c b/source/smbd/server.c
index b3b428a9b42..b18921e1af3 100644
--- a/source/smbd/server.c
+++ b/source/smbd/server.c
@@ -61,26 +61,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);
+ if(am_parent)
+ kill(0,SIGTERM);
}
-
/****************************************************************************
- open the socket communication
+ Open the socket communication - inetd.
****************************************************************************/
+
static BOOL open_sockets_inetd(void)
{
/* Started from inetd. fd 0 is the socket. */
@@ -97,10 +114,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();
@@ -212,10 +229,13 @@ 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) {
+ DEBUG(0,("Got SIGHUP\n"));
change_to_root_user();
DEBUG(1,("Reloading services after SIGHUP\n"));
reload_services(False);
@@ -320,8 +340,9 @@ max can be %d\n",
}
/****************************************************************************
- reload the services file
- **************************************************************************/
+ Reload the services file.
+ **************************************************************************/
+
BOOL reload_services(BOOL test)
{
BOOL ret;
@@ -370,30 +391,11 @@ 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;
@@ -443,8 +445,9 @@ static void decrement_smbd_process_count(void)
}
/****************************************************************************
-exit the server
+ Exit the server.
****************************************************************************/
+
void exit_server(char *reason)
{
static int firsttime=1;
@@ -494,8 +497,9 @@ void exit_server(char *reason)
}
/****************************************************************************
- initialise connect, service and file structs
+ Initialise connect, service and file structs.
****************************************************************************/
+
static void init_structs(void )
{
/*
@@ -526,8 +530,9 @@ static void init_structs(void )
}
/****************************************************************************
-usage on the program
+ Usage on the program.
****************************************************************************/
+
static void usage(char *pname)
{
@@ -548,13 +553,14 @@ 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;
@@ -611,6 +617,7 @@ static void usage(char *pname)
DEBUGLEVEL = 10000;
else
DEBUGLEVEL = atoi(optarg);
+ AllowDebugChange = False;
break;
case 'p':
@@ -666,7 +673,8 @@ 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);
@@ -685,6 +693,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 */
@@ -735,8 +744,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)) {
@@ -782,6 +789,11 @@ 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);
@@ -804,11 +816,6 @@ 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()));