]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
messaging: Add messaging_dgm_forall
authorVolker Lendecke <vl@samba.org>
Fri, 21 Jul 2017 17:03:26 +0000 (19:03 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 4 Dec 2017 23:56:12 +0000 (00:56 +0100)
This factors out the traversal function from _wipe. It will be used to
replace message_send_all soon.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/messages_dgm.c
source3/lib/messages_dgm.h

index fd38839ae0f1787e5f72a68953747a066572d91b..245d7bb064c540f08b4d931cb09f3d5179e298c4 100644 (file)
@@ -1614,6 +1614,52 @@ int messaging_dgm_wipe(void)
        return 0;
 }
 
+int messaging_dgm_forall(int (*fn)(pid_t pid, void *private_data),
+                        void *private_data)
+{
+       struct messaging_dgm_context *ctx = global_dgm_context;
+       DIR *msgdir;
+       struct dirent *dp;
+
+       if (ctx == NULL) {
+               return ENOTCONN;
+       }
+
+       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).
+        */
+
+       msgdir = opendir(ctx->socket_dir.buf);
+       if (msgdir == NULL) {
+               return errno;
+       }
+
+       while ((dp = readdir(msgdir)) != NULL) {
+               unsigned long pid;
+               int ret;
+
+               pid = strtoul(dp->d_name, NULL, 10);
+               if (pid == 0) {
+                       /*
+                        * . and .. and other malformed entries
+                        */
+                       continue;
+               }
+
+               ret = fn(pid, private_data);
+               if (ret != 0) {
+                       break;
+               }
+       }
+       closedir(msgdir);
+
+       return 0;
+}
+
 struct messaging_dgm_fde {
        struct tevent_fd *fde;
 };
index ca11db1dacf1a516e06a3190e5f82c6d404687e5..7221c72660bbaa242ea46f9ff2b73f9c6360d996 100644 (file)
@@ -42,6 +42,8 @@ int messaging_dgm_send(pid_t pid,
                       const int *fds, size_t num_fds);
 int messaging_dgm_cleanup(pid_t pid);
 int messaging_dgm_wipe(void);
+int messaging_dgm_forall(int (*fn)(pid_t pid, void *private_data),
+                        void *private_data);
 
 struct messaging_dgm_fde;
 struct messaging_dgm_fde *messaging_dgm_register_tevent_context(