diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-07-28 23:34:19 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2008-07-28 23:34:19 +0000 |
commit | c7045198ca8f4ff5b97205340d51127f8503c2bd (patch) | |
tree | 387ee7a78760f683df6035af28d665e3972aa30b /nscd | |
parent | c83494a925f4b4b716f9ba3abcb5e695d3e2a8a9 (diff) | |
download | glibc-c7045198ca8f4ff5b97205340d51127f8503c2bd.tar glibc-c7045198ca8f4ff5b97205340d51127f8503c2bd.tar.gz glibc-c7045198ca8f4ff5b97205340d51127f8503c2bd.tar.bz2 glibc-c7045198ca8f4ff5b97205340d51127f8503c2bd.zip |
Updated to fedora-glibc-20080728T2320cvs/fedora-glibc-2_8_90-10
Diffstat (limited to 'nscd')
-rw-r--r-- | nscd/Makefile | 2 | ||||
-rw-r--r-- | nscd/connections.c | 99 | ||||
-rw-r--r-- | nscd/nscd_helper.c | 31 |
3 files changed, 106 insertions, 26 deletions
diff --git a/nscd/Makefile b/nscd/Makefile index 51badea201..364ddfe8dd 100644 --- a/nscd/Makefile +++ b/nscd/Makefile @@ -90,7 +90,7 @@ CFLAGS-nscd_initgroups.c = -fexceptions nscd-cflags = -DIS_IN_nscd=1 -D_FORTIFY_SOURCE=2 ifeq (yesyes,$(have-fpie)$(build-shared)) -nscd-cflags += -fpie +nscd-cflags += $(pie-ccflag) endif ifeq (yes,$(have-ssp)) nscd-cflags += -fstack-protector diff --git a/nscd/connections.c b/nscd/connections.c index e4d32b27de..a1b92f466b 100644 --- a/nscd/connections.c +++ b/nscd/connections.c @@ -234,6 +234,14 @@ static int inotify_fd = -1; static int resolv_conf_descr = -1; #endif +#ifndef __ASSUME_SOCK_CLOEXEC +/* Negative if SOCK_CLOEXEC is not supported, positive if it is, zero + before be know the result. */ +static int have_sock_cloexec; +/* The paccept syscall was introduced at the same time as SOCK_CLOEXEC. */ +# define have_paccept have_sock_cloexec +#endif + /* Number of times clients had to wait. */ unsigned long int client_queued; @@ -517,9 +525,15 @@ nscd_init (void) #ifdef HAVE_INOTIFY /* Use inotify to recognize changed files. */ - inotify_fd = inotify_init (); - if (inotify_fd != -1) - fcntl (inotify_fd, F_SETFL, O_NONBLOCK); + inotify_fd = inotify_init1 (IN_NONBLOCK); +# ifndef __ASSUME_IN_NONBLOCK + if (inotify_fd == -1 && errno == ENOSYS) + { + inotify_fd = inotify_init (); + if (inotify_fd != -1) + fcntl (inotify_fd, F_SETFL, O_RDONLY | O_NONBLOCK); + } +# endif #endif for (size_t cnt = 0; cnt < lastdb; ++cnt) @@ -860,7 +874,21 @@ cannot set socket to close on exec: %s; disabling paranoia mode"), } /* Create the socket. */ - sock = socket (AF_UNIX, SOCK_STREAM, 0); +#ifndef __ASSUME_SOCK_CLOEXEC + sock = -1; + if (have_sock_cloexec >= 0) +#endif + { + sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); +#ifdef __ASSUME_SOCK_CLOEXEC + if (have_sock_cloexec == 0) + have_sock_cloexec = sock != -1 || errno != EINVAL ? 1 : -1; +#endif + } +#ifndef __ASSUME_SOCK_CLOEXEC + if (have_sock_cloexec < 0) + sock = socket (AF_UNIX, SOCK_STREAM, 0); +#endif if (sock < 0) { dbg_log (_("cannot open socket: %s"), strerror (errno)); @@ -876,22 +904,27 @@ cannot set socket to close on exec: %s; disabling paranoia mode"), exit (errno == EACCES ? 4 : 1); } - /* We don't want to get stuck on accept. */ - int fl = fcntl (sock, F_GETFL); - if (fl == -1 || fcntl (sock, F_SETFL, fl | O_NONBLOCK) == -1) +#ifndef __ASSUME_SOCK_CLOEXEC + if (have_sock_cloexec < 0) { - dbg_log (_("cannot change socket to nonblocking mode: %s"), - strerror (errno)); - exit (1); - } + /* We don't want to get stuck on accept. */ + int fl = fcntl (sock, F_GETFL); + if (fl == -1 || fcntl (sock, F_SETFL, fl | O_NONBLOCK) == -1) + { + dbg_log (_("cannot change socket to nonblocking mode: %s"), + strerror (errno)); + exit (1); + } - /* The descriptor needs to be closed on exec. */ - if (paranoia && fcntl (sock, F_SETFD, FD_CLOEXEC) == -1) - { - dbg_log (_("cannot set socket to close on exec: %s"), - strerror (errno)); - exit (1); + /* The descriptor needs to be closed on exec. */ + if (paranoia && fcntl (sock, F_SETFD, FD_CLOEXEC) == -1) + { + dbg_log (_("cannot set socket to close on exec: %s"), + strerror (errno)); + exit (1); + } } +#endif /* Set permissions for the socket. */ chmod (_PATH_NSCDSOCKET, DEFFILEMODE); @@ -1576,10 +1609,15 @@ nscd_run_worker (void *p) /* We are done with the list. */ pthread_mutex_unlock (&readylist_lock); - /* We do not want to block on a short read or so. */ - int fl = fcntl (fd, F_GETFL); - if (fl == -1 || fcntl (fd, F_SETFL, fl | O_NONBLOCK) == -1) - goto close_and_out; +#ifndef __ASSUME_SOCK_CLOEXEC + if (have_sock_cloexec < 0) + { + /* We do not want to block on a short read or so. */ + int fl = fcntl (fd, F_GETFL); + if (fl == -1 || fcntl (fd, F_SETFL, fl | O_NONBLOCK) == -1) + goto close_and_out; + } +#endif /* Now read the request. */ request_header req; @@ -1779,7 +1817,24 @@ main_loop_poll (void) if (conns[0].revents != 0) { /* We have a new incoming connection. Accept the connection. */ - int fd = TEMP_FAILURE_RETRY (accept (sock, NULL, NULL)); + int fd; + +#ifndef __ASSUME_PACCEPT + fd = -1; + if (have_paccept >= 0) +#endif + { + fd = TEMP_FAILURE_RETRY (paccept (sock, NULL, NULL, NULL, + SOCK_NONBLOCK)); +#ifndef __ASSUME_PACCEPT + if (have_paccept == 0) + have_paccept = fd != -1 || errno != ENOSYS ? 1 : -1; +#endif + } +#ifndef __ASSUME_PACCEPT + if (have_paccept < 0) + fd = TEMP_FAILURE_RETRY (accept (sock, NULL, NULL)); +#endif /* Use the descriptor if we have not reached the limit. */ if (fd >= 0) diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c index 9828a46df0..7db5d09845 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; |