s4:dsdb/repl Split the 'convert' or 'commit' stages in the DRS import
[Samba.git] / source4 / smbd / process_model.c
blobe3ea4dbf39d74ea91d4ba002fc0116bad1ac8c71
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"
25 static const struct model_ops *process_model_byname(const char *name);
28 setup the events for the chosen process model
30 _PUBLIC_ const struct model_ops *process_model_startup(struct tevent_context *ev, const char *model)
32 const struct model_ops *ops;
34 ops = process_model_byname(model);
35 if (!ops) {
36 DEBUG(0,("Unknown process model '%s'\n", model));
37 exit(-1);
40 ops->model_init(ev);
42 return ops;
45 /* the list of currently registered process models */
46 static struct process_model {
47 struct model_ops *ops;
48 } *models = NULL;
49 static int num_models;
52 register a process model.
54 The 'name' can be later used by other backends to find the operations
55 structure for this backend.
57 _PUBLIC_ NTSTATUS register_process_model(const void *_ops)
59 const struct model_ops *ops = _ops;
61 if (process_model_byname(ops->name) != NULL) {
62 /* its already registered! */
63 DEBUG(0,("PROCESS_MODEL '%s' already registered\n",
64 ops->name));
65 return NT_STATUS_OBJECT_NAME_COLLISION;
68 models = realloc_p(models, struct process_model, num_models+1);
69 if (!models) {
70 smb_panic("out of memory in register_process_model");
73 models[num_models].ops = smb_xmemdup(ops, sizeof(*ops));
74 models[num_models].ops->name = smb_xstrdup(ops->name);
76 num_models++;
78 DEBUG(3,("PROCESS_MODEL '%s' registered\n",
79 ops->name));
81 return NT_STATUS_OK;
84 _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
86 extern NTSTATUS process_model_thread_init(void);
87 extern NTSTATUS process_model_standard_init(void);
88 extern NTSTATUS process_model_prefork_init(void);
89 extern NTSTATUS process_model_single_init(void);
90 init_module_fn static_init[] = { STATIC_process_model_MODULES };
91 init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "process_model");
93 run_init_functions(static_init);
94 run_init_functions(shared_init);
96 talloc_free(shared_init);
98 return NT_STATUS_OK;
102 return the operations structure for a named backend of the specified type
104 static const struct model_ops *process_model_byname(const char *name)
106 int i;
108 for (i=0;i<num_models;i++) {
109 if (strcmp(models[i].ops->name, name) == 0) {
110 return models[i].ops;
114 return NULL;
118 return the PROCESS_MODEL module version, and the size of some critical types
119 This can be used by process model modules to either detect compilation errors, or provide
120 multiple implementations for different smbd compilation options in one module
122 const struct process_model_critical_sizes *process_model_version(void)
124 static const struct process_model_critical_sizes critical_sizes = {
125 PROCESS_MODEL_VERSION,
126 sizeof(struct model_ops)
129 return &critical_sizes;