From 05647d4723321081959dd02a5035419335b38c6e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 16 Oct 2017 21:52:35 +0200 Subject: [PATCH] messaging_dgm: Use messaging_dgm_forall in dgm_wipe Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/lib/messages_dgm.c | 59 +++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 245d7bb064c..b9cddc274c2 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -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; } -- 2.11.4.GIT