Skip to content

Commit

Permalink
* nscd/nscd_helper.c (open_socket): Use SOCK_CLOEXEC and
Browse files Browse the repository at this point in the history
	SOCK_NONBLOCK if possible.
  • Loading branch information
Ulrich Drepper committed Jul 25, 2008
1 parent b206d8b commit c418b1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2008-07-25 Ulrich Drepper <drepper@redhat.com>

* nscd/nscd_helper.c (open_socket): Use SOCK_CLOEXEC and
SOCK_NONBLOCK if possible.

* sysdeps/unix/sysv/linux/opensock.c (__opensock): Use
SOCK_CLOEXEC if available.

Expand Down
31 changes: 28 additions & 3 deletions nscd/nscd_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <sys/un.h>
#include <not-cancel.h>
#include <nis/rpcsvc/nis.h>
#include <kernel-features.h>

#include "nscd-client.h"

Expand Down Expand Up @@ -161,7 +162,26 @@ __readvall (int fd, const struct iovec *iov, int iovcnt)
static int
open_socket (request_type type, const char *key, size_t keylen)
{
int sock = __socket (PF_UNIX, SOCK_STREAM, 0);
int sock;

#ifdef SOCK_CLOEXEC
# ifndef __ASSUME_SOCK_CLOEXEC
if (__have_sock_cloexec >= 0)
# endif
{
sock = __socket (PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
# ifndef __ASSUME_SOCK_CLOEXEC
if (__have_sock_cloexec == 0)
__have_sock_cloexec = sock != -1 || errno != EINVAL ? 1 : -1;
# endif
}
#endif
#ifndef __ASSUME_SOCK_CLOEXEC
# ifdef SOCK_CLOEXEC
if (__have_sock_cloexec < 0)
# endif
sock = __socket (PF_UNIX, SOCK_STREAM, 0);
#endif
if (sock < 0)
return -1;

Expand All @@ -172,8 +192,13 @@ open_socket (request_type type, const char *key, size_t keylen)
} reqdata;
size_t real_sizeof_reqdata = sizeof (request_header) + keylen;

/* Make socket non-blocking. */
__fcntl (sock, F_SETFL, O_RDWR | O_NONBLOCK);
#ifndef __ASSUME_SOCK_CLOEXEC
# ifdef SOCK_NONBLOCK
if (__have_sock_cloexec < 0)
# endif
/* Make socket non-blocking. */
__fcntl (sock, F_SETFL, O_RDWR | O_NONBLOCK);
#endif

struct sockaddr_un sun;
sun.sun_family = AF_UNIX;
Expand Down

0 comments on commit c418b1b

Please sign in to comment.