From: Volker Lendecke Date: Fri, 21 Jul 2017 17:03:26 +0000 (+0200) Subject: messaging: Add messaging_dgm_forall X-Git-Tag: talloc-2.1.11~300 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b5b999d2f324889827223fc3d0ac74a76530092;p=thirdparty%2Fsamba.git messaging: Add messaging_dgm_forall This factors out the traversal function from _wipe. It will be used to replace message_send_all soon. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index fd38839ae0f..245d7bb064c 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -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; }; diff --git a/source3/lib/messages_dgm.h b/source3/lib/messages_dgm.h index ca11db1dacf..7221c72660b 100644 --- a/source3/lib/messages_dgm.h +++ b/source3/lib/messages_dgm.h @@ -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(