cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=712f7e878bfe9b49890cd1d67f921f3f1cf5d74a

commit 712f7e878bfe9b49890cd1d67f921f3f1cf5d74a
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Tue Apr 18 16:55:31 2017 -0700

    ecore: use new API eina_file_close_on_exec.
---
 src/lib/ecore/ecore_anim.c       |  4 ++--
 src/lib/ecore/ecore_exe_posix.c  | 26 +++++++++++++-------------
 src/lib/ecore/ecore_main.c       | 19 ++-----------------
 src/lib/ecore/ecore_pipe.c       |  6 +++---
 src/lib/ecore/ecore_private.h    |  2 --
 src/lib/ecore/efl_io_closer_fd.c | 13 +------------
 6 files changed, 21 insertions(+), 49 deletions(-)

diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c
index 84e31e1..47282c7 100644
--- a/src/lib/ecore/ecore_anim.c
+++ b/src/lib/ecore/ecore_anim.c
@@ -165,7 +165,7 @@ _timer_tick_core(void *data EINA_UNUSED, Ecore_Thread 
*thread)
 
 #ifdef HAVE_EPOLL
    pollfd = epoll_create(1);
-   if (pollfd >= 0) _ecore_fd_close_on_exec(pollfd);
+   if (pollfd >= 0) eina_file_close_on_exec(pollfd, EINA_TRUE);
 
 #if defined(TFD_NONBLOCK) && defined(TFD_CLOEXEC)
    timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
@@ -173,7 +173,7 @@ _timer_tick_core(void *data EINA_UNUSED, Ecore_Thread 
*thread)
    if (timerfd < 0)
      {
         timerfd = timerfd_create(CLOCK_MONOTONIC, 0);
-        if (timerfd >= 0) _ecore_fd_close_on_exec(timerfd);
+        if (timerfd >= 0) eina_file_close_on_exec(timerfd, EINA_TRUE);
      }
    if (timerfd < 0)
      {
diff --git a/src/lib/ecore/ecore_exe_posix.c b/src/lib/ecore/ecore_exe_posix.c
index d6683a2..f30ff7a 100644
--- a/src/lib/ecore/ecore_exe_posix.c
+++ b/src/lib/ecore/ecore_exe_posix.c
@@ -339,7 +339,7 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, Ecore_Exe_Data 
*exe)
          {
             /* Setup the status pipe. */
              E_NO_ERRNO(result, close(statusPipe[0]), ok);
-             E_IF_NO_ERRNO(result, fcntl(statusPipe[1], F_SETFD, FD_CLOEXEC), 
ok) /* close on exec shows success */
+             E_IF_NO_ERRNO(result, eina_file_close_on_exec(statusPipe[1], 
EINA_TRUE), ok) /* close on exec shows success */
              {
                 /* Run the actual command. */
                  _ecore_exe_exec_it(exe_cmd, flags); /* no return */
@@ -422,12 +422,12 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, 
Ecore_Exe_Data *exe)
                                     O_NONBLOCK), ok) {
                 }
                 E_IF_NO_ERRNO(result,
-                              fcntl(exe->child_fd_error, F_SETFD,
-                                    FD_CLOEXEC), ok) {
+                              eina_file_close_on_exec(exe->child_fd_error, 
EINA_TRUE),
+                              ok) {
                 }
                 E_IF_NO_ERRNO(result,
-                              fcntl(exe->child_fd_error_x, F_SETFD,
-                                    FD_CLOEXEC), ok) {
+                              eina_file_close_on_exec(exe->child_fd_error_x, 
EINA_TRUE),
+                              ok) {
                 }
                 {
                    exe->error_fd_handler =
@@ -446,12 +446,12 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, 
Ecore_Exe_Data *exe)
                                     O_NONBLOCK), ok) {
                 }
                 E_IF_NO_ERRNO(result,
-                              fcntl(exe->child_fd_read, F_SETFD,
-                                    FD_CLOEXEC), ok) {
+                              eina_file_close_on_exec(exe->child_fd_read, 
EINA_TRUE),
+                              ok) {
                 }
                 E_IF_NO_ERRNO(result,
-                              fcntl(exe->child_fd_read_x, F_SETFD,
-                                    FD_CLOEXEC), ok) {
+                              eina_file_close_on_exec(exe->child_fd_read_x, 
EINA_TRUE),
+                              ok) {
                 }
                 {
                    exe->read_fd_handler =
@@ -470,12 +470,12 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, 
Ecore_Exe_Data *exe)
                                     O_NONBLOCK), ok) {
                 }
                 E_IF_NO_ERRNO(result,
-                              fcntl(exe->child_fd_write, F_SETFD,
-                                    FD_CLOEXEC), ok) {
+                              eina_file_close_on_exec(exe->child_fd_write, 
EINA_TRUE),
+                              ok) {
                 }
                 E_IF_NO_ERRNO(result,
-                              fcntl(exe->child_fd_write_x, F_SETFD,
-                                    FD_CLOEXEC), ok) {
+                              eina_file_close_on_exec(exe->child_fd_write_x, 
EINA_TRUE),
+                              ok) {
                 }
                 {
                    exe->write_fd_handler =
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index 758bad6..10011d9 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -326,21 +326,6 @@ static gboolean _ecore_glib_idle_enterer_called;
 static gboolean ecore_fds_ready;
 #endif
 
-void
-_ecore_fd_close_on_exec(int fd)
-{
-#ifdef HAVE_FCNTL
-   int flags;
-
-   flags = fcntl(fd, F_GETFD);
-   if (flags == -1) return;
-   flags |= FD_CLOEXEC;
-   if (fcntl(fd, F_SETFD, flags) == -1)  return;
-#else
-   (void) fd;
-#endif
-}
-
 #ifdef EFL_EXTRA_SANITY_CHECKS
 static inline void
 _ecore_fd_valid(void)
@@ -1042,7 +1027,7 @@ _ecore_main_loop_init(void)
    if ((epoll_fd < 0) && HAVE_EPOLL)
      WRN("Failed to create epoll fd!");
    epoll_pid = getpid();
-   _ecore_fd_close_on_exec(epoll_fd);
+   eina_file_close_on_exec(epoll_fd, EINA_TRUE);
 
    /* add polls on all our file descriptors */
    Ecore_Fd_Handler *fdh;
@@ -1148,7 +1133,7 @@ _ecore_main_loop_init(void)
           WRN("failed to create timer fd!");
         else
           {
-             _ecore_fd_close_on_exec(timer_fd);
+             eina_file_close_on_exec(timer_fd, EINA_TRUE);
              ecore_timer_fd.fd = timer_fd;
              ecore_timer_fd.events = G_IO_IN;
              ecore_timer_fd.revents = 0;
diff --git a/src/lib/ecore/ecore_pipe.c b/src/lib/ecore/ecore_pipe.c
index e9eca08..1dfb864 100644
--- a/src/lib/ecore/ecore_pipe.c
+++ b/src/lib/ecore/ecore_pipe.c
@@ -360,15 +360,15 @@ ecore_pipe_full_add(Ecore_Pipe_Cb handler,
    p->data = data;
 
    if (!read_survive_fork)
-     _ecore_fd_close_on_exec(fd_read);
+     eina_file_close_on_exec(fd_read, EINA_TRUE);
    if (!write_survive_fork)
-     _ecore_fd_close_on_exec(fd_write);
+     eina_file_close_on_exec(fd_write, EINA_TRUE);
 
 #if defined(HAVE_SYS_EPOLL_H) && defined(HAVE_SYS_TIMERFD_H)
    struct epoll_event pollev = { 0 };
    p->pollfd = epoll_create(1);
    p->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
-   _ecore_fd_close_on_exec(p->pollfd);
+   eina_file_close_on_exec(p->pollfd, EINA_TRUE);
 
    pollev.data.ptr = (void *)(uintptr_t)(p->fd_read);
    pollev.events = EPOLLIN;
diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h
index f810c6c..54daa5e 100644
--- a/src/lib/ecore/ecore_private.h
+++ b/src/lib/ecore/ecore_private.h
@@ -213,8 +213,6 @@ Ecore_Fd_Handler *
                                       Eina_Bool is_file);
 void      *_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
 
-void       _ecore_fd_close_on_exec(int fd);
-
 void       _ecore_main_shutdown(void);
 
 #if defined (_WIN32) || defined (__lv2ppu__) || defined (HAVE_EXOTIC)
diff --git a/src/lib/ecore/efl_io_closer_fd.c b/src/lib/ecore/efl_io_closer_fd.c
index eebc835..cc5fcf9 100644
--- a/src/lib/ecore/efl_io_closer_fd.c
+++ b/src/lib/ecore/efl_io_closer_fd.c
@@ -69,18 +69,7 @@ _efl_io_closer_fd_efl_io_closer_close_on_exec_set(Eo *o, 
Efl_Io_Closer_Fd_Data *
                                   * already set!
                                   */
 
-   flags = fcntl(fd, F_GETFD);
-   if (flags < 0)
-     {
-        ERR("fcntl(%d, F_GETFD): %s", fd, strerror(errno));
-        pd->close_on_exec = old;
-        return EINA_FALSE;
-     }
-   if (close_on_exec)
-     flags |= FD_CLOEXEC;
-   else
-     flags &= (~FD_CLOEXEC);
-   if (fcntl(fd, F_SETFD, flags) < 0)
+   if (!eina_file_close_on_exec(fd, close_on_exec))
      {
         ERR("fcntl(%d, F_SETFD, %#x): %s", fd, flags, strerror(errno));
         pd->close_on_exec = old;

-- 


Reply via email to