r25446: Merge some changes I made on the way home from SFO:
[jelmer/samba4-debian.git] / source / smbd / process_model.c
index 121b35aba44b41d839a0656e4e619be373efe1b9..bb4d3a53bbfc1fb635ed7982bef75582e99d8c9e 100644 (file)
@@ -6,7 +6,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "smbd/process_model.h"
+#include "build.h"
+#include "param/param.h"
 
+/*
+  setup the events for the chosen process model
+*/
+_PUBLIC_ const struct model_ops *process_model_startup(struct event_context *ev, const char *model)
+{
+       const struct model_ops *ops;
+
+       ops = process_model_byname(model);
+       if (!ops) {
+               DEBUG(0,("Unknown process model '%s'\n", model));
+               exit(-1);
+       }
+
+       ops->model_init(ev);
+
+       return ops;
+}
 
 /* the list of currently registered process models */
-static struct {
+static struct process_model {
        struct model_ops *ops;
 } *models = NULL;
 static int num_models;
@@ -34,7 +53,7 @@ static int num_models;
   The 'name' can be later used by other backends to find the operations
   structure for this backend.  
 */
-static NTSTATUS register_process_model(void *_ops)
+_PUBLIC_ NTSTATUS register_process_model(const void *_ops)
 {
        const struct model_ops *ops = _ops;
 
@@ -45,7 +64,7 @@ static NTSTATUS register_process_model(void *_ops)
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
-       models = Realloc(models, sizeof(models[0]) * (num_models+1));
+       models = realloc_p(models, struct process_model, num_models+1);
        if (!models) {
                smb_panic("out of memory in register_process_model");
        }
@@ -61,6 +80,19 @@ static NTSTATUS register_process_model(void *_ops)
        return NT_STATUS_OK;
 }
 
+NTSTATUS process_model_init(void)
+{
+       init_module_fn static_init[] = STATIC_process_model_MODULES;
+       init_module_fn *shared_init = load_samba_modules(NULL, global_loadparm, "process_model");
+
+       run_init_functions(static_init);
+       run_init_functions(shared_init);
+
+       talloc_free(shared_init);
+       
+       return NT_STATUS_OK;
+}
+
 /*
   return the operations structure for a named backend of the specified type
 */
@@ -86,30 +118,8 @@ const struct process_model_critical_sizes *process_model_version(void)
 {
        static const struct process_model_critical_sizes critical_sizes = {
                PROCESS_MODEL_VERSION,
-               sizeof(struct model_ops),
-               sizeof(struct server_context),
-               sizeof(struct event_context),
-               sizeof(struct fd_event)
+               sizeof(struct model_ops)
        };
 
        return &critical_sizes;
 }
-
-/*
-  initialise the PROCESS_MODEL subsystem
-*/
-BOOL process_model_init(void)
-{
-       NTSTATUS status;
-
-       status = register_subsystem("process_model", register_process_model); 
-       if (!NT_STATUS_IS_OK(status)) {
-               return False;
-       }
-
-       /* FIXME: Perhaps panic if a basic process model, such as simple, fails to initialise? */
-       static_init_process_model;
-
-       DEBUG(3,("PROCESS subsystem version %d initialised\n", PROCESS_MODEL_VERSION));
-       return True;
-}