2 Unix SMB/CIFS implementation.
3 process model manager - main loop
4 Copyright (C) Andrew Tridgell 1992-2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 setup the events for the chosen process model
27 void process_model_startup(struct event_context *events,
30 const struct model_ops *ops;
32 ops = process_model_byname(model);
34 DEBUG(0,("Unknown process model '%s'\n", model));
40 /* now setup the listening sockets, adding
41 event handlers to the events structure */
42 open_sockets_smbd(events, ops);
44 /* setup any sockets we need to listen on for RPC over TCP */
45 open_sockets_rpc(events, ops);
48 /* the list of currently registered process models */
50 struct model_ops *ops;
52 static int num_models;
55 register a process model.
57 The 'name' can be later used by other backends to find the operations
58 structure for this backend.
60 static NTSTATUS register_process_model(void *_ops)
62 const struct model_ops *ops = _ops;
64 if (process_model_byname(ops->name) != NULL) {
65 /* its already registered! */
66 DEBUG(0,("PROCESS_MODEL '%s' already registered\n",
68 return NT_STATUS_OBJECT_NAME_COLLISION;
71 models = Realloc(models, sizeof(models[0]) * (num_models+1));
73 smb_panic("out of memory in register_process_model");
76 models[num_models].ops = smb_xmemdup(ops, sizeof(*ops));
77 models[num_models].ops->name = smb_xstrdup(ops->name);
81 DEBUG(3,("PROCESS_MODEL '%s' registered\n",
88 return the operations structure for a named backend of the specified type
90 const struct model_ops *process_model_byname(const char *name)
94 for (i=0;i<num_models;i++) {
95 if (strcmp(models[i].ops->name, name) == 0) {
104 return the PROCESS_MODEL module version, and the size of some critical types
105 This can be used by process model modules to either detect compilation errors, or provide
106 multiple implementations for different smbd compilation options in one module
108 const struct process_model_critical_sizes *process_model_version(void)
110 static const struct process_model_critical_sizes critical_sizes = {
111 PROCESS_MODEL_VERSION,
112 sizeof(struct model_ops),
113 sizeof(struct smbsrv_context),
114 sizeof(struct event_context),
115 sizeof(struct fd_event)
118 return &critical_sizes;
122 initialise the PROCESS_MODEL subsystem
124 BOOL process_model_init(void)
128 status = register_subsystem("process_model", register_process_model);
129 if (!NT_STATUS_IS_OK(status)) {
133 /* FIXME: Perhaps panic if a basic process model, such as simple, fails to initialise? */
134 static_init_process_model;
136 DEBUG(3,("PROCESS subsystem version %d initialised\n", PROCESS_MODEL_VERSION));