s4:lib/messaging: terminate the irpc_servers_byname() result with server_id_set_disco...
[Samba/gebeck_regimport.git] / source4 / smbd / process_single.c
blob742eac1824d4e834268b7a171090183bc6c9aba5
1 /*
2 Unix SMB/CIFS implementation.
4 process model: process (1 process handles all client connections)
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) James J Myers 2003 <myersjj@samba.org>
8 Copyright (C) Stefan (metze) Metzmacher 2004
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/process_model.h"
26 #include "system/filesys.h"
27 #include "cluster/cluster.h"
29 NTSTATUS process_model_single_init(void);
32 called when the process model is selected
34 static void single_model_init(void)
39 called when a listening socket becomes readable.
41 static void single_accept_connection(struct tevent_context *ev,
42 struct loadparm_context *lp_ctx,
43 struct socket_context *listen_socket,
44 void (*new_conn)(struct tevent_context *,
45 struct loadparm_context *,
46 struct socket_context *,
47 struct server_id , void *),
48 void *private_data)
50 NTSTATUS status;
51 struct socket_context *connected_socket;
53 /* accept an incoming connection. */
54 status = socket_accept(listen_socket, &connected_socket);
55 if (!NT_STATUS_IS_OK(status)) {
56 DEBUG(0,("single_accept_connection: accept: %s\n", nt_errstr(status)));
57 /* this looks strange, but is correct.
59 We can only be here if woken up from select, due to
60 an incoming connection.
62 We need to throttle things until the system clears
63 enough resources to handle this new socket.
65 If we don't then we will spin filling the log and
66 causing more problems. We don't panic as this is
67 probably a temporary resource constraint */
68 sleep(1);
69 return;
72 talloc_steal(private_data, connected_socket);
74 /* The cluster_id(0, fd) cannot collide with the incrementing
75 * task below, as the first component is 0, not 1 */
76 new_conn(ev, lp_ctx, connected_socket,
77 cluster_id(0, socket_get_fd(connected_socket)), private_data);
81 called to startup a new task
83 static void single_new_task(struct tevent_context *ev,
84 struct loadparm_context *lp_ctx,
85 const char *service_name,
86 void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *),
87 void *private_data)
89 /* start our taskids at 1, zero is reserved for the top
90 level samba task */
91 static uint32_t taskid = 1;
93 /* We use 1 so we cannot collide in with cluster ids generated
94 * in the accept connection above, and unlikly to collide with
95 * PIDs from process model standard (don't run samba as
96 * init) */
97 new_task(ev, lp_ctx, cluster_id(1, taskid++), private_data);
101 /* called when a task goes down */
102 static void single_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason)
104 DEBUG(3,("single_terminate: reason[%s]\n",reason));
107 /* called to set a title of a task or connection */
108 static void single_set_title(struct tevent_context *ev, const char *title)
112 const struct model_ops single_ops = {
113 .name = "single",
114 .model_init = single_model_init,
115 .new_task = single_new_task,
116 .accept_connection = single_accept_connection,
117 .terminate = single_terminate,
118 .set_title = single_set_title,
122 initialise the single process model, registering ourselves with the
123 process model subsystem
125 NTSTATUS process_model_single_init(void)
127 return register_process_model(&single_ops);