mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
* sysdeps/unix/sysv/linux/opensock.c (__opensock): Use
SOCK_CLOEXEC if available.
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
2008-07-25 Ulrich Drepper <drepper@redhat.com>
|
2008-07-25 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/unix/sysv/linux/opensock.c (__opensock): Use
|
||||||
|
SOCK_CLOEXEC if available.
|
||||||
|
|
||||||
* include/rpc/clnt.h: Declare __libc_clntudp_bufcreate and
|
* include/rpc/clnt.h: Declare __libc_clntudp_bufcreate and
|
||||||
__libc_clntudp_bufcreate_internal.
|
__libc_clntudp_bufcreate_internal.
|
||||||
* include/sys/socket.h: Declare __have_sock_cloexec.
|
* include/sys/socket.h: Declare __have_sock_cloexec.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 1999, 2001, 2002, 2007 Free Software Foundation, Inc.
|
/* Copyright (C) 1999, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <kernel-features.h>
|
||||||
|
|
||||||
/* Return a socket of any type. The socket can be used in subsequent
|
/* Return a socket of any type. The socket can be used in subsequent
|
||||||
ioctl calls to talk to the kernel. */
|
ioctl calls to talk to the kernel. */
|
||||||
@ -70,7 +71,24 @@ __opensock (void)
|
|||||||
{
|
{
|
||||||
assert (last_type != 0);
|
assert (last_type != 0);
|
||||||
|
|
||||||
result = __socket (last_family, last_type, 0);
|
#ifdef SOCK_CLOEXEC
|
||||||
|
# ifndef __ASSUME_SOCK_CLOEXEC
|
||||||
|
if (__have_sock_cloexec >= 0)
|
||||||
|
# endif
|
||||||
|
{
|
||||||
|
result = __socket (last_family, last_type | SOCK_CLOEXEC, 0);
|
||||||
|
# ifndef __ASSUME_SOCK_CLOEXEC
|
||||||
|
if (__have_sock_cloexec == 0)
|
||||||
|
__have_sock_cloexec = result != -1 || errno != EINVAL ? 1 : -1;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifndef __ASSUME_SOCK_CLOEXEC
|
||||||
|
# ifdef SOCK_CLOEXEC
|
||||||
|
if (__have_sock_cloexec < 0)
|
||||||
|
# endif
|
||||||
|
result = __socket (last_family, last_type, 0);
|
||||||
|
#endif
|
||||||
if (result != -1 || errno != EAFNOSUPPORT)
|
if (result != -1 || errno != EAFNOSUPPORT)
|
||||||
/* Maybe the socket type isn't supported anymore (module is
|
/* Maybe the socket type isn't supported anymore (module is
|
||||||
unloaded). In this case again try to find the type. */
|
unloaded). In this case again try to find the type. */
|
||||||
@ -105,7 +123,24 @@ __opensock (void)
|
|||||||
if (afs[cnt].family == AF_NETROM || afs[cnt].family == AF_X25)
|
if (afs[cnt].family == AF_NETROM || afs[cnt].family == AF_X25)
|
||||||
type = SOCK_SEQPACKET;
|
type = SOCK_SEQPACKET;
|
||||||
|
|
||||||
result = __socket (afs[cnt].family, type, 0);
|
#ifdef SOCK_CLOEXEC
|
||||||
|
# ifndef __ASSUME_SOCK_CLOEXEC
|
||||||
|
if (__have_sock_cloexec >= 0)
|
||||||
|
# endif
|
||||||
|
{
|
||||||
|
result = __socket (afs[cnt].family, type | SOCK_CLOEXEC, 0);
|
||||||
|
# ifndef __ASSUME_SOCK_CLOEXEC
|
||||||
|
if (__have_sock_cloexec == 0)
|
||||||
|
__have_sock_cloexec = result != -1 || errno != EINVAL ? 1 : -1;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifndef __ASSUME_SOCK_CLOEXEC
|
||||||
|
# ifdef SOCK_CLOEXEC
|
||||||
|
if (__have_sock_cloexec < 0)
|
||||||
|
# endif
|
||||||
|
result = __socket (afs[cnt].family, type, 0);
|
||||||
|
#endif
|
||||||
if (result != -1)
|
if (result != -1)
|
||||||
{
|
{
|
||||||
/* Found an available family. */
|
/* Found an available family. */
|
||||||
|
Reference in New Issue
Block a user