Rev 632: make sure we set close on exec on any possibly inherited fds in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Wed Sep 19 01:46:38 GMT 2007


------------------------------------------------------------
revno: 632
revision-id: tridge at samba.org-20070919014637-ugbcrhuu6n9aoss9
parent: tridge at samba.org-20070919014611-pz72rqcyedjygbfy
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Wed 2007-09-19 11:46:37 +1000
message:
  make sure we set close on exec on any possibly inherited fds
modified:
  lib/events/events_epoll.c      events_epoll.c-20070501213746-4fxluwiq4rcxib8p-2
  lib/tdb/common/open.c          open.c-20070220022425-m1wibgjq7n5hahs6-8
  server/ctdb_recover.c          ctdb_recover.c-20070503002147-admmfgt1oj6gexfo-1
=== modified file 'lib/events/events_epoll.c'
--- a/lib/events/events_epoll.c	2007-07-10 05:34:00 +0000
+++ b/lib/events/events_epoll.c	2007-09-19 01:46:37 +0000
@@ -90,7 +90,14 @@
 */
 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_check_reopen(struct epoll_event_context *epoll_ev)
 {
 	struct fd_event *fde;
+	unsigned v;
 
 	if (epoll_ev->pid == getpid()) {
 		return;
@@ -116,6 +124,11 @@
 		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);

=== modified file 'lib/tdb/common/open.c'
--- a/lib/tdb/common/open.c	2007-07-10 05:32:27 +0000
+++ b/lib/tdb/common/open.c	2007-09-19 01:46:37 +0000
@@ -138,6 +138,7 @@
 	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 @@
 		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",

=== modified file 'server/ctdb_recover.c'
--- a/server/ctdb_recover.c	2007-09-04 00:06:36 +0000
+++ b/server/ctdb_recover.c	2007-09-19 01:46:37 +0000
@@ -661,6 +661,8 @@
 		return false;
 	}
 
+	set_close_on_exec(ctdb->recovery_lock_fd);
+
 	lock.l_type = F_WRLCK;
 	lock.l_whence = SEEK_SET;
 	lock.l_start = 0;



More information about the samba-cvs mailing list