diff options
| author | Volker Lendecke <vl@samba.org> | 2014-04-10 22:07:11 +0200 |
|---|---|---|
| committer | Jeremy Allison <jra@samba.org> | 2014-04-23 22:33:09 +0200 |
| commit | 6874e4a0f2b2bce120f2eea4563239b90c968dd7 (patch) | |
| tree | 8f2065b4281ffe5b43f42a1e24da68c0bece06ba /source3/lib/messages_dgm.c | |
| parent | dac9b3d73f94e86acb3770bf5ca728f107505b0b (diff) | |
| download | samba-6874e4a0f2b2bce120f2eea4563239b90c968dd7.tar.gz samba-6874e4a0f2b2bce120f2eea4563239b90c968dd7.tar.xz samba-6874e4a0f2b2bce120f2eea4563239b90c968dd7.zip | |
messaging_dgm: Add messaging_dgm_wipe
This walks all sockets and wipes the left-overs
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/lib/messages_dgm.c')
| -rw-r--r-- | source3/lib/messages_dgm.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 8327f9d505..354dac3677 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -407,3 +407,57 @@ NTSTATUS messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) TALLOC_FREE(lockfile_name); return NT_STATUS_OK; } + +NTSTATUS messaging_dgm_wipe(struct messaging_context *msg_ctx) +{ + struct messaging_dgm_context *ctx = talloc_get_type_abort( + msg_ctx->local->private_data, struct messaging_dgm_context); + char *msgdir_name; + DIR *msgdir; + struct dirent *dp; + pid_t our_pid = getpid(); + + /* + * 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_name = talloc_asprintf(talloc_tos(), "%s/msg", ctx->cache_dir); + if (msgdir_name == NULL) { + return NT_STATUS_NO_MEMORY; + } + + msgdir = opendir(msgdir_name); + TALLOC_FREE(msgdir_name); + if (msgdir == NULL) { + return map_nt_error_from_unix(errno); + } + + while ((dp = readdir(msgdir)) != NULL) { + NTSTATUS status; + unsigned long pid; + + pid = strtoul(dp->d_name, NULL, 10); + if (pid == 0) { + /* + * . and .. and other malformed entries + */ + continue; + } + if (pid == our_pid) { + /* + * fcntl(F_GETLK) will succeed for ourselves, we hold + * that lock ourselves. + */ + continue; + } + + status = messaging_dgm_cleanup(msg_ctx, pid); + DEBUG(10, ("messaging_dgm_cleanup(%lu) returned %s\n", + pid, nt_errstr(status))); + } + closedir(msgdir); + + return NT_STATUS_OK; +} |
