winbind: Use forall_children in winbind_child_died()
authorVolker Lendecke <vl@samba.org>
Mon, 26 Feb 2018 11:59:06 +0000 (12:59 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 1 Mar 2018 08:53:45 +0000 (09:53 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13309

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/winbindd/winbindd_dual.c

index d3453346ef137e9a798decba1e21017c0a94e0e7..3c949d943f9e2f3f6203054fd4006df1908b2da5 100644 (file)
@@ -772,29 +772,42 @@ void setup_child(struct winbindd_domain *domain, struct winbindd_child *child,
        }
 }
 
-void winbind_child_died(pid_t pid)
-{
+struct winbind_child_died_state {
+       pid_t pid;
        struct winbindd_child *child;
+};
 
-       for (child = winbindd_children; child != NULL; child = child->next) {
-               if (child->pid == pid) {
-                       break;
-               }
+static bool winbind_child_died_fn(struct winbindd_child *child,
+                                 void *private_data)
+{
+       struct winbind_child_died_state *state = private_data;
+
+       if (child->pid == state->pid) {
+               state->child = child;
+               return false;
        }
+       return true;
+}
 
-       if (child == NULL) {
+void winbind_child_died(pid_t pid)
+{
+       struct winbind_child_died_state state = { .pid = pid };
+
+       forall_children(winbind_child_died_fn, &state);
+
+       if (state.child == NULL) {
                DEBUG(5, ("Already reaped child %u died\n", (unsigned int)pid));
                return;
        }
 
        /* This will be re-added in fork_domain_child() */
 
-       DLIST_REMOVE(winbindd_children, child);
-       child->pid = 0;
+       DLIST_REMOVE(winbindd_children, state.child);
+       state.child->pid = 0;
 
-       if (child->sock != -1) {
-               close(child->sock);
-               child->sock = -1;
+       if (state.child->sock != -1) {
+               close(state.child->sock);
+               state.child->sock = -1;
        }
 }