s3: messaging: Add infrastructure to clean up orphaned sockets every 15 minutes as...
authorVolker Lendecke <vl@samba.org>
Fri, 11 Apr 2014 11:08:56 +0000 (11:08 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 23 Apr 2014 20:33:09 +0000 (22:33 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/messages.h
source3/lib/messages.c

index 8a818db57b0f6cd5dab4dd501072bec5c80f3164..1681ec9ede322d1c672b3b66695213c0633fa017 100644 (file)
@@ -146,6 +146,8 @@ struct tevent_req *messaging_read_send(TALLOC_CTX *mem_ctx,
 int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                        struct messaging_rec **presult);
 
+bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg);
+
 #include "librpc/gen_ndr/ndr_messaging.h"
 
 #endif
index b4ed80754bd44258e518707d321254f1210360ed..b6fe4237bac5e51542c54b02156b7ce78ad5ffb3 100644 (file)
@@ -50,6 +50,7 @@
 #include "serverid.h"
 #include "messages.h"
 #include "lib/util/tevent_unix.h"
+#include "lib/background.h"
 
 struct messaging_callback {
        struct messaging_callback *prev, *next;
@@ -586,4 +587,53 @@ void messaging_dispatch_rec(struct messaging_context *msg_ctx,
        return;
 }
 
+static int mess_parent_dgm_cleanup(void *private_data);
+static void mess_parent_dgm_cleanup_done(struct tevent_req *req);
+
+bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg)
+{
+       struct tevent_req *req;
+
+       req = background_job_send(
+               msg, msg->event_ctx, msg, NULL, 0,
+               lp_parm_int(-1, "messaging", "messaging dgm cleanup interval", 60*15),
+               mess_parent_dgm_cleanup, msg);
+       if (req == NULL) {
+               return false;
+       }
+       tevent_req_set_callback(req, mess_parent_dgm_cleanup_done, msg);
+       return true;
+}
+
+static int mess_parent_dgm_cleanup(void *private_data)
+{
+       struct messaging_context *msg_ctx = talloc_get_type_abort(
+               private_data, struct messaging_context);
+       NTSTATUS status;
+
+       status = messaging_dgm_wipe(msg_ctx);
+       DEBUG(10, ("messaging_dgm_wipe returned %s\n", nt_errstr(status)));
+       return lp_parm_int(-1, "messaging", "messaging dgm cleanup interval", 60*15);
+}
+
+static void mess_parent_dgm_cleanup_done(struct tevent_req *req)
+{
+       struct messaging_context *msg = tevent_req_callback_data(
+               req, struct messaging_context);
+       NTSTATUS status;
+
+       status = background_job_recv(req);
+       TALLOC_FREE(req);
+       DEBUG(1, ("messaging dgm cleanup job ended with %s\n", nt_errstr(status)));
+
+       req = background_job_send(
+               msg, msg->event_ctx, msg, NULL, 0,
+               lp_parm_int(-1, "messaging", "messaging dgm cleanup interval", 60*15),
+               mess_parent_dgm_cleanup, msg);
+       if (req == NULL) {
+               DEBUG(1, ("background_job_send failed\n"));
+       }
+       tevent_req_set_callback(req, mess_parent_dgm_cleanup_done, msg);
+}
+
 /** @} **/