s4:lib/messaging: terminate the irpc_servers_byname() result with server_id_set_disco...
[Samba/gebeck_regimport.git] / source4 / smbd / process_model.c
blobbbcbe3b6acc789369efdcda80dab7b794c71b9df
1 /*
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/process_model.h"
23 #include "param/param.h"
24 #include "lib/util/samba_modules.h"
26 /* the list of currently registered process models */
27 static struct process_model {
28 const struct model_ops *ops;
29 bool initialised;
30 } *models = NULL;
31 static int num_models;
35 return the operations structure for a named backend of the specified type
37 static struct process_model *process_model_byname(const char *name)
39 int i;
41 for (i=0;i<num_models;i++) {
42 if (strcmp(models[i].ops->name, name) == 0) {
43 return &models[i];
47 return NULL;
52 setup the events for the chosen process model
54 _PUBLIC_ const struct model_ops *process_model_startup(const char *model)
56 struct process_model *m;
58 m = process_model_byname(model);
59 if (m == NULL) {
60 DEBUG(0,("Unknown process model '%s'\n", model));
61 exit(-1);
64 if (!m->initialised) {
65 m->initialised = true;
66 m->ops->model_init();
69 return m->ops;
73 register a process model.
75 The 'name' can be later used by other backends to find the operations
76 structure for this backend.
78 _PUBLIC_ NTSTATUS register_process_model(const struct model_ops *ops)
80 if (process_model_byname(ops->name) != NULL) {
81 /* its already registered! */
82 DEBUG(0,("PROCESS_MODEL '%s' already registered\n",
83 ops->name));
84 return NT_STATUS_OBJECT_NAME_COLLISION;
87 models = talloc_realloc(NULL, models, struct process_model, num_models+1);
88 if (!models) {
89 smb_panic("out of memory in register_process_model");
92 models[num_models].ops = ops;
93 models[num_models].initialised = false;
95 num_models++;
97 DEBUG(3,("PROCESS_MODEL '%s' registered\n", ops->name));
99 return NT_STATUS_OK;
102 _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
104 #define _MODULE_PROTO(init) extern NTSTATUS init(void);
105 STATIC_process_model_MODULES_PROTO;
106 init_module_fn static_init[] = { STATIC_process_model_MODULES };
107 init_module_fn *shared_init;
108 static bool initialised;
110 if (initialised) {
111 return NT_STATUS_OK;
113 initialised = true;
115 shared_init = load_samba_modules(NULL, "process_model");
117 run_init_functions(static_init);
118 run_init_functions(shared_init);
120 talloc_free(shared_init);
122 return NT_STATUS_OK;
126 return the PROCESS_MODEL module version, and the size of some critical types
127 This can be used by process model modules to either detect compilation errors, or provide
128 multiple implementations for different smbd compilation options in one module
130 const struct process_model_critical_sizes *process_model_version(void)
132 static const struct process_model_critical_sizes critical_sizes = {
133 PROCESS_MODEL_VERSION,
134 sizeof(struct model_ops)
137 return &critical_sizes;