From 695938b6332277031b8f55bef0c7ae79c3942d98 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 27 Apr 2021 18:03:57 +0200 Subject: [PATCH] lib: Add parent_watch_fd() Make the parent watcher pipe used in reinit_after_fork() available for external users that can't call reinit_after_fork(). Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/include/proto.h | 1 + source3/lib/util.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/source3/include/proto.h b/source3/include/proto.h index dd262529212..f9bffb3aa59 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -326,6 +326,7 @@ char *unix_clean_name(TALLOC_CTX *ctx, const char *s); char *clean_name(TALLOC_CTX *ctx, const char *s); ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, off_t pos); NTSTATUS init_before_fork(void); +int parent_watch_fd(void); NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx, struct tevent_context *ev_ctx, bool parent_longlived, diff --git a/source3/lib/util.c b/source3/lib/util.c index 0cd5c8e6698..1a0bc5003cd 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -21,6 +21,11 @@ along with this program. If not, see . */ +/** + * @brief Small functions that don't fit anywhere else + * @file util.c + */ + #include "includes.h" #include "system/passwd.h" #include "system/filesys.h" @@ -387,6 +392,20 @@ NTSTATUS init_before_fork(void) return NT_STATUS_OK; } +/** + * @brief Get a fd to watch for our parent process to exit + * + * Samba parent processes open a pipe that naturally closes when the + * parent exits. Child processes can watch the read end of the pipe + * for readability: Readability with 0 bytes to read means the parent + * has exited and the child process might also want to exit. + */ + +int parent_watch_fd(void) +{ + return reinit_after_fork_pipe[0]; +} + /** * Detect died parent by detecting EOF on the pipe */ -- 2.47.3