ctdb-common: Set close-on-exec when creating PID file
authorMartin Schwenke <martin@meltin.net>
Wed, 12 Jul 2017 03:41:17 +0000 (13:41 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 13 Jul 2017 11:30:23 +0000 (13:30 +0200)
Otherwise, for example, the file descriptor for the main PID file will
leak all the way down to event scripts.

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

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/pidfile.c

index b3f29e3f07d605f8a8fb00a755dd4a1e6beb61ce..51c0c25c92efd182a6c50a03d85dc35cf00ae3da 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <talloc.h>
 
+#include "lib/util/blocking.h"
+
 #include "common/pidfile.h"
 
 struct pidfile_context {
@@ -61,6 +63,12 @@ int pidfile_create(TALLOC_CTX *mem_ctx, const char *pidfile,
                goto fail;
        }
 
+       if (! set_close_on_exec(fd)) {
+               close(fd);
+               ret = EIO;
+               goto fail;
+       }
+
        pid_ctx->fd = fd;
 
        lck = (struct flock) {