Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/smbd/process_model.c

    r414 r745  
    2323#include "param/param.h"
    2424
    25 static const struct model_ops *process_model_byname(const char *name);
     25/* the list of currently registered process models */
     26static struct process_model {
     27        const struct model_ops *ops;
     28        bool initialised;
     29} *models = NULL;
     30static int num_models;
     31
     32
     33/*
     34  return the operations structure for a named backend of the specified type
     35*/
     36static struct process_model *process_model_byname(const char *name)
     37{
     38        int i;
     39
     40        for (i=0;i<num_models;i++) {
     41                if (strcmp(models[i].ops->name, name) == 0) {
     42                        return &models[i];
     43                }
     44        }
     45
     46        return NULL;
     47}
     48
    2649
    2750/*
    2851  setup the events for the chosen process model
    2952*/
    30 _PUBLIC_ const struct model_ops *process_model_startup(struct tevent_context *ev, const char *model)
     53_PUBLIC_ const struct model_ops *process_model_startup(const char *model)
    3154{
    32         const struct model_ops *ops;
     55        struct process_model *m;
    3356
    34         ops = process_model_byname(model);
    35         if (!ops) {
     57        m = process_model_byname(model);
     58        if (m == NULL) {
    3659                DEBUG(0,("Unknown process model '%s'\n", model));
    3760                exit(-1);
    3861        }
    3962
    40         ops->model_init(ev);
     63        if (!m->initialised) {
     64                m->initialised = true;
     65                m->ops->model_init();
     66        }
    4167
    42         return ops;
     68        return m->ops;
    4369}
    44 
    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;
    5070
    5171/*
     
    5575  structure for this backend. 
    5676*/
    57 _PUBLIC_ NTSTATUS register_process_model(const void *_ops)
     77_PUBLIC_ NTSTATUS register_process_model(const struct model_ops *ops)
    5878{
    59         const struct model_ops *ops = _ops;
    60 
    6179        if (process_model_byname(ops->name) != NULL) {
    6280                /* its already registered! */
     
    6684        }
    6785
    68         models = realloc_p(models, struct process_model, num_models+1);
     86        models = talloc_realloc(NULL, models, struct process_model, num_models+1);
    6987        if (!models) {
    7088                smb_panic("out of memory in register_process_model");
    7189        }
    7290
    73         models[num_models].ops = smb_xmemdup(ops, sizeof(*ops));
    74         models[num_models].ops->name = smb_xstrdup(ops->name);
     91        models[num_models].ops = ops;
     92        models[num_models].initialised = false;
    7593
    7694        num_models++;
    7795
    78         DEBUG(3,("PROCESS_MODEL '%s' registered\n",
    79                  ops->name));
     96        DEBUG(3,("PROCESS_MODEL '%s' registered\n", ops->name));
    8097
    8198        return NT_STATUS_OK;
     
    84101_PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
    85102{
    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);
     103#define _MODULE_PROTO(init) extern NTSTATUS init(void);
     104        STATIC_process_model_MODULES_PROTO;
    90105        init_module_fn static_init[] = { STATIC_process_model_MODULES };
    91         init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "process_model");
     106        init_module_fn *shared_init;
     107        static bool initialised;
    92108
     109        if (initialised) {
     110                return NT_STATUS_OK;
     111        }
     112        initialised = true;
     113
     114        shared_init = load_samba_modules(NULL, lp_ctx, "process_model");
     115       
    93116        run_init_functions(static_init);
    94117        run_init_functions(shared_init);
    95118
    96119        talloc_free(shared_init);
    97        
     120
    98121        return NT_STATUS_OK;
    99 }
    100 
    101 /*
    102   return the operations structure for a named backend of the specified type
    103 */
    104 static const struct model_ops *process_model_byname(const char *name)
    105 {
    106         int i;
    107 
    108         for (i=0;i<num_models;i++) {
    109                 if (strcmp(models[i].ops->name, name) == 0) {
    110                         return models[i].ops;
    111                 }
    112         }
    113 
    114         return NULL;
    115122}
    116123
Note: See TracChangeset for help on using the changeset viewer.