summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-09-22 14:55:55 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-09-22 14:57:15 -0700
commit17507bab43e18b3a29fb045302de6c4f88fef594 (patch)
treea160705cc8f5366d32d099fbe00d16eb4a7c72fd /src/lib/ecore
parent6232fa2a9bad08cdd5ec249b2a5624e0051c9480 (diff)
ecore: force initialization of Efl.Io.Closer.Fd.
This will prevent closing magically fd 0 when the object is not initialized yet.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_io_closer_fd.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/ecore/efl_io_closer_fd.c b/src/lib/ecore/efl_io_closer_fd.c
index 42724e0646..e55de422af 100644
--- a/src/lib/ecore/efl_io_closer_fd.c
+++ b/src/lib/ecore/efl_io_closer_fd.c
@@ -13,28 +13,43 @@
13typedef struct _Efl_Io_Closer_Fd_Data 13typedef struct _Efl_Io_Closer_Fd_Data
14{ 14{
15 int fd; 15 int fd;
16
16 Eina_Bool close_on_exec; 17 Eina_Bool close_on_exec;
17 Eina_Bool close_on_destructor; 18 Eina_Bool close_on_destructor;
19 Eina_Bool initialized;
18} Efl_Io_Closer_Fd_Data; 20} Efl_Io_Closer_Fd_Data;
19 21
22static void
23_efl_io_closer_initialize(Efl_Io_Closer_Fd_Data *pd)
24{
25 if (pd->initialized) return ;
26 pd->fd = -1;
27 pd->initialized = EINA_TRUE;
28}
29
20EOLIAN static void 30EOLIAN static void
21_efl_io_closer_fd_closer_fd_set(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd, int fd) 31_efl_io_closer_fd_closer_fd_set(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd, int fd)
22{ 32{
33 _efl_io_closer_initialize(pd);
23 pd->fd = fd; 34 pd->fd = fd;
24} 35}
25 36
26EOLIAN static int 37EOLIAN static int
27_efl_io_closer_fd_closer_fd_get(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd) 38_efl_io_closer_fd_closer_fd_get(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd)
28{ 39{
40 _efl_io_closer_initialize(pd);
29 return pd->fd; 41 return pd->fd;
30} 42}
31 43
32EOLIAN static Eina_Error 44EOLIAN static Eina_Error
33_efl_io_closer_fd_efl_io_closer_close(Eo *o, Efl_Io_Closer_Fd_Data *pd EINA_UNUSED) 45_efl_io_closer_fd_efl_io_closer_close(Eo *o, Efl_Io_Closer_Fd_Data *pd EINA_UNUSED)
34{ 46{
35 int fd = efl_io_closer_fd_get(o); 47 int fd;
36 Eina_Error err = 0; 48 Eina_Error err = 0;
37 49
50 _efl_io_closer_initialize(pd);
51 fd = efl_io_closer_fd_get(o);
52
38 EINA_SAFETY_ON_TRUE_RETURN_VAL(fd < 0, EBADF); 53 EINA_SAFETY_ON_TRUE_RETURN_VAL(fd < 0, EBADF);
39 54
40 efl_io_closer_fd_set(o, -1); 55 efl_io_closer_fd_set(o, -1);
@@ -46,12 +61,15 @@ _efl_io_closer_fd_efl_io_closer_close(Eo *o, Efl_Io_Closer_Fd_Data *pd EINA_UNUS
46EOLIAN static Eina_Bool 61EOLIAN static Eina_Bool
47_efl_io_closer_fd_efl_io_closer_closed_get(Eo *o, Efl_Io_Closer_Fd_Data *pd EINA_UNUSED) 62_efl_io_closer_fd_efl_io_closer_closed_get(Eo *o, Efl_Io_Closer_Fd_Data *pd EINA_UNUSED)
48{ 63{
64 _efl_io_closer_initialize(pd);
49 return efl_io_closer_fd_get(o) < 0; 65 return efl_io_closer_fd_get(o) < 0;
50} 66}
51 67
52EOLIAN static Eina_Bool 68EOLIAN static Eina_Bool
53_efl_io_closer_fd_efl_io_closer_close_on_exec_set(Eo *o, Efl_Io_Closer_Fd_Data *pd, Eina_Bool close_on_exec) 69_efl_io_closer_fd_efl_io_closer_close_on_exec_set(Eo *o, Efl_Io_Closer_Fd_Data *pd, Eina_Bool close_on_exec)
54{ 70{
71 _efl_io_closer_initialize(pd);
72
55#ifdef _WIN32 73#ifdef _WIN32
56 DBG("close on exec is not supported on windows"); 74 DBG("close on exec is not supported on windows");
57 pd->close_on_exec = close_on_exec; 75 pd->close_on_exec = close_on_exec;
@@ -83,6 +101,8 @@ _efl_io_closer_fd_efl_io_closer_close_on_exec_set(Eo *o, Efl_Io_Closer_Fd_Data *
83EOLIAN static Eina_Bool 101EOLIAN static Eina_Bool
84_efl_io_closer_fd_efl_io_closer_close_on_exec_get(Eo *o, Efl_Io_Closer_Fd_Data *pd) 102_efl_io_closer_fd_efl_io_closer_close_on_exec_get(Eo *o, Efl_Io_Closer_Fd_Data *pd)
85{ 103{
104 _efl_io_closer_initialize(pd);
105
86#ifdef _WIN32 106#ifdef _WIN32
87 return pd->close_on_exec; 107 return pd->close_on_exec;
88 (void)o; 108 (void)o;
@@ -110,12 +130,14 @@ _efl_io_closer_fd_efl_io_closer_close_on_exec_get(Eo *o, Efl_Io_Closer_Fd_Data *
110EOLIAN static void 130EOLIAN static void
111_efl_io_closer_fd_efl_io_closer_close_on_destructor_set(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd, Eina_Bool close_on_destructor) 131_efl_io_closer_fd_efl_io_closer_close_on_destructor_set(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd, Eina_Bool close_on_destructor)
112{ 132{
133 _efl_io_closer_initialize(pd);
113 pd->close_on_destructor = close_on_destructor; 134 pd->close_on_destructor = close_on_destructor;
114} 135}
115 136
116EOLIAN static Eina_Bool 137EOLIAN static Eina_Bool
117_efl_io_closer_fd_efl_io_closer_close_on_destructor_get(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd) 138_efl_io_closer_fd_efl_io_closer_close_on_destructor_get(Eo *o EINA_UNUSED, Efl_Io_Closer_Fd_Data *pd)
118{ 139{
140 _efl_io_closer_initialize(pd);
119 return pd->close_on_destructor; 141 return pd->close_on_destructor;
120} 142}
121 143