From 3b022b19b77c3a159682b76998fa9ac9518e1c3c Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Mon, 4 Aug 2014 09:52:09 +0200 Subject: Use F_CLOSEM if available Use F_CLOSEM to close all file descriptors if available. BUG: 764655 Change-Id: Ib3c682825b89c163ebb152848f2533b3cb62cdce Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/8379 Tested-by: Gluster Build System Reviewed-by: Kaleb KEITHLEY Reviewed-by: Humble Devassy Chirammal Reviewed-by: Vijay Bellur --- contrib/uuid/gen_uuid.c | 7 +++++++ libglusterfs/src/run.c | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/contrib/uuid/gen_uuid.c b/contrib/uuid/gen_uuid.c index 79923cd542f..e69995ae557 100644 --- a/contrib/uuid/gen_uuid.c +++ b/contrib/uuid/gen_uuid.c @@ -465,6 +465,12 @@ static ssize_t read_all(int fd, char *buf, size_t count) #if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H) static void close_all_fds(void) { +#ifdef F_CLOSEM + (void)fcntl(0, F_CLOSEM); + (void)open("/dev/null", O_RDWR); /* stdin */ + (void)open("/dev/null", O_RDWR); /* stdout */ + (void)open("/dev/null", O_RDWR); /* stderr */ +#else /* F_CLOSEM */ int i, max; #if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX) @@ -485,6 +491,7 @@ static void close_all_fds(void) if (i <= 2) open("/dev/null", O_RDWR); } +#endif /* F_CLOSEM */ } #endif diff --git a/libglusterfs/src/run.c b/libglusterfs/src/run.c index 4fd2a3a0d79..93fe12aed10 100644 --- a/libglusterfs/src/run.c +++ b/libglusterfs/src/run.c @@ -289,7 +289,10 @@ runner_start (runner_t *runner) closedir (d); } else ret = -1; -#else +#else /* !GF_LINUX_HOST_OS */ +#ifdef F_CLOSEM /* NetBSD */ + (void)fcntl(3, F_CLOSEM); +#else /* !F_CLOSEM */ struct rlimit rl; ret = getrlimit (RLIMIT_NOFILE, &rl); GF_ASSERT (ret == 0); @@ -298,7 +301,8 @@ runner_start (runner_t *runner) if (i != xpi[1]) close (i); } -#endif +#endif /* !F_CLOSEM */ +#endif /* !GF_LINUX_HOST_OS */ } if (ret != -1) { -- cgit