summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-12-07 11:01:41 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-12-07 11:01:41 +0000
commit88ba56d9d539b5e5e87433b8b539cc69777a1025 (patch)
tree458dd66d1a79d02c73b18838e455cca5765bf6b6 /src/lib/ecore
parent931e4f9325098b259868ebfd18c08a0eabd73a66 (diff)
efl: don't leak fd on exec.
SVN revision: 80434
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/ecore_main.c22
-rw-r--r--src/lib/ecore/ecore_pipe.c3
-rw-r--r--src/lib/ecore/ecore_private.h2
3 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index cc7b0654a5..069283ac21 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -270,6 +270,26 @@ static gboolean _ecore_glib_idle_enterer_called;
270static gboolean ecore_fds_ready; 270static gboolean ecore_fds_ready;
271#endif 271#endif
272 272
273Eina_Bool
274_ecore_fd_close_on_exec(int fd)
275{
276#ifdef HAVE_EXECVP
277 int flags;
278
279 flags = fcntl(fd, F_GETFD);
280 if (flags == -1)
281 return EINA_FALSE;
282
283 flags |= FD_CLOEXEC;
284 if (fcntl(fd, F_SETFD, flags) == -1)
285 return EINA_FALSE;
286 return EINA_TRUE;
287#else
288 (void) fd;
289 return EINA_FALSE;
290#endif
291}
292
273static inline void 293static inline void
274_ecore_fd_valid(void) 294_ecore_fd_valid(void)
275{ 295{
@@ -754,6 +774,7 @@ _ecore_main_loop_init(void)
754 if (epoll_fd < 0) 774 if (epoll_fd < 0)
755 WRN("Failed to create epoll fd!"); 775 WRN("Failed to create epoll fd!");
756 epoll_pid = getpid(); 776 epoll_pid = getpid();
777 _ecore_fd_close_on_exec(epoll_fd);
757 778
758 /* add polls on all our file descriptors */ 779 /* add polls on all our file descriptors */
759 Ecore_Fd_Handler *fdh; 780 Ecore_Fd_Handler *fdh;
@@ -789,6 +810,7 @@ _ecore_main_loop_init(void)
789 WRN("failed to create timer fd!"); 810 WRN("failed to create timer fd!");
790 else 811 else
791 { 812 {
813 _ecore_fd_close_on_exec(timer_fd);
792 ecore_timer_fd.fd = timer_fd; 814 ecore_timer_fd.fd = timer_fd;
793 ecore_timer_fd.events = G_IO_IN; 815 ecore_timer_fd.events = G_IO_IN;
794 ecore_timer_fd.revents = 0; 816 ecore_timer_fd.revents = 0;
diff --git a/src/lib/ecore/ecore_pipe.c b/src/lib/ecore/ecore_pipe.c
index 3caf9781d0..de7e5f4e78 100644
--- a/src/lib/ecore/ecore_pipe.c
+++ b/src/lib/ecore/ecore_pipe.c
@@ -415,6 +415,9 @@ _ecore_pipe_add(Ecore_Pipe_Cb handler,
415 p->handler = handler; 415 p->handler = handler;
416 p->data = data; 416 p->data = data;
417 417
418 _ecore_fd_close_on_exec(fds[0]);
419 _ecore_fd_close_on_exec(fds[1]);
420
418 fcntl(p->fd_read, F_SETFL, O_NONBLOCK); 421 fcntl(p->fd_read, F_SETFL, O_NONBLOCK);
419 p->fd_handler = ecore_main_fd_handler_add(p->fd_read, 422 p->fd_handler = ecore_main_fd_handler_add(p->fd_read,
420 ECORE_FD_READ, 423 ECORE_FD_READ,
diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h
index a03dc9ed22..b9c11b5da8 100644
--- a/src/lib/ecore/ecore_private.h
+++ b/src/lib/ecore/ecore_private.h
@@ -186,6 +186,8 @@ Ecore_Fd_Handler *
186 const void *buf_data); 186 const void *buf_data);
187void *_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler); 187void *_ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
188 188
189Eina_Bool _ecore_fd_close_on_exec(int fd);
190
189void _ecore_main_shutdown(void); 191void _ecore_main_shutdown(void);
190 192
191#if defined (_WIN32) || defined (__lv2ppu__) || defined (HAVE_EXOTIC) 193#if defined (_WIN32) || defined (__lv2ppu__) || defined (HAVE_EXOTIC)