eina: use new API eina_file_close_on_exec.

This commit is contained in:
Cedric BAIL 2017-04-18 16:54:03 -07:00
parent 9d8549f7a3
commit b2893dfc77
3 changed files with 3 additions and 17 deletions

View File

@ -682,7 +682,7 @@ _eina_debug_monitor_service_connect(void)
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) goto err;
// set the socket to close when we exec things so they don't inherit it
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto err;
if (!eina_file_close_on_exec(fd, EINA_TRUE)) goto err;
// set up some socket options on addr re-use
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
sizeof(curstate)) < 0)

View File

@ -763,9 +763,6 @@ eina_file_open(const char *path, Eina_Bool shared)
char *filename;
struct stat file_stat;
int fd = -1;
#ifdef HAVE_FCNTL
int flags;
#endif
EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
@ -783,16 +780,9 @@ eina_file_open(const char *path, Eina_Bool shared)
if (fd < 0) goto on_error;
#ifdef HAVE_FCNTL
flags = fcntl(fd, F_GETFD);
if (flags == -1)
if (!eina_file_close_on_exec(fd, EINA_TRUE))
goto on_error;
flags |= FD_CLOEXEC;
if (fcntl(fd, F_SETFD, flags) == -1)
goto on_error;
#endif
if (fstat(fd, &file_stat))
goto on_error;

View File

@ -196,11 +196,7 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled)
/* if we don;'t have one - fail to set up mmap safety */
if (_eina_mmap_zero_fd < 0) return EINA_FALSE;
#ifdef HAVE_FCNTL
flags = fcntl(_eina_mmap_zero_fd, F_GETFD);
flags |= FD_CLOEXEC;
fcntl(_eina_mmap_zero_fd, F_SETFD, flags); /* If this fail, it will just leak a fd to zero ... */
#endif
eina_file_close_on_exec(_eina_mmap_zero_fd, EINA_TRUE);
}
/* set up signal handler for SIGBUS */
sa.sa_sigaction = _eina_mmap_safe_sigbus;