From: Andrew Tridgell Date: Wed, 19 Sep 2007 01:46:37 +0000 (+1000) Subject: make sure we set close on exec on any possibly inherited fds X-Git-Tag: tevent-0.9.20~348^2~2399 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=81bfa58d58491e72019e3b0f5a4bda117a03a3e4;p=thirdparty%2Fsamba.git make sure we set close on exec on any possibly inherited fds (This used to be ctdb commit d9dec82076f14a348e7b67b4350180681ff86f32) --- diff --git a/ctdb/lib/events/events_epoll.c b/ctdb/lib/events/events_epoll.c index 5e1c1417c86..d10eb79ea78 100644 --- a/ctdb/lib/events/events_epoll.c +++ b/ctdb/lib/events/events_epoll.c @@ -90,7 +90,14 @@ static int epoll_ctx_destructor(struct epoll_event_context *epoll_ev) */ static void epoll_init_ctx(struct epoll_event_context *epoll_ev) { + unsigned v; + epoll_ev->epoll_fd = epoll_create(64); + + /* on exec, don't inherit the fd */ + v = fcntl(epoll_ev->epoll_fd, F_GETFD, 0); + fcntl(epoll_ev->epoll_fd, F_SETFD, v | FD_CLOEXEC); + epoll_ev->pid = getpid(); talloc_set_destructor(epoll_ev, epoll_ctx_destructor); } @@ -105,6 +112,7 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct fd_even static void epoll_check_reopen(struct epoll_event_context *epoll_ev) { struct fd_event *fde; + unsigned v; if (epoll_ev->pid == getpid()) { return; @@ -116,6 +124,11 @@ static void epoll_check_reopen(struct epoll_event_context *epoll_ev) DEBUG(0,("Failed to recreate epoll handle after fork\n")); return; } + + /* on exec, don't inherit the fd */ + v = fcntl(epoll_ev->epoll_fd, F_GETFD, 0); + fcntl(epoll_ev->epoll_fd, F_SETFD, v | FD_CLOEXEC); + epoll_ev->pid = getpid(); for (fde=epoll_ev->fd_events;fde;fde=fde->next) { epoll_add_event(epoll_ev, fde); diff --git a/ctdb/lib/tdb/common/open.c b/ctdb/lib/tdb/common/open.c index 1985bb75f34..8ff2f105642 100644 --- a/ctdb/lib/tdb/common/open.c +++ b/ctdb/lib/tdb/common/open.c @@ -138,6 +138,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, int rev = 0, locked = 0; unsigned char *vp; u32 vertest; + unsigned v; if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) { /* Can't log this */ @@ -197,6 +198,10 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, goto fail; /* errno set by open(2) */ } + /* on exec, don't inherit the fd */ + v = fcntl(tdb->fd, F_GETFD, 0); + fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC); + /* ensure there is only one process initialising at once */ if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0, 1) == -1) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to get global lock on %s: %s\n", diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index a07f5235026..c79c85d4e7d 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -661,6 +661,8 @@ bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep) return false; } + set_close_on_exec(ctdb->recovery_lock_fd); + lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0;