summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2017-04-18 16:55:31 -0700
committerCedric BAIL <cedric@osg.samsung.com>2017-04-18 16:55:31 -0700
commit712f7e878bfe9b49890cd1d67f921f3f1cf5d74a (patch)
treebd0249726554c92e3abbaf8cee3d5b6e38a7f7d4 /src/lib/ecore
parenta2094567c995349f68b41667dafa43c39968a77f (diff)
ecore: use new API eina_file_close_on_exec.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/ecore_anim.c4
-rw-r--r--src/lib/ecore/ecore_exe_posix.c26
-rw-r--r--src/lib/ecore/ecore_main.c19
-rw-r--r--src/lib/ecore/ecore_pipe.c6
-rw-r--r--src/lib/ecore/ecore_private.h2
-rw-r--r--src/lib/ecore/efl_io_closer_fd.c13
6 files changed, 21 insertions, 49 deletions
diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c
index 84e31e1a40..47282c7801 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)
165 165
166#ifdef HAVE_EPOLL 166#ifdef HAVE_EPOLL
167 pollfd = epoll_create(1); 167 pollfd = epoll_create(1);
168 if (pollfd >= 0) _ecore_fd_close_on_exec(pollfd); 168 if (pollfd >= 0) eina_file_close_on_exec(pollfd, EINA_TRUE);
169 169
170#if defined(TFD_NONBLOCK) && defined(TFD_CLOEXEC) 170#if defined(TFD_NONBLOCK) && defined(TFD_CLOEXEC)
171 timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); 171 timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
@@ -173,7 +173,7 @@ _timer_tick_core(void *data EINA_UNUSED, Ecore_Thread *thread)
173 if (timerfd < 0) 173 if (timerfd < 0)
174 { 174 {
175 timerfd = timerfd_create(CLOCK_MONOTONIC, 0); 175 timerfd = timerfd_create(CLOCK_MONOTONIC, 0);
176 if (timerfd >= 0) _ecore_fd_close_on_exec(timerfd); 176 if (timerfd >= 0) eina_file_close_on_exec(timerfd, EINA_TRUE);
177 } 177 }
178 if (timerfd < 0) 178 if (timerfd < 0)
179 { 179 {
diff --git a/src/lib/ecore/ecore_exe_posix.c b/src/lib/ecore/ecore_exe_posix.c
index d6683a26d7..f30ff7a8f5 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)
339 { 339 {
340 /* Setup the status pipe. */ 340 /* Setup the status pipe. */
341 E_NO_ERRNO(result, close(statusPipe[0]), ok); 341 E_NO_ERRNO(result, close(statusPipe[0]), ok);
342 E_IF_NO_ERRNO(result, fcntl(statusPipe[1], F_SETFD, FD_CLOEXEC), ok) /* close on exec shows success */ 342 E_IF_NO_ERRNO(result, eina_file_close_on_exec(statusPipe[1], EINA_TRUE), ok) /* close on exec shows success */
343 { 343 {
344 /* Run the actual command. */ 344 /* Run the actual command. */
345 _ecore_exe_exec_it(exe_cmd, flags); /* no return */ 345 _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)
422 O_NONBLOCK), ok) { 422 O_NONBLOCK), ok) {
423 } 423 }
424 E_IF_NO_ERRNO(result, 424 E_IF_NO_ERRNO(result,
425 fcntl(exe->child_fd_error, F_SETFD, 425 eina_file_close_on_exec(exe->child_fd_error, EINA_TRUE),
426 FD_CLOEXEC), ok) { 426 ok) {
427 } 427 }
428 E_IF_NO_ERRNO(result, 428 E_IF_NO_ERRNO(result,
429 fcntl(exe->child_fd_error_x, F_SETFD, 429 eina_file_close_on_exec(exe->child_fd_error_x, EINA_TRUE),
430 FD_CLOEXEC), ok) { 430 ok) {
431 } 431 }
432 { 432 {
433 exe->error_fd_handler = 433 exe->error_fd_handler =
@@ -446,12 +446,12 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, Ecore_Exe_Data *exe)
446 O_NONBLOCK), ok) { 446 O_NONBLOCK), ok) {
447 } 447 }
448 E_IF_NO_ERRNO(result, 448 E_IF_NO_ERRNO(result,
449 fcntl(exe->child_fd_read, F_SETFD, 449 eina_file_close_on_exec(exe->child_fd_read, EINA_TRUE),
450 FD_CLOEXEC), ok) { 450 ok) {
451 } 451 }
452 E_IF_NO_ERRNO(result, 452 E_IF_NO_ERRNO(result,
453 fcntl(exe->child_fd_read_x, F_SETFD, 453 eina_file_close_on_exec(exe->child_fd_read_x, EINA_TRUE),
454 FD_CLOEXEC), ok) { 454 ok) {
455 } 455 }
456 { 456 {
457 exe->read_fd_handler = 457 exe->read_fd_handler =
@@ -470,12 +470,12 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, Ecore_Exe_Data *exe)
470 O_NONBLOCK), ok) { 470 O_NONBLOCK), ok) {
471 } 471 }
472 E_IF_NO_ERRNO(result, 472 E_IF_NO_ERRNO(result,
473 fcntl(exe->child_fd_write, F_SETFD, 473 eina_file_close_on_exec(exe->child_fd_write, EINA_TRUE),
474 FD_CLOEXEC), ok) { 474 ok) {
475 } 475 }
476 E_IF_NO_ERRNO(result, 476 E_IF_NO_ERRNO(result,
477 fcntl(exe->child_fd_write_x, F_SETFD, 477 eina_file_close_on_exec(exe->child_fd_write_x, EINA_TRUE),
478 FD_CLOEXEC), ok) { 478 ok) {
479 } 479 }
480 { 480 {
481 exe->write_fd_handler = 481 exe->write_fd_handler =
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index 758bad624f..10011d9aff 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;
326static gboolean ecore_fds_ready; 326static gboolean ecore_fds_ready;
327#endif 327#endif
328 328
329void
330_ecore_fd_close_on_exec(int fd)
331{
332#ifdef HAVE_FCNTL
333 int flags;
334
335 flags = fcntl(fd, F_GETFD);
336 if (flags == -1) return;
337 flags |= FD_CLOEXEC;
338 if (fcntl(fd, F_SETFD, flags) == -1) return;
339#else
340 (void) fd;
341#endif
342}
343
344#ifdef EFL_EXTRA_SANITY_CHECKS 329#ifdef EFL_EXTRA_SANITY_CHECKS
345static inline void 330static inline void
346_ecore_fd_valid(void) 331_ecore_fd_valid(void)
@@ -1042,7 +1027,7 @@ _ecore_main_loop_init(void)
1042 if ((epoll_fd < 0) && HAVE_EPOLL) 1027 if ((epoll_fd < 0) && HAVE_EPOLL)
1043 WRN("Failed to create epoll fd!"); 1028 WRN("Failed to create epoll fd!");
1044 epoll_pid = getpid(); 1029 epoll_pid = getpid();
1045 _ecore_fd_close_on_exec(epoll_fd); 1030 eina_file_close_on_exec(epoll_fd, EINA_TRUE);
1046 1031
1047 /* add polls on all our file descriptors */ 1032 /* add polls on all our file descriptors */
1048 Ecore_Fd_Handler *fdh; 1033 Ecore_Fd_Handler *fdh;
@@ -1148,7 +1133,7 @@ _ecore_main_loop_init(void)
1148 WRN("failed to create timer fd!"); 1133 WRN("failed to create timer fd!");
1149 else 1134 else
1150 { 1135 {
1151 _ecore_fd_close_on_exec(timer_fd); 1136 eina_file_close_on_exec(timer_fd, EINA_TRUE);
1152 ecore_timer_fd.fd = timer_fd; 1137 ecore_timer_fd.fd = timer_fd;
1153 ecore_timer_fd.events = G_IO_IN; 1138 ecore_timer_fd.events = G_IO_IN;
1154 ecore_timer_fd.revents = 0; 1139 ecore_timer_fd.revents = 0;
diff --git a/src/lib/ecore/ecore_pipe.c b/src/lib/ecore/ecore_pipe.c
index e9eca08a0b..1dfb8640e4 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,
360 p->data = data; 360 p->data = data;
361 361
362 if (!read_survive_fork) 362 if (!read_survive_fork)
363 _ecore_fd_close_on_exec(fd_read); 363 eina_file_close_on_exec(fd_read, EINA_TRUE);
364 if (!write_survive_fork) 364 if (!write_survive_fork)
365 _ecore_fd_close_on_exec(fd_write); 365 eina_file_close_on_exec(fd_write, EINA_TRUE);
366 366
367#if defined(HAVE_SYS_EPOLL_H) && defined(HAVE_SYS_TIMERFD_H) 367#if defined(HAVE_SYS_EPOLL_H) && defined(HAVE_SYS_TIMERFD_H)
368 struct epoll_event pollev = { 0 }; 368 struct epoll_event pollev = { 0 };
369 p->pollfd = epoll_create(1); 369 p->pollfd = epoll_create(1);
370 p->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); 370 p->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
371 _ecore_fd_close_on_exec(p->pollfd); 371 eina_file_close_on_exec(p->pollfd, EINA_TRUE);
372 372
373 pollev.data.ptr = (void *)(uintptr_t)(p->fd_read); 373 pollev.data.ptr = (void *)(uintptr_t)(p->fd_read);
374 pollev.events = EPOLLIN; 374 pollev.events = EPOLLIN;
diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h
index f810c6c129..54daa5e30b 100644
--- a/src/lib/ecore/ecore_private.h
+++ b/src/lib/ecore/ecore_private.h
@@ -213,8 +213,6 @@ Ecore_Fd_Handler *
213 Eina_Bool is_file); 213 Eina_Bool is_file);
214void *_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler); 214void *_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
215 215
216void _ecore_fd_close_on_exec(int fd);
217
218void _ecore_main_shutdown(void); 216void _ecore_main_shutdown(void);
219 217
220#if defined (_WIN32) || defined (__lv2ppu__) || defined (HAVE_EXOTIC) 218#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 eebc835de4..cc5fcf9143 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 *
69 * already set! 69 * already set!
70 */ 70 */
71 71
72 flags = fcntl(fd, F_GETFD); 72 if (!eina_file_close_on_exec(fd, close_on_exec))
73 if (flags < 0)
74 {
75 ERR("fcntl(%d, F_GETFD): %s", fd, strerror(errno));
76 pd->close_on_exec = old;
77 return EINA_FALSE;
78 }
79 if (close_on_exec)
80 flags |= FD_CLOEXEC;
81 else
82 flags &= (~FD_CLOEXEC);
83 if (fcntl(fd, F_SETFD, flags) < 0)
84 { 73 {
85 ERR("fcntl(%d, F_SETFD, %#x): %s", fd, flags, strerror(errno)); 74 ERR("fcntl(%d, F_SETFD, %#x): %s", fd, flags, strerror(errno));
86 pd->close_on_exec = old; 75 pd->close_on_exec = old;