summaryrefslogtreecommitdiff
path: root/nscd
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2015-10-17 12:02:37 +0200
committerFlorian Weimer <fweimer@redhat.com>2015-10-17 12:02:37 +0200
commit52fb79d6cdecb89a6f0375091e7c12ed79ae6760 (patch)
treee4885bfee90d7fe9f584518d3bc242050c725ef0 /nscd
parentf546f87c4ffb1642ffc96b8d614c329ed35252c3 (diff)
Assume that SOCK_CLOEXEC is available and works
This fixes (harmless) data races when accessing the various __have_sock_cloexec variables.
Diffstat (limited to 'nscd')
-rw-r--r--nscd/connections.c68
-rw-r--r--nscd/nscd_helper.c27
2 files changed, 2 insertions, 93 deletions
diff --git a/nscd/connections.c b/nscd/connections.c
index cba5e6ad9d..e16406ba54 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -257,11 +257,6 @@ int inotify_fd = -1;
static int nl_status_fd = -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;
-#endif
#ifndef __ASSUME_ACCEPT4
static int have_accept4;
#endif
@@ -830,21 +825,7 @@ cannot set socket to close on exec: %s; disabling paranoia mode"),
}
/* Create the socket. */
-#ifndef __ASSUME_SOCK_CLOEXEC
- sock = -1;
- if (have_sock_cloexec >= 0)
-#endif
- {
- sock = socket (AF_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
- }
-#ifndef __ASSUME_SOCK_CLOEXEC
- if (have_sock_cloexec < 0)
- sock = socket (AF_UNIX, SOCK_STREAM, 0);
-#endif
+ sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (sock < 0)
{
dbg_log (_("cannot open socket: %s"), strerror (errno));
@@ -860,28 +841,6 @@ cannot set socket to close on exec: %s; disabling paranoia mode"),
do_exit (errno == EACCES ? 4 : 1, 0, NULL);
}
-#ifndef __ASSUME_SOCK_CLOEXEC
- if (have_sock_cloexec < 0)
- {
- /* 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));
- do_exit (1, 0, NULL);
- }
-
- /* 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));
- do_exit (1, 0, NULL);
- }
- }
-#endif
-
/* Set permissions for the socket. */
chmod (_PATH_NSCDSOCKET, DEFFILEMODE);
@@ -922,31 +881,6 @@ cannot set socket to close on exec: %s; disabling paranoia mode"),
/* Start the timestamp process. */
dbs[hstdb].head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP]
= __bump_nl_timestamp ();
-
-# ifndef __ASSUME_SOCK_CLOEXEC
- if (have_sock_cloexec < 0)
- {
- /* We don't want to get stuck on accept. */
- int fl = fcntl (nl_status_fd, F_GETFL);
- if (fl == -1
- || fcntl (nl_status_fd, F_SETFL, fl | O_NONBLOCK) == -1)
- {
- dbg_log (_("\
-cannot change socket to nonblocking mode: %s"),
- strerror (errno));
- do_exit (1, 0, NULL);
- }
-
- /* The descriptor needs to be closed on exec. */
- if (paranoia
- && fcntl (nl_status_fd, F_SETFD, FD_CLOEXEC) == -1)
- {
- dbg_log (_("cannot set socket to close on exec: %s"),
- strerror (errno));
- do_exit (1, 0, NULL);
- }
- }
-# endif
}
}
}
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index 52a5caadfa..341b9311b2 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -166,24 +166,7 @@ open_socket (request_type type, const char *key, size_t keylen)
{
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
+ sock = __socket (PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (sock < 0)
return -1;
@@ -194,14 +177,6 @@ open_socket (request_type type, const char *key, size_t keylen)
char key[];
} *reqdata = alloca (real_sizeof_reqdata);
-#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;
strcpy (sun.sun_path, _PATH_NSCDSOCKET);