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 static void exit_server(const char *reason)
28 DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
32 /****************************************************************************
34 ****************************************************************************/
35 static int binary_smbd_main(int argc,const char *argv[])
37 BOOL is_daemon = False;
38 BOOL interactive = False;
40 BOOL log_stdout = False;
43 struct server_context *srv_ctx;
44 const char *model = "standard";
45 struct poptOption long_options[] = {
48 {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" , NULL },
49 {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)", NULL},
50 {"foreground", 'F', POPT_ARG_VAL, &Fork, True, "Run daemon in foreground (for daemontools & etc)" , NULL },
51 {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout", NULL },
52 {"port", 'p', POPT_ARG_STRING, NULL, 0, "Listen on the specified ports", "PORTS"},
53 {"model", 'M', POPT_ARG_STRING, &model, True, "Select process model", "MODEL"},
57 pc = poptGetContext("smbd", argc, argv, long_options, 0);
59 while((opt = poptGetNextOpt(pc)) != -1) {
62 lp_set_cmdline("smb ports", poptGetOptArg(pc));
73 if (log_stdout && Fork) {
74 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
77 setup_logging(argv[0], log_stdout?DEBUG_STDOUT:DEBUG_FILE);
79 fault_setup((void (*)(void *))exit_server);
81 /* we are never interested in SIGPIPE */
82 BlockSignals(True,SIGPIPE);
85 /* we are never interested in SIGFPE */
86 BlockSignals(True,SIGFPE);
90 /* We are no longer interested in USR2 */
91 BlockSignals(True,SIGUSR2);
94 /* POSIX demands that signals are inherited. If the invoking process has
95 * these signals masked, we will have problems, as we won't recieve them. */
96 BlockSignals(False, SIGHUP);
97 BlockSignals(False, SIGUSR1);
98 BlockSignals(False, SIGTERM);
100 /* we want total control over the permissions on created files,
101 so set our umask to 0 */
106 DEBUG(0,("smbd version %s started.\n", SAMBA_VERSION_STRING));
107 DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2004\n"));
109 if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || sizeof(uint64_t) < 8) {
110 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
114 if (!reload_services(NULL, False))
117 if (!is_daemon && !is_a_socket(0)) {
119 DEBUG(0,("standard input is not a socket, assuming -D option\n"));
122 * Setting is_daemon here prevents us from eventually calling
123 * the open_sockets_inetd()
129 if (is_daemon && !interactive) {
130 DEBUG(3,("Becoming a daemon.\n"));
134 if (!directory_exist(lp_lockdir(), NULL)) {
135 mkdir(lp_lockdir(), 0755);
139 pidfile_create("smbd");
144 DEBUG(0,("Using %s process model\n", model));
145 srv_ctx = server_service_startup(model);
147 DEBUG(0,("Starting Services failed.\n"));
151 /* wait for events */
152 return event_loop_wait(srv_ctx->events);
155 int main(int argc, const char *argv[])
157 return binary_smbd_main(argc, argv);