]> git.samba.org - samba.git/blob - source4/smbd/process_single.c
r23792: convert Samba4 to GPLv3
[samba.git] / source4 / smbd / process_single.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    process model: process (1 process handles all client connections)
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) James J Myers 2003 <myersjj@samba.org>
8    Copyright (C) Stefan (metze) Metzmacher 2004
9    
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.
14    
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.
19    
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/>.
22 */
23
24 #include "includes.h"
25 #include "smbd/process_model.h"
26 #include "system/filesys.h"
27 #include "cluster/cluster.h"
28
29 /*
30   called when the process model is selected
31 */
32 static void single_model_init(struct event_context *ev)
33 {
34 }
35
36 /*
37   called when a listening socket becomes readable. 
38 */
39 static void single_accept_connection(struct event_context *ev, 
40                                      struct socket_context *sock,
41                                      void (*new_conn)(struct event_context *, struct socket_context *, 
42                                                       struct server_id , void *), 
43                                      void *private)
44 {
45         NTSTATUS status;
46         struct socket_context *sock2;
47
48         /* accept an incoming connection. */
49         status = socket_accept(sock, &sock2);
50         if (!NT_STATUS_IS_OK(status)) {
51                 DEBUG(0,("single_accept_connection: accept: %s\n", nt_errstr(status)));
52                 /* this looks strange, but is correct. We need to
53                    throttle things until the system clears enough
54                    resources to handle this new socket. If we don't
55                    then we will spin filling the log and causing more
56                    problems. We don't panic as this is probably a
57                    temporary resource constraint */
58                 sleep(1);
59                 return;
60         }
61
62         talloc_steal(private, sock);
63
64         new_conn(ev, sock2, cluster_id(socket_get_fd(sock2)), private);
65 }
66
67 /*
68   called to startup a new task
69 */
70 static void single_new_task(struct event_context *ev, 
71                             void (*new_task)(struct event_context *, struct server_id, void *), 
72                             void *private)
73 {
74         static uint32_t taskid = 0x10000000;
75         new_task(ev, cluster_id(taskid++), private);
76 }
77
78
79 /* called when a task goes down */
80 static void single_terminate(struct event_context *ev, const char *reason) 
81 {
82         DEBUG(2,("single_terminate: reason[%s]\n",reason));
83 }
84
85 /* called to set a title of a task or connection */
86 static void single_set_title(struct event_context *ev, const char *title) 
87 {
88 }
89
90 static const struct model_ops single_ops = {
91         .name                   = "single",
92         .model_init             = single_model_init,
93         .new_task               = single_new_task,
94         .accept_connection      = single_accept_connection,
95         .terminate              = single_terminate,
96         .set_title              = single_set_title,
97 };
98
99 /*
100   initialise the single process model, registering ourselves with the
101   process model subsystem
102  */
103 NTSTATUS process_model_single_init(void)
104 {
105         return register_process_model(&single_ops);
106 }