From b2893dfc77fc6bcf5c3a16d3dab30cafc3740d15 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Tue, 18 Apr 2017 16:54:03 -0700 Subject: [PATCH] eina: use new API eina_file_close_on_exec. --- src/lib/eina/eina_debug_monitor.c | 2 +- src/lib/eina/eina_file.c | 12 +----------- src/lib/eina/eina_mmap.c | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/lib/eina/eina_debug_monitor.c b/src/lib/eina/eina_debug_monitor.c index 1044d53..4188a03 100644 --- a/src/lib/eina/eina_debug_monitor.c +++ b/src/lib/eina/eina_debug_monitor.c @@ -682,7 +682,7 @@ _eina_debug_monitor_service_connect(void) fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) goto err; // set the socket to close when we exec things so they don't inherit it - if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto err; + if (!eina_file_close_on_exec(fd, EINA_TRUE)) goto err; // set up some socket options on addr re-use if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c index c378ea5..4a0c782 100644 --- a/src/lib/eina/eina_file.c +++ b/src/lib/eina/eina_file.c @@ -763,9 +763,6 @@ eina_file_open(const char *path, Eina_Bool shared) char *filename; struct stat file_stat; int fd = -1; -#ifdef HAVE_FCNTL - int flags; -#endif EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); @@ -783,15 +780,8 @@ eina_file_open(const char *path, Eina_Bool shared) if (fd < 0) goto on_error; -#ifdef HAVE_FCNTL - flags = fcntl(fd, F_GETFD); - if (flags == -1) - goto on_error; - - flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) + if (!eina_file_close_on_exec(fd, EINA_TRUE)) goto on_error; -#endif if (fstat(fd, &file_stat)) goto on_error; diff --git a/src/lib/eina/eina_mmap.c b/src/lib/eina/eina_mmap.c index 34a6f8d..7e7af0b 100644 --- a/src/lib/eina/eina_mmap.c +++ b/src/lib/eina/eina_mmap.c @@ -196,11 +196,7 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled) /* if we don;'t have one - fail to set up mmap safety */ if (_eina_mmap_zero_fd < 0) return EINA_FALSE; -#ifdef HAVE_FCNTL - flags = fcntl(_eina_mmap_zero_fd, F_GETFD); - flags |= FD_CLOEXEC; - fcntl(_eina_mmap_zero_fd, F_SETFD, flags); /* If this fail, it will just leak a fd to zero ... */ -#endif + eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE); } /* set up signal handler for SIGBUS */ sa.sa_sigaction = _eina_mmap_safe_sigbus; -- 2.7.4