ecore_con: use new API eina_file_close_on_exec.

This commit is contained in:
Cedric BAIL 2017-04-18 16:56:01 -07:00
parent 712f7e878b
commit 662f7d3310
3 changed files with 6 additions and 55 deletions

View File

@ -587,10 +587,9 @@ efl_net_socket4(int domain, int type, int protocol, Eina_Bool close_on_exec)
{
if (close_on_exec)
{
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
if (!eina_file_close_on_exec(fd, EINA_TRUE))
{
int errno_bkp = errno;
ERR("fcntl(" SOCKET_FMT ", F_SETFD, FD_CLOEXEC): %s", fd, strerror(errno));
closesocket(fd);
fd = INVALID_SOCKET;
errno = errno_bkp;
@ -815,25 +814,12 @@ _efl_net_connect_async_end(void *data, Ecore_Thread *thread EINA_UNUSED)
/* if it wasn't a close on exec, release the socket to be passed to child */
if ((!d->close_on_exec) && (d->sockfd != INVALID_SOCKET))
{
int flags = fcntl(d->sockfd, F_GETFD);
if (flags < 0)
if (!eina_file_close_on_exec(d->sockfd, EINA_FALSE))
{
d->error = errno;
ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", d->sockfd, eina_error_msg_get(d->error));
closesocket(d->sockfd);
d->sockfd = INVALID_SOCKET;
}
else
{
flags &= (~FD_CLOEXEC);
if (fcntl(d->sockfd, F_SETFD, flags) < 0)
{
d->error = errno;
ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", d->sockfd, flags, eina_error_msg_get(d->error));
closesocket(d->sockfd);
d->sockfd = INVALID_SOCKET;
}
}
}
#endif
d->cb((void *)d->data, d->addr, d->addrlen, d->sockfd, d->error);
@ -2222,25 +2208,12 @@ _efl_net_ip_connect_async_end(void *data, Ecore_Thread *thread EINA_UNUSED)
/* if it wasn't a close on exec, release the socket to be passed to child */
if ((!d->close_on_exec) && (d->sockfd != INVALID_SOCKET))
{
int flags = fcntl(d->sockfd, F_GETFD);
if (flags < 0)
if (!eina_file_close_on_exec(d->sockfd, EINA_FALSE))
{
d->error = errno;
ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", d->sockfd, strerror(errno));
closesocket(d->sockfd);
d->sockfd = INVALID_SOCKET;
}
else
{
flags &= (~FD_CLOEXEC);
if (fcntl(d->sockfd, F_SETFD, flags) < 0)
{
d->error = errno;
ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", d->sockfd, flags, strerror(errno));
closesocket(d->sockfd);
d->sockfd = INVALID_SOCKET;
}
}
}
#endif

View File

@ -1780,18 +1780,7 @@ _efl_net_dialer_http_efl_io_closer_close_on_exec_set(Eo *o EINA_UNUSED, Efl_Net_
if (pd->fd == INVALID_SOCKET) return EINA_TRUE; /* postpone until _efl_net_dialer_http_socket_open */
flags = fcntl(pd->fd, F_GETFD);
if (flags < 0)
{
ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", pd->fd, strerror(errno));
pd->close_on_exec = old;
return EINA_FALSE;
}
if (close_on_exec)
flags |= FD_CLOEXEC;
else
flags &= (~FD_CLOEXEC);
if (fcntl(pd->fd, F_SETFD, flags) < 0)
if (!eina_file_close_on_exec(pd->fd, close_on_exec))
{
ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", pd->fd, flags, strerror(errno));
pd->close_on_exec = old;

View File

@ -51,7 +51,7 @@ efl_net_accept4(SOCKET fd, struct sockaddr *addr, socklen_t *addrlen, Eina_Bool
#ifdef FD_CLOEXEC
if (close_on_exec)
{
if (fcntl(client, F_SETFD, FD_CLOEXEC) < 0)
if (!eina_file_close_on_exec(client, EINA_TRUE))
{
int errno_bkp = errno;
ERR("fcntl(" SOCKET_FMT ", F_SETFD, FD_CLOEXEC): %s", client, strerror(errno));
@ -280,18 +280,7 @@ _efl_net_server_fd_close_on_exec_set(Eo *o, Efl_Net_Server_Fd_Data *pd, Eina_Boo
fd = efl_loop_fd_get(o);
if (fd == INVALID_SOCKET) return EINA_TRUE; /* postpone until fd_set() */
flags = fcntl(fd, F_GETFD);
if (flags < 0)
{
ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", fd, strerror(errno));
pd->close_on_exec = old;
return EINA_FALSE;
}
if (close_on_exec)
flags |= FD_CLOEXEC;
else
flags &= (~FD_CLOEXEC);
if (fcntl(fd, F_SETFD, flags) < 0)
if (!eina_file_close_on_exec(fd, close_on_exec))
{
ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", fd, flags, strerror(errno));
pd->close_on_exec = old;