s4-smbd: don't initialise process models more than once
authorAndrew Tridgell <tridge@samba.org>
Sat, 30 Oct 2010 00:24:15 +0000 (11:24 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sat, 30 Oct 2010 12:49:00 +0000 (23:49 +1100)
this also removes the event_context parameter from process model
initialisation. It isn't needed, and is confusing when a process model
init can be called from more than one place, possibly with different
event contexts.

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

18 files changed:
source4/dns_server/dns_server.c
source4/kdc/kdc.c
source4/ldap_server/ldap_server.c
source4/ntp_signd/ntp_signd.c
source4/rpc_server/service_rpc.c
source4/smb_server/smb_samba3.c
source4/smbd/process_model.c
source4/smbd/process_model.h
source4/smbd/process_onefork.c
source4/smbd/process_prefork.c
source4/smbd/process_single.c
source4/smbd/process_standard.c
source4/smbd/process_thread.c
source4/smbd/service.c
source4/torture/rpc/spoolss_notify.c
source4/web_server/web_server.c
source4/winbind/wb_server.c
source4/wrepl_server/wrepl_in_connection.c

index 635cd9507fa181f01b7e09d7165c2065a21d9528..8e37fc21d3d0b0d0daa7292f379d7171e396142b 100644 (file)
@@ -550,7 +550,7 @@ static NTSTATUS dns_startup_interfaces(struct dns_server *dns, struct loadparm_c
        /* within the dns task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
-       model_ops = process_model_startup(dns->task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) {
                DEBUG(0,("Can't find 'single' process model_ops\n"));
                return NT_STATUS_INTERNAL_ERROR;
index 3242258e23e899e6eaa2fcadff8fbc0d9e1b61c1..a4bab42920b393a0549ed31123ac4ab227b36440 100644 (file)
@@ -537,7 +537,7 @@ static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_c
        /* within the kdc task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
-       model_ops = process_model_startup(kdc->task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) {
                DEBUG(0,("Can't find 'single' process model_ops\n"));
                return NT_STATUS_INTERNAL_ERROR;
index ba5a268e8e2e837d2cc9653e919aa02a829e5673..38e89598833d81edbd809c8780f7950ad37caf3f 100644 (file)
@@ -899,7 +899,7 @@ static void ldapsrv_task_init(struct task_server *task)
        task_server_set_title(task, "task[ldapsrv]");
 
        /* run the ldap server as a single process */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) goto failed;
 
        ldap_service = talloc_zero(task, struct ldapsrv_service);
index ae3eeb93f754269ccf15bceb1a18b86fc1480e53..a0dd2d3065b8cd3ff682af82bfcb1d161b191070 100644 (file)
@@ -503,7 +503,7 @@ static void ntp_signd_task_init(struct task_server *task)
        /* within the ntp_signd task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) {
                DEBUG(0,("Can't find 'single' process model_ops\n"));
                return;
index 82d6d9be6eccbf5a310a0c187364aa739e97c062..dfe25b75c661a04d17faed9a7130f58d1bb4ed6e 100644 (file)
@@ -56,7 +56,7 @@ static void dcesrv_task_init(struct task_server *task)
 
        /* run the rpc server as a single process to allow for shard
         * handles, and sharing of ldb contexts */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) goto failed;
 
        status = dcesrv_init_context(task->event_ctx,
index 5af2ce50423b92dc7878708bd20bfd14023e364f..df85bcf90010c04d33621ab88a689e30c7577da6 100644 (file)
@@ -119,7 +119,7 @@ static void samba3_smb_task_init(struct task_server *task)
        NTSTATUS status;
        const struct model_ops *model_ops;
 
-       model_ops = process_model_startup(task->event_ctx, "standard");
+       model_ops = process_model_startup("standard");
 
        if (model_ops == NULL) {
                goto failed;
index d3f234eb41c921155bafdf33c2f9659ab4f4a842..0e636054609ffcb0e1f9d8493632fabd540e5491 100644 (file)
 #include "smbd/process_model.h"
 #include "param/param.h"
 
-static const struct model_ops *process_model_byname(const char *name);
+/* the list of currently registered process models */
+static struct process_model {
+       struct model_ops *ops;
+       bool initialised;
+} *models = NULL;
+static int num_models;
+
+
+/*
+  return the operations structure for a named backend of the specified type
+*/
+static struct process_model *process_model_byname(const char *name)
+{
+       int i;
+
+       for (i=0;i<num_models;i++) {
+               if (strcmp(models[i].ops->name, name) == 0) {
+                       return &models[i];
+               }
+       }
+
+       return NULL;
+}
+
 
 /*
   setup the events for the chosen process model
 */
-_PUBLIC_ const struct model_ops *process_model_startup(struct tevent_context *ev, const char *model)
+_PUBLIC_ const struct model_ops *process_model_startup(const char *model)
 {
-       const struct model_ops *ops;
+       struct process_model *m;
 
-       ops = process_model_byname(model);
-       if (!ops) {
+       m = process_model_byname(model);
+       if (m == NULL) {
                DEBUG(0,("Unknown process model '%s'\n", model));
                exit(-1);
        }
 
-       ops->model_init(ev);
+       if (!m->initialised) {
+               m->initialised = true;
+               m->ops->model_init();
+       }
 
-       return ops;
+       return m->ops;
 }
 
-/* the list of currently registered process models */
-static struct process_model {
-       struct model_ops *ops;
-} *models = NULL;
-static int num_models;
-
 /*
   register a process model. 
 
@@ -99,22 +119,6 @@ _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
        return NT_STATUS_OK;
 }
 
-/*
-  return the operations structure for a named backend of the specified type
-*/
-static const struct model_ops *process_model_byname(const char *name)
-{
-       int i;
-
-       for (i=0;i<num_models;i++) {
-               if (strcmp(models[i].ops->name, name) == 0) {
-                       return models[i].ops;
-               }
-       }
-
-       return NULL;
-}
-
 /*
   return the PROCESS_MODEL module version, and the size of some critical types
   This can be used by process model modules to either detect compilation errors, or provide
index 1d3e32eb341688e70ac38818c9782b927f1436aa..b5790316ec2e55a107c9ac5f46c96e63dbaea7c7 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "lib/socket/socket.h"
 #include "smbd/service.h"
+#include "smbd/process_model_proto.h"
 
 /* modules can use the following to determine if the interface has changed
  * please increment the version number after each interface change
@@ -41,7 +42,7 @@ struct model_ops {
        const char *name;
 
        /* called at startup when the model is selected */
-       void (*model_init)(struct tevent_context *);
+       void (*model_init)(void);
 
        /* function to accept new connection */
        void (*accept_connection)(struct tevent_context *, 
@@ -78,7 +79,7 @@ struct process_model_critical_sizes {
 
 extern const struct model_ops single_ops;
 
-const struct model_ops *process_model_startup(struct tevent_context *ev, const char *model);
+const struct model_ops *process_model_startup(const char *model);
 NTSTATUS register_process_model(const void *_ops);
 NTSTATUS process_model_init(struct loadparm_context *lp_ctx);
 
index b0e2e29bd6cbe1889c4f6ce259662a496e47dd65..da34f731641ef83888e8dc9db0481807b9f985d3 100644 (file)
@@ -49,7 +49,7 @@ static int none_setproctitle(const char *fmt, ...)
 /*
   called when the process model is selected
 */
-static void onefork_model_init(struct tevent_context *ev)
+static void onefork_model_init(void)
 {
        signal(SIGCHLD, SIG_IGN);
 }
index 64941dbeb5f244bd6786d04fe60143cef4fc0406..13404643814c3e4bb906e5309799e5605cfdfdf0 100644 (file)
@@ -49,7 +49,7 @@ static int none_setproctitle(const char *fmt, ...)
 /*
   called when the process model is selected
 */
-static void prefork_model_init(struct tevent_context *ev)
+static void prefork_model_init(void)
 {
        signal(SIGCHLD, SIG_IGN);
 }
index 688b46e0a01c831c03ed9655629ca9daa2335d7e..7678a912f982f864c91976bfb60770ccf0d83afe 100644 (file)
@@ -29,7 +29,7 @@
 /*
   called when the process model is selected
 */
-static void single_model_init(struct tevent_context *ev)
+static void single_model_init(void)
 {
 }
 
index 5ee8e6948d05b0ed899e2ae961c16ddd24272bb5..99e815a160b5bd3860f6eecbb69f8cd2fd2da336 100644 (file)
@@ -50,7 +50,7 @@ static int child_pipe[2];
 /*
   called when the process model is selected
 */
-static void standard_model_init(struct tevent_context *ev)
+static void standard_model_init(void)
 {
        pipe(child_pipe);
        signal(SIGCHLD, SIG_IGN);
index b169a79222c1ee5c3b68563559028ba58629ce49..cf94234c34f9d2abc36978c5e94a5278de5b5301 100644 (file)
@@ -511,7 +511,7 @@ static void thread_fault_handler(int sig)
 /*
   called when the process model is selected
 */
-static void thread_model_init(struct tevent_context *event_context)
+static void thread_model_init(void)
 {
        struct mutex_ops m_ops;
        struct debug_ops d_ops;
@@ -520,7 +520,7 @@ static void thread_model_init(struct tevent_context *event_context)
        ZERO_STRUCT(d_ops);
 
        pthread_key_create(&title_key, NULL);
-       pthread_setspecific(title_key, talloc_strdup(event_context, ""));
+       pthread_setspecific(title_key, NULL);
 
        /* register mutex/rwlock handlers */
        m_ops.mutex_init = thread_mutex_init;
index 7b53e9fa4e309ac55960be65b15927b1ef203ca1..9cdbbc28f3a1066afa9bc94d5f0ea9287c1fada5 100644 (file)
@@ -83,7 +83,7 @@ NTSTATUS server_service_startup(struct tevent_context *event_ctx,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       model_ops = process_model_startup(event_ctx, model);
+       model_ops = process_model_startup(model);
        if (!model_ops) {
                DEBUG(0,("process_model_startup('%s') failed\n", model));
                return NT_STATUS_INTERNAL_ERROR;
index 8e23637442e92a3503b407a1980d54b65f3c81a5..4608f1f09db8547c75e797c3143c0a67bf67189e 100644 (file)
@@ -460,7 +460,7 @@ static bool test_start_dcerpc_server(struct torture_context *tctx,
 
        torture_comment(tctx, "Listening for callbacks on %s\n", address);
 
-       status = smbsrv_add_socket(event_ctx, tctx->lp_ctx, &single_ops, address);
+       status = smbsrv_add_socket(event_ctx, tctx->lp_ctx, process_model_startup("single"), address);
        torture_assert_ntstatus_ok(tctx, status, "starting smb server");
 
        status = dcesrv_init_context(tctx, tctx->lp_ctx, endpoints, &dce_ctx);
@@ -469,7 +469,7 @@ static bool test_start_dcerpc_server(struct torture_context *tctx,
 
        for (e=dce_ctx->endpoint_list;e;e=e->next) {
                status = dcesrv_add_ep(dce_ctx, tctx->lp_ctx,
-                                      e, tctx->ev, &single_ops);
+                                      e, tctx->ev, process_model_startup("single"));
                torture_assert_ntstatus_ok(tctx, status,
                                "unable listen on dcerpc endpoint server");
        }
index f40f0a625bac815834e084b4b28e7a7059a5579c..97e65e5a475da7e658f4bb133e78866b47f38f8f 100644 (file)
@@ -307,7 +307,7 @@ static void websrv_task_init(struct task_server *task)
        task_server_set_title(task, "task[websrv]");
 
        /* run the web server as a single process */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) goto failed;
 
        if (lpcfg_interfaces(task->lp_ctx) && lpcfg_bind_interfaces_only(task->lp_ctx)) {
index 184b1162c121d25046950f5757c942d5aabc977a..34d145d318ef098f5715e8b3f0c4eb7b1ab4eb4d 100644 (file)
@@ -205,7 +205,7 @@ static void winbind_task_init(struct task_server *task)
        /* within the winbind task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) {
                task_server_terminate(task,
                                      "Can't find 'single' process model_ops", true);
index a32b842e04aa0f55bb83ee6ca03614af70782126..632c9a9a5b2e604f33caea60d583e36bfdac11ba 100644 (file)
@@ -357,7 +357,7 @@ NTSTATUS wreplsrv_in_connection_merge(struct wreplsrv_partner *partner,
        /* within the wrepl task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
-       model_ops = process_model_startup(service->task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) {
                DEBUG(0,("Can't find 'single' process model_ops"));
                return NT_STATUS_INTERNAL_ERROR;
@@ -430,7 +430,7 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar
        /* within the wrepl task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) {
                DEBUG(0,("Can't find 'single' process model_ops"));
                return NT_STATUS_INTERNAL_ERROR;