Merge branch 'master' of git://git.samba.org/samba
[kai/samba.git] / source4 / smbd / process_prefork.c
index 0d17e5301d44e6a7444cfaa5785bf9f6177424aa..721856bb468e4d7ba89c24d61c45afeca1a2e55b 100644 (file)
 
 #include "includes.h"
 #include "lib/events/events.h"
-#include "../tdb/include/tdb.h"
 #include "lib/socket/socket.h"
 #include "smbd/process_model.h"
 #include "param/secrets.h"
 #include "system/filesys.h"
 #include "cluster/cluster.h"
 #include "param/param.h"
+#include "lib/ldb_wrap.h"
 
 #ifdef HAVE_SETPROCTITLE
 #ifdef HAVE_SETPROCTITLE_H
@@ -49,17 +49,14 @@ static int none_setproctitle(const char *fmt, ...)
 /*
   called when the process model is selected
 */
-static void prefork_model_init(struct event_context *ev)
+static void prefork_model_init(struct tevent_context *ev)
 {
        signal(SIGCHLD, SIG_IGN);
 }
 
 static void prefork_reload_after_fork(void)
 {
-       /* tdb needs special fork handling */
-       if (tdb_reopen_all(1) == -1) {
-               DEBUG(0,("prefork_reload_after_fork: tdb_reopen_all failed.\n"));
-       }
+       ldb_wrap_fork_hook();
 
        /* Ensure that the forked children do not expose identical random streams */
        set_need_random_reseed();
@@ -68,13 +65,13 @@ static void prefork_reload_after_fork(void)
 /*
   called when a listening socket becomes readable. 
 */
-static void prefork_accept_connection(struct event_context *ev, 
+static void prefork_accept_connection(struct tevent_context *ev, 
                                      struct loadparm_context *lp_ctx,
                                      struct socket_context *listen_socket,
-                                      void (*new_conn)(struct event_context *,
+                                      void (*new_conn)(struct tevent_context *,
                                                        struct loadparm_context *, struct socket_context *, 
                                                        struct server_id , void *), 
-                                      void *private)
+                                      void *private_data)
 {
        NTSTATUS status;
        struct socket_context *connected_socket;
@@ -86,24 +83,24 @@ static void prefork_accept_connection(struct event_context *ev,
                return;
        }
 
-       talloc_steal(private, connected_socket);
+       talloc_steal(private_data, connected_socket);
 
-       new_conn(ev, lp_ctx, connected_socket, cluster_id(pid, socket_get_fd(connected_socket)), private);
+       new_conn(ev, lp_ctx, connected_socket, cluster_id(pid, socket_get_fd(connected_socket)), private_data);
 }
 
 /*
   called to create a new server task
 */
-static void prefork_new_task(struct event_context *ev, 
+static void prefork_new_task(struct tevent_context *ev, 
                             struct loadparm_context *lp_ctx,
                             const char *service_name,
-                            void (*new_task_fn)(struct event_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 
-                            void *private)
+                            void (*new_task_fn)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 
+                            void *private_data)
 {
        pid_t pid;
        int i, num_children;
 
-       struct event_context *ev2, *ev_parent;
+       struct tevent_context *ev2, *ev_parent;
 
        pid = fork();
 
@@ -117,10 +114,13 @@ static void prefork_new_task(struct event_context *ev,
        /* This is now the child code. We need a completely new event_context to work with */
        ev2 = s4_event_context_init(NULL);
 
+       /* setup this as the default context */
+       s4_event_context_set_default(ev2);
+
        /* the service has given us a private pointer that
           encapsulates the context it needs for this new connection -
           everything else will be freed */
-       talloc_steal(ev2, private);
+       talloc_steal(ev2, private_data);
 
        /* this will free all the listening sockets and all state that
           is not associated with this new connection */
@@ -131,7 +131,7 @@ static void prefork_new_task(struct event_context *ev,
        prefork_reload_after_fork();
 
        /* setup this new connection: process will bind to it's sockets etc */
-       new_task_fn(ev2, lp_ctx, cluster_id(pid, 0), private);
+       new_task_fn(ev2, lp_ctx, cluster_id(pid, 0), private_data);
 
        num_children = lp_parm_int(lp_ctx, NULL, "prefork children", service_name, 0);
        if (num_children == 0) {
@@ -174,7 +174,10 @@ static void prefork_new_task(struct event_context *ev,
        
        /* But we need a events system to handle reaping children */
        ev_parent = s4_event_context_init(NULL);
-       
+
+       /* setup this as the default context */
+       s4_event_context_set_default(ev_parent);
+
        /* TODO: Handle some events... */
        
        /* we can't return to the top level here, as that event context is gone,
@@ -189,13 +192,13 @@ static void prefork_new_task(struct event_context *ev,
 
 
 /* called when a task goes down */
-_NORETURN_ static void prefork_terminate(struct event_context *ev, const char *reason) 
+_NORETURN_ static void prefork_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason) 
 {
        DEBUG(2,("prefork_terminate: reason[%s]\n",reason));
 }
 
 /* called to set a title of a task or connection */
-static void prefork_set_title(struct event_context *ev, const char *title) 
+static void prefork_set_title(struct tevent_context *ev, const char *title) 
 {
        if (title) {
                setproctitle("%s", title);