]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Set close-on-exec for startup fd
authorAmitay Isaacs <amitay@gmail.com>
Wed, 10 Oct 2018 07:16:33 +0000 (18:16 +1100)
committerKarolin Seeger <kseeger@samba.org>
Mon, 29 Oct 2018 08:26:13 +0000 (09:26 +0100)
The startup_fd should not be propagated to the child processes created
from a daemon.  It should only be used in the daemon code to return the
status of the startup.  Another use of startup_fd is to notify the
parent if the daemon process has exited.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13659

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
(cherry picked from commit 80549927bc1741a4b8af8b8e830de4d37fa0c4a8)

ctdb/common/sock_daemon.c
ctdb/common/sock_daemon.h

index 03d3ac1f1ec32416bc37b41eeb50cc7a08caf16b..86cc2f2e5026e3cc3c3d3e65aab03c8118bd273c 100644 (file)
@@ -517,9 +517,15 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd,
        return 0;
 }
 
-void sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd)
+bool sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd)
 {
+       if (! set_close_on_exec(fd)) {
+               D_ERR("Failed to set close-on-exec on startup fd\n");
+               return false;
+       }
+
        sockd->startup_fd = fd;
+       return true;
 }
 
 /*
index a28f8c6f39c1b4161d72e5902cbbee9e2347004a..fb0c686532874c8cb1e6613c110ab41fae3944e4 100644 (file)
@@ -214,8 +214,9 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd,
  *
  * @param[in] sockd Socket daemon context
  * @param[in] fd File descriptor
+ * @return true on success, false on error
  */
-void sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd);
+bool sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd);
 
 /**
  * @brief Async computation start to run a socket daemon