smbd: Move serverid_deregister() to the cleanupd
authorVolker Lendecke <vl@samba.org>
Fri, 6 Nov 2015 16:01:02 +0000 (17:01 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 16 Nov 2015 13:51:33 +0000 (14:51 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/server.c
source3/smbd/smbd_cleanupd.c

index ff259dd2d6edf06360528b46e2e2245a15d0d034..b83cfdd33f605d4e764495ffa4842f808c328060 100644 (file)
@@ -555,12 +555,9 @@ static void remove_child_pid(struct smbd_parent_context *parent,
                             bool unclean_shutdown)
 {
        struct smbd_child_pid *child;
-       struct server_id child_id;
        struct iovec iov[2];
        NTSTATUS status;
 
-       child_id = pid_to_procid(pid);
-
        iov[0] = (struct iovec) { .iov_base = (uint8_t *)&pid,
                                  .iov_len = sizeof(pid) };
        iov[1] = (struct iovec) { .iov_base = (uint8_t *)&unclean_shutdown,
@@ -605,11 +602,6 @@ static void remove_child_pid(struct smbd_parent_context *parent,
                        DEBUG(1,("Scheduled cleanup of brl and lock database after unclean shutdown\n"));
                }
        }
-
-       if (!serverid_deregister(child_id)) {
-               DEBUG(1, ("Could not remove pid %d from serverid.tdb\n",
-                         (int)pid));
-       }
 }
 
 /****************************************************************************
index 90a054f108664582096942a2ef94bbc0b93e714c..e931a28e8a98bac44ac05d3e58559f72de41b455 100644 (file)
 
 #include "replace.h"
 #include "smbd_cleanupd.h"
+#include "lib/util_procid.h"
 #include "lib/util/tevent_ntstatus.h"
 #include "lib/util/debug.h"
 #include "smbprofile.h"
+#include "serverid.h"
 
 struct smbd_cleanupd_state {
        pid_t parent_pid;
@@ -86,6 +88,7 @@ static void smbd_cleanupd_process_exited(struct messaging_context *msg,
        struct smbd_cleanupd_state *state = tevent_req_data(
                req, struct smbd_cleanupd_state);
        pid_t pid;
+       struct server_id child_id;
        bool unclean_shutdown;
        int ret;
 
@@ -101,6 +104,14 @@ static void smbd_cleanupd_process_exited(struct messaging_context *msg,
        DBG_DEBUG("%d exited %sclean\n", (int)pid,
                  unclean_shutdown ? "un" : "");
 
+       /*
+        * Get child_id before messaging_cleanup which wipes the
+        * unique_id. Not that it really matters here for functionality (the
+        * child should have properly cleaned up :-)) though, but it looks
+        * nicer.
+        */
+       child_id = pid_to_procid(pid);
+
        smbprofile_cleanup(pid, state->parent_pid);
 
        ret = messaging_cleanup(msg, pid);
@@ -108,6 +119,11 @@ static void smbd_cleanupd_process_exited(struct messaging_context *msg,
        if ((ret != 0) && (ret != ENOENT)) {
                DBG_DEBUG("messaging_cleanup returned %s\n", strerror(ret));
        }
+
+       if (!serverid_deregister(child_id)) {
+               DEBUG(1, ("Could not remove pid %d from serverid.tdb\n",
+                         (int)pid));
+       }
 }
 
 NTSTATUS smbd_cleanupd_recv(struct tevent_req *req)