TODO- s3:winbindd: use tevent_loop_wait() in the main loop
authorMichael Adam <obnox@samba.org>
Tue, 26 Feb 2013 16:38:14 +0000 (17:38 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 07:52:31 +0000 (09:52 +0200)
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

TODO: also child ...
TODO: let winbindd_tevent_trace_state be a stack variable,
      similar to 1d615ee923a2b46ffd7f943a9ba9e362b6322e5e
      and 9afc37bef4e60ea4a13db8ae68ba30d73b5b719c

source3/winbindd/winbindd.c
source3/winbindd/winbindd_dual.c

index 76d644b1ba60302ab6acf1820f729b71e73d105b..40709acbcc606afb3e90c2f4d83b8dae1bd19961 100644 (file)
@@ -1479,6 +1479,34 @@ static void winbindd_addr_changed(struct tevent_req *req)
        tevent_req_set_callback(req, winbindd_addr_changed, state);
 }
 
+
+struct winbindd_tevent_trace_state {
+       TALLOC_CTX *frame;
+};
+
+static void winbindd_tevent_trace_callback(enum tevent_trace_point point,
+                                          void *private_data)
+{
+       struct winbindd_tevent_trace_state *state =
+               talloc_get_type_abort(private_data,
+                                     struct winbindd_tevent_trace_state);
+
+       switch (point) {
+       case TEVENT_TRACE_BEFORE_WAIT:
+       case TEVENT_TRACE_AFTER_WAIT:
+               break;
+       case TEVENT_TRACE_BEFORE_LOOP_ONCE:
+               TALLOC_FREE(state->frame);
+               state->frame = talloc_stackframe();
+               errno = 0;
+               break;
+       case TEVENT_TRACE_AFTER_LOOP_ONCE:
+               TALLOC_FREE(state->frame);
+               break;
+       }
+}
+
+
 /* Main function */
 
 int main(int argc, const char **argv)
@@ -1509,6 +1537,9 @@ int main(int argc, const char **argv)
        TALLOC_CTX *frame;
        NTSTATUS status;
        bool ok;
+       int ret = 0;
+       struct tevent_context *ev_ctx = NULL;
+       struct winbindd_tevent_trace_state *trace_state = NULL;
 
        setproctitle_init(argc, discard_const(argv), environ);
 
@@ -1699,7 +1730,7 @@ int main(int argc, const char **argv)
        if (!init_names())
                exit(1);
 
-       load_interfaces();
+       load_interfaces();
 
        if (!secrets_init()) {
 
@@ -1798,17 +1829,34 @@ int main(int argc, const char **argv)
        gpupdate_init();
 
        /* Loop waiting for requests */
-       while (1) {
-               frame = talloc_stackframe();
 
-               if (tevent_loop_once(server_event_context()) == -1) {
-                       DEBUG(1, ("tevent_loop_once() failed: %s\n",
-                                 strerror(errno)));
-                       return 1;
-               }
+       ev_ctx = server_event_context();
+       if (ev_ctx == NULL) {
+               DEBUG(0, ("%s: winbind_event_context() failed\n",
+                         __location__));
+               exit(1);
+       }
 
-               TALLOC_FREE(frame);
+       trace_state = talloc_zero(ev_ctx, struct winbindd_tevent_trace_state);
+       if (trace_state == NULL) {
+               DEBUG(0, ("talloc_zero(winbindd_tevent_trace_state).\n"));
+               exit(1);
        }
 
+       trace_state->frame = frame;
+       frame = NULL;
+
+       tevent_set_trace_callback(ev_ctx, winbindd_tevent_trace_callback,
+                                 trace_state);
+
+       ret = tevent_loop_wait(ev_ctx);
+       if (ret != 0) {
+               DEBUG(0, ("tevent_loop_wait failed: %d, %s, exiting\n",
+                         ret, strerror(errno)));
+               exit(1);
+       }
+
+       TALLOC_FREE(trace_state->frame);
+
        return 0;
 }
index cff2c974deeee5c35a512b6d44afc4e6c589b65d..3874c1f68639dfe39d9ed1cd3636426cf69273a5 100644 (file)
@@ -1812,7 +1812,6 @@ static bool fork_domain_child(struct winbindd_child *child)
        while (1) {
 
                int ret;
-               TALLOC_CTX *frame = talloc_stackframe();
 
                ret = tevent_loop_once(server_event_context());
                if (ret != 0) {
@@ -1828,8 +1827,6 @@ static bool fork_domain_child(struct winbindd_child *child)
                                child->domain->name ));
                        child->domain->startup = False;
                }
-
-               TALLOC_FREE(frame);
        }
 }