]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Add parent_watch_fd()
authorVolker Lendecke <vl@samba.org>
Tue, 27 Apr 2021 16:03:57 +0000 (18:03 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 11 May 2021 22:56:37 +0000 (22:56 +0000)
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 <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/util.c

index dd2625292125809f8c4be5caaba7fe3d86dbacfb..f9bffb3aa59c9f716871fe842ae1b4bf9cc34b98 100644 (file)
@@ -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,
index 0cd5c8e6698dbcb052ddcaa8b7f214a6109087b2..1a0bc5003cd46dd320aaae67b889d3b411d07e76 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+/**
+ * @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
  */