From 2f3435085e0d6f64cd41b2d42e446da8821abc4b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 4 Jun 2014 14:42:46 +0000 Subject: [PATCH] messaging3: Make messaging_dgm_cleanup return 0/errno Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/include/messages.h | 2 +- source3/lib/messages_dgm.c | 26 ++++++++++++-------------- source3/smbd/server.c | 6 +++--- source3/utils/smbcontrol.c | 8 ++++++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/source3/include/messages.h b/source3/include/messages.h index 71b344a61e5..d826c11d8e9 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -76,7 +76,7 @@ struct messaging_backend { NTSTATUS messaging_dgm_init(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, struct messaging_backend **presult); -NTSTATUS messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid); +int messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid); NTSTATUS messaging_dgm_wipe(struct messaging_context *msg_ctx); void *messaging_dgm_register_tevent_context(TALLOC_CTX *mem_ctx, struct messaging_context *msg_ctx, diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index fb0419da5b0..1e6e9545e6d 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -368,7 +368,7 @@ static void messaging_dgm_recv(struct unix_msg_ctx *ctx, messaging_dispatch_rec(dgm_ctx->msg_ctx, &rec); } -NTSTATUS messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) +int messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) { struct messaging_backend *be = messaging_local_backend(msg_ctx); struct messaging_dgm_context *ctx = talloc_get_type_abort( @@ -376,26 +376,25 @@ NTSTATUS messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) char *lockfile_name, *socket_name; int fd, ret; struct flock lck = {}; - NTSTATUS status = NT_STATUS_OK; lockfile_name = talloc_asprintf(talloc_tos(), "%s/lck/%u", ctx->cache_dir, (unsigned)pid); if (lockfile_name == NULL) { - return NT_STATUS_NO_MEMORY; + return ENOMEM; } socket_name = talloc_asprintf(lockfile_name, "%s/msg/%u", ctx->cache_dir, (unsigned)pid); if (socket_name == NULL) { TALLOC_FREE(lockfile_name); - return NT_STATUS_NO_MEMORY; + return ENOMEM; } fd = open(lockfile_name, O_NONBLOCK|O_WRONLY, 0); if (fd == -1) { - status = map_nt_error_from_unix(errno); + ret = errno; DEBUG(10, ("%s: open(%s) failed: %s\n", __func__, - lockfile_name, strerror(errno))); - return status; + lockfile_name, strerror(ret))); + return ret; } lck.l_type = F_WRLCK; @@ -405,12 +404,12 @@ NTSTATUS messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) ret = fcntl(fd, F_SETLK, &lck); if (ret != 0) { - status = map_nt_error_from_unix(errno); + ret = errno; DEBUG(10, ("%s: Could not get lock: %s\n", __func__, - strerror(errno))); + strerror(ret))); TALLOC_FREE(lockfile_name); close(fd); - return status; + return ret; } (void)unlink(socket_name); @@ -418,7 +417,7 @@ NTSTATUS messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) (void)close(fd); TALLOC_FREE(lockfile_name); - return NT_STATUS_OK; + return 0; } NTSTATUS messaging_dgm_wipe(struct messaging_context *msg_ctx) @@ -449,7 +448,6 @@ NTSTATUS messaging_dgm_wipe(struct messaging_context *msg_ctx) } while ((dp = readdir(msgdir)) != NULL) { - NTSTATUS status; unsigned long pid; pid = strtoul(dp->d_name, NULL, 10); @@ -467,9 +465,9 @@ NTSTATUS messaging_dgm_wipe(struct messaging_context *msg_ctx) continue; } - status = messaging_dgm_cleanup(msg_ctx, pid); + ret = messaging_dgm_cleanup(msg_ctx, pid); DEBUG(10, ("messaging_dgm_cleanup(%lu) returned %s\n", - pid, nt_errstr(status))); + pid, ret ? strerror(ret) : "ok")); } closedir(msgdir); diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 53d615e4804..40684adae1c 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -445,13 +445,13 @@ static void remove_child_pid(struct smbd_parent_context *parent, { struct smbd_child_pid *child; struct server_id child_id; - NTSTATUS status; + int ret; child_id = pid_to_procid(pid); - status = messaging_dgm_cleanup(parent->msg_ctx, pid); + ret = messaging_dgm_cleanup(parent->msg_ctx, pid); DEBUG(10, ("%s: messaging_dgm_cleanup returned %s\n", - __func__, nt_errstr(status))); + __func__, ret ? strerror(ret) : "ok")); for (child = parent->children; child != NULL; child = child->next) { if (child->pid == pid) { diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 274de7077bc..d11adc666e5 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -973,10 +973,14 @@ static bool do_dgm_cleanup(struct tevent_context *ev_ctx, const struct server_id pid, const int argc, const char **argv) { - NTSTATUS status; + NTSTATUS status = NT_STATUS_OK; if (pid.pid != 0) { - status = messaging_dgm_cleanup(msg_ctx, pid.pid); + int ret; + ret = messaging_dgm_cleanup(msg_ctx, pid.pid); + if (ret != 0) { + status = map_nt_error_from_unix(ret); + } } else { status = messaging_dgm_wipe(msg_ctx); } -- 2.11.4.GIT