mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 07:56:17 +01:00
gsocket: Use accept4 () for race-free setting of the close-on-exec flag
The code was already setting the close-on-exec flag for the new socket, just in a racy way.
This commit is contained in:
parent
1c305c4fb0
commit
3dc77fef24
@ -2858,6 +2858,9 @@ g_socket_accept (GSocket *socket,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_ACCEPT4
|
||||||
|
gboolean try_accept4 = TRUE;
|
||||||
|
#endif
|
||||||
GSocket *new_socket;
|
GSocket *new_socket;
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
@ -2871,7 +2874,28 @@ g_socket_accept (GSocket *socket,
|
|||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
if ((ret = accept (socket->priv->fd, NULL, 0)) < 0)
|
gboolean try_accept = TRUE;
|
||||||
|
|
||||||
|
#ifdef HAVE_ACCEPT4
|
||||||
|
if (try_accept4)
|
||||||
|
{
|
||||||
|
ret = accept4 (socket->priv->fd, NULL, 0, SOCK_CLOEXEC);
|
||||||
|
if (ret < 0 && errno == ENOSYS)
|
||||||
|
{
|
||||||
|
try_accept4 = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try_accept = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert (try_accept4 || try_accept);
|
||||||
|
#endif
|
||||||
|
if (try_accept)
|
||||||
|
ret = accept (socket->priv->fd, NULL, 0);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
int errsv = get_socket_errno ();
|
int errsv = get_socket_errno ();
|
||||||
|
|
||||||
|
@ -606,6 +606,7 @@ if host_system == 'windows'
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
functions = [
|
functions = [
|
||||||
|
'accept4',
|
||||||
'close_range',
|
'close_range',
|
||||||
'endmntent',
|
'endmntent',
|
||||||
'endservent',
|
'endservent',
|
||||||
|
Loading…
Reference in New Issue
Block a user