2 Unix SMB/CIFS implementation.
3 Main SMB server routines
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Martin Pool 2002
6 Copyright (C) Jelmer Vernooij 2002
7 Copyright (C) James J Myers 2003 <myersjj@samba.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "lib/cmdline/popt_common.h"
28 /****************************************************************************
30 ****************************************************************************/
31 static int binary_smbd_main(int argc,const char *argv[])
33 BOOL is_daemon = False;
34 BOOL interactive = False;
36 BOOL log_stdout = False;
39 struct server_context *server;
40 const char *model = "standard";
41 struct poptOption long_options[] = {
44 {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" , NULL },
45 {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)", NULL},
46 {"foreground", 'F', POPT_ARG_VAL, &Fork, True, "Run daemon in foreground (for daemontools & etc)" , NULL },
47 {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout", NULL },
48 {"port", 'p', POPT_ARG_STRING, NULL, 0, "Listen on the specified ports", "PORTS"},
49 {"model", 'M', POPT_ARG_STRING, &model, True, "Select process model", "MODEL"},
54 pc = poptGetContext("smbd", argc, argv, long_options, 0);
56 while((opt = poptGetNextOpt(pc)) != -1) {
59 lp_set_cmdline("smb ports", poptGetOptArg(pc));
70 if (log_stdout && Fork) {
71 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
74 setup_logging(argv[0], log_stdout?DEBUG_STDOUT:DEBUG_FILE);
78 /* we are never interested in SIGPIPE */
79 BlockSignals(True,SIGPIPE);
82 /* we are never interested in SIGFPE */
83 BlockSignals(True,SIGFPE);
87 /* We are no longer interested in USR2 */
88 BlockSignals(True,SIGUSR2);
91 /* POSIX demands that signals are inherited. If the invoking process has
92 * these signals masked, we will have problems, as we won't recieve them. */
93 BlockSignals(False, SIGHUP);
94 BlockSignals(False, SIGUSR1);
95 BlockSignals(False, SIGTERM);
97 /* we want total control over the permissions on created files,
98 so set our umask to 0 */
103 DEBUG(0,("smbd version %s started.\n", SAMBA_VERSION_STRING));
104 DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2005\n"));
106 if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || sizeof(uint64_t) < 8) {
107 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
111 if (!reload_services(NULL, False))
114 if (!is_daemon && !is_a_socket(0)) {
116 DEBUG(0,("standard input is not a socket, assuming -D option\n"));
119 * Setting is_daemon here prevents us from eventually calling
120 * the open_sockets_inetd()
126 if (is_daemon && !interactive) {
127 DEBUG(3,("Becoming a daemon.\n"));
131 if (!directory_exist(lp_lockdir(), NULL)) {
132 mkdir(lp_lockdir(), 0755);
136 pidfile_create("smbd");
143 DEBUG(0,("Using %s process model\n", model));
144 server = server_service_startup(model, lp_server_services());
146 DEBUG(0,("Starting Services failed.\n"));
150 /* wait for events */
151 event_loop_wait(server->event.ctx);
153 server_service_shutdown(server, "exit");
158 int main(int argc, const char *argv[])
160 return binary_smbd_main(argc, argv);