['dladdr', ['dlfcn.h'], ['dl'], '-D_GNU_SOURCE=1']
]
+open_cloexec = cc.run('''#include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ int main(int argc, char **argv) {
+ int res = open(argv[0], O_RDONLY | O_CLOEXEC);
+ if (res < 0) return 1;
+ return 0;
+ }
+ ''',
+ name : 'open works with O_CLOEXEC')
+if open_cloexec.compiled() and open_cloexec.returncode() == 0
+ config_h.set10('HAVE_OPEN_CLOEXEC', true)
+endif
+
strerror_r_char_p = cc.compiles('''#define _GNU_SOURCE
#include <string.h>
int func (void)
if (!filename) return NULL;
if (shared)
+ {
#ifdef HAVE_SHM_OPEN
- fd = shm_open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
+ fd = shm_open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
+ if ((fd != -1) && (!eina_file_close_on_exec(fd, EINA_TRUE)))
+ goto on_error;
#else
- goto on_error;
+ goto on_error;
#endif
+ }
else
- fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
+ {
+#ifdef HAVE_OPEN_CLOEXEC
+ fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO | O_CLOEXEC);
+#else
+ fd = open(filename, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
+ if ((fd != -1) && (!eina_file_close_on_exec(fd, EINA_TRUE)))
+ goto on_error;
+#endif
+ }
if (fd < 0) goto on_error;
- if (!eina_file_close_on_exec(fd, EINA_TRUE))
- goto on_error;
-
if (fstat(fd, &file_stat))
goto on_error;
/* no zero page device - open it */
if (_eina_mmap_zero_fd < 0)
{
+#ifdef HAVE_OPEN_CLOEXEC
+ _eina_mmap_zero_fd = open("/dev/zero", O_RDWR | O_CLOEXEC);
+ /* if we don;'t have one - fail to set up mmap safety */
+ if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
+#else
_eina_mmap_zero_fd = open("/dev/zero", O_RDWR);
/* if we don;'t have one - fail to set up mmap safety */
if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE);
+#endif
}
/* set up signal handler for SIGBUS */
sa.sa_sigaction = _eina_mmap_safe_sigbus;