aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-07-25 18:31:07 +0000
committerUlrich Drepper <drepper@redhat.com>2008-07-25 18:31:07 +0000
commitc418b1ba4cda2026554a3b98957eaab0d53c1245 (patch)
tree17925fd1fdca674e6a2e4215cbba8ea2541e1523
parentb206d8b166f7501c8db0d922fe3652560df2227d (diff)
downloadglibc-c418b1ba4cda2026554a3b98957eaab0d53c1245.zip
glibc-c418b1ba4cda2026554a3b98957eaab0d53c1245.tar.gz
glibc-c418b1ba4cda2026554a3b98957eaab0d53c1245.tar.bz2
* nscd/nscd_helper.c (open_socket): Use SOCK_CLOEXEC and
SOCK_NONBLOCK if possible.
-rw-r--r--ChangeLog3
-rw-r--r--nscd/nscd_helper.c31
2 files changed, 31 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5c962f0..98775ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index 9828a46..7db5d09 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -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"
@@ -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;
@@ -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;