summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--header_checks/meson.build14
-rw-r--r--src/lib/eina/eina_file.c21
-rw-r--r--src/lib/eina/eina_mmap.c6
3 files changed, 35 insertions, 6 deletions
diff --git a/header_checks/meson.build b/header_checks/meson.build
index ff5b21ee0c..4cc855e218 100644
--- a/header_checks/meson.build
+++ b/header_checks/meson.build
@@ -123,6 +123,20 @@ function_checks = [
123 ['dladdr', ['dlfcn.h'], ['dl'], '-D_GNU_SOURCE=1'] 123 ['dladdr', ['dlfcn.h'], ['dl'], '-D_GNU_SOURCE=1']
124] 124]
125 125
126open_cloexec = cc.run('''#include <sys/types.h>
127 #include <sys/stat.h>
128 #include <fcntl.h>
129 int main(int argc, char **argv) {
130 int res = open(argv[0], O_RDONLY | O_CLOEXEC);
131 if (res < 0) return 1;
132 return 0;
133 }
134 ''',
135 name : 'open works with O_CLOEXEC')
136if open_cloexec.compiled() and open_cloexec.returncode() == 0
137 config_h.set10('HAVE_OPEN_CLOEXEC', true)
138endif
139
126strerror_r_char_p = cc.compiles('''#define _GNU_SOURCE 140strerror_r_char_p = cc.compiles('''#define _GNU_SOURCE
127 #include <string.h> 141 #include <string.h>
128 int func (void) 142 int func (void)
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index cc53f65cce..068aa12e14 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -802,19 +802,28 @@ eina_file_open(const char *path, Eina_Bool shared)
802 if (!filename) return NULL; 802 if (!filename) return NULL;
803 803
804 if (shared) 804 if (shared)
805 {
805#ifdef HAVE_SHM_OPEN 806#ifdef HAVE_SHM_OPEN
806 fd = shm_open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); 807 fd = shm_open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
808 if ((fd != -1) && (!eina_file_close_on_exec(fd, EINA_TRUE)))
809 goto on_error;
807#else 810#else
808 goto on_error; 811 goto on_error;
809#endif 812#endif
813 }
810 else 814 else
811 fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); 815 {
816#ifdef HAVE_OPEN_CLOEXEC
817 fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO | O_CLOEXEC);
818#else
819 fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
820 if ((fd != -1) && (!eina_file_close_on_exec(fd, EINA_TRUE)))
821 goto on_error;
822#endif
823 }
812 824
813 if (fd < 0) goto on_error; 825 if (fd < 0) goto on_error;
814 826
815 if (!eina_file_close_on_exec(fd, EINA_TRUE))
816 goto on_error;
817
818 if (fstat(fd, &file_stat)) 827 if (fstat(fd, &file_stat))
819 goto on_error; 828 goto on_error;
820 829
diff --git a/src/lib/eina/eina_mmap.c b/src/lib/eina/eina_mmap.c
index 11d8804759..23386dac1d 100644
--- a/src/lib/eina/eina_mmap.c
+++ b/src/lib/eina/eina_mmap.c
@@ -198,10 +198,16 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled)
198 /* no zero page device - open it */ 198 /* no zero page device - open it */
199 if (_eina_mmap_zero_fd < 0) 199 if (_eina_mmap_zero_fd < 0)
200 { 200 {
201#ifdef HAVE_OPEN_CLOEXEC
202 _eina_mmap_zero_fd = open("/dev/zero", O_RDWR | O_CLOEXEC);
203 /* if we don;'t have one - fail to set up mmap safety */
204 if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
205#else
201 _eina_mmap_zero_fd = open("/dev/zero", O_RDWR); 206 _eina_mmap_zero_fd = open("/dev/zero", O_RDWR);
202 /* if we don;'t have one - fail to set up mmap safety */ 207 /* if we don;'t have one - fail to set up mmap safety */
203 if (_eina_mmap_zero_fd < 0) return EINA_FALSE; 208 if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
204 eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE); 209 eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE);
210#endif
205 } 211 }
206 /* set up signal handler for SIGBUS */ 212 /* set up signal handler for SIGBUS */
207 sa.sa_sigaction = _eina_mmap_safe_sigbus; 213 sa.sa_sigaction = _eina_mmap_safe_sigbus;