messaging_dgm: Use messaging_dgm_forall in dgm_wipe
authorVolker Lendecke <vl@samba.org>
Mon, 16 Oct 2017 19:52:35 +0000 (21:52 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 4 Dec 2017 23:56:12 +0000 (00:56 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/messages_dgm.c

index 245d7bb064c540f08b4d931cb09f3d5179e298c4..b9cddc274c223b94a0792ce968e3460218c6343b 100644 (file)
@@ -1562,55 +1562,30 @@ int messaging_dgm_cleanup(pid_t pid)
        return 0;
 }
 
-int messaging_dgm_wipe(void)
+static int messaging_dgm_wipe_fn(pid_t pid, void *private_data)
 {
-       struct messaging_dgm_context *ctx = global_dgm_context;
-       DIR *msgdir;
-       struct dirent *dp;
-       pid_t our_pid = getpid();
+       pid_t *our_pid = (pid_t *)private_data;
        int ret;
 
-       if (ctx == NULL) {
-               return ENOTCONN;
+       if (pid == *our_pid) {
+               /*
+                * fcntl(F_GETLK) will succeed for ourselves, we hold
+                * that lock ourselves.
+                */
+               return 0;
        }
 
-       messaging_dgm_validate(ctx);
-
-       /*
-        * We scan the socket directory and not the lock directory. Otherwise
-        * we would race against messaging_dgm_lockfile_create's open(O_CREAT)
-        * and fcntl(SETLK).
-        */
+       ret = messaging_dgm_cleanup(pid);
+       DEBUG(10, ("messaging_dgm_cleanup(%lu) returned %s\n",
+                  (unsigned long)pid, ret ? strerror(ret) : "ok"));
 
-       msgdir = opendir(ctx->socket_dir.buf);
-       if (msgdir == NULL) {
-               return errno;
-       }
-
-       while ((dp = readdir(msgdir)) != NULL) {
-               unsigned long pid;
-
-               pid = strtoul(dp->d_name, NULL, 10);
-               if (pid == 0) {
-                       /*
-                        * . and .. and other malformed entries
-                        */
-                       continue;
-               }
-               if ((pid_t)pid == our_pid) {
-                       /*
-                        * fcntl(F_GETLK) will succeed for ourselves, we hold
-                        * that lock ourselves.
-                        */
-                       continue;
-               }
-
-               ret = messaging_dgm_cleanup(pid);
-               DEBUG(10, ("messaging_dgm_cleanup(%lu) returned %s\n",
-                          pid, ret ? strerror(ret) : "ok"));
-       }
-       closedir(msgdir);
+       return 0;
+}
 
+int messaging_dgm_wipe(void)
+{
+       pid_t pid = getpid();
+       messaging_dgm_forall(messaging_dgm_wipe_fn, &pid);
        return 0;
 }