/*
- Unix SMB/Netbios implementation.
+ Unix SMB/CIFS implementation.
Main SMB server routines
Copyright (C) Andrew Tridgell 1992-1998
Copyright (C) Martin Pool 2002
return server_fd;
}
-void smbd_set_server_fd(int fd)
+static void smbd_set_server_fd(int fd)
{
server_fd = fd;
client_setfd(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))
{
}
/****************************************************************************
- 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;
}
/****************************************************************************
- open the socket communication
+ Open the socket communication - inetd.
****************************************************************************/
+
static BOOL open_sockets_inetd(void)
{
/* Started from inetd. fd 0 is the socket. */
return True;
}
+static void msg_exit_server(int msg_type, pid_t src, void *buf, size_t len)
+{
+ exit_server("Got a SHUTDOWN message");
+}
+
/****************************************************************************
- open the socket communication
+ Open the socket communication.
****************************************************************************/
+
static BOOL open_sockets(BOOL is_daemon,int port)
{
int num_interfaces = iface_count();
message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
message_register(MSG_SMB_SAM_REPL, msg_sam_repl);
+ message_register(MSG_SHUTDOWN, msg_exit_server);
/* now accept incoming connections - forking a new process
for each incoming connection */
memcpy((char *)&lfds, (char *)&listen_set,
sizeof(listen_set));
- num = sys_select(FD_SETSIZE,&lfds,NULL);
+ 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;
}
/****************************************************************************
- reload the services file
- **************************************************************************/
+ Reload the services file.
+**************************************************************************/
+
BOOL reload_services(BOOL test)
{
BOOL ret;
}
}
- reset_mangled_cache();
+ mangle_reset_cache();
reset_stat_cache();
/* this forces service parameters to be flushed */
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!
}
/****************************************************************************
-exit the server
+ Exit the server.
****************************************************************************/
+
void exit_server(char *reason)
{
static int firsttime=1;
}
/****************************************************************************
- initialise connect, service and file structs
+ Initialise connect, service and file structs.
****************************************************************************/
+
static void init_structs(void )
{
/*
}
/****************************************************************************
-usage on the program
+ Usage on the program.
****************************************************************************/
+
static void usage(char *pname)
{
}
/****************************************************************************
- main program
+ main program.
****************************************************************************/
+
int main(int argc,char *argv[])
{
extern BOOL append_log;
+ extern BOOL AllowDebugChange;
extern char *optarg;
/* shall I run as a daemon */
BOOL is_daemon = False;
DEBUGLEVEL = 10000;
else
DEBUGLEVEL = atoi(optarg);
+ AllowDebugChange = False;
break;
case 'p':
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);
* 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 */
}
#endif
-#ifdef WITH_SSL
- {
- extern BOOL sslEnabled;
- sslEnabled = lp_ssl_enabled();
- if(sslEnabled)
- sslutil_init(True);
- }
-#endif /* WITH_SSL */
-
fstrcpy(global_myworkgroup, lp_workgroup());
- CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
-
DEBUG(3,( "loaded services\n"));
if (!is_daemon && !is_a_socket(0)) {
- DEBUG(0,("standard input is not a socket, assuming -D option\n"));
+ if (!interactive)
+ DEBUG(0,("standard input is not a socket, assuming -D option\n"));
+
+ /*
+ * Setting is_daemon here prevents us from eventually calling
+ * the open_sockets_inetd()
+ */
+
is_daemon = True;
}
if (!init_oplocks())
exit(1);
- /* Setup mangle */
- if (!init_mangle_tdb())
- exit(1);
-
/* Setup change notify */
if (!init_change_notify())
exit(1);