From bd7c3bed543d02fb01f69b29ea1a736e7a0f618d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 25 Sep 2004 07:55:46 +0000 Subject: Updated to fedora-glibc-20040925T0738 --- nis/ypclnt.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'nis') diff --git a/nis/ypclnt.c b/nis/ypclnt.c index ab28e6002b..f25c7c710b 100644 --- a/nis/ypclnt.c +++ b/nis/ypclnt.c @@ -74,7 +74,7 @@ yp_bind_client_create (const char *domain, dom_binding *ysd, if (ysd->dom_client != NULL) { /* If the program exits, close the socket */ - if (fcntl (ysd->dom_socket, F_SETFD, 1) == -1) + if (fcntl (ysd->dom_socket, F_SETFD, FD_CLOEXEC) == -1) perror ("fcntl: F_SETFD"); } } @@ -83,23 +83,18 @@ yp_bind_client_create (const char *domain, dom_binding *ysd, static void yp_bind_file (const char *domain, dom_binding *ysd) { - struct ypbind_resp ypbr; - char path[sizeof (BINDINGDIR) + strlen (domain) + 10]; - struct iovec vec[2]; - unsigned short port; - int fd; + char path[sizeof (BINDINGDIR) + strlen (domain) + 3 * sizeof (unsigned) + 3]; - sprintf (path, "%s/%s.%d", BINDINGDIR, domain, YPBINDVERS); - fd = open (path, O_RDONLY); + snprintf (path, sizeof (path), "%s/%s.%u", BINDINGDIR, domain, YPBINDVERS); + int fd = open (path, O_RDONLY); if (fd >= 0) { - /* We have a binding file and could save a RPC call */ - vec[0].iov_base = &port; - vec[0].iov_len = sizeof (port); - vec[1].iov_base = &ypbr; - vec[1].iov_len = sizeof (ypbr); + /* We have a binding file and could save a RPC call. The file + contains a port number and the YPBIND_RESP record. The port + number (16 bits) can be ignored. */ + struct ypbind_resp ypbr; - if (readv (fd, vec, 2) == sizeof (port) + sizeof (ypbr)) + if (pread (fd, &ypbr, sizeof (ypbr), 2) == sizeof (ypbr)) yp_bind_client_create (domain, ysd, &ypbr); close (fd); @@ -183,9 +178,9 @@ __yp_bind (const char *domain, dom_binding **ypdb) } #if USE_BINDINGDIR - /* Try binding dir at first if we have no binding */ + /* Try binding dir at first if we have no binding */ if (ysd->dom_client == NULL) - yp_bind_file (domain, ysd); + yp_bind_file (domain, ysd); #endif /* USE_BINDINGDIR */ if (ysd->dom_client == NULL) @@ -309,16 +304,10 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs, status = YPERR_YPERR; __libc_lock_lock (ypbindlist_lock); - if (__ypbindlist != NULL) + ydb = __ypbindlist; + while (ydb != NULL) { - ydb = __ypbindlist; - while (ydb != NULL) - { - if (strcmp (domain, ydb->dom_domain) == 0) - break; - ydb = ydb->dom_pnext; - } - if (ydb != NULL) + if (strcmp (domain, ydb->dom_domain) == 0) { if (__yp_bind (domain, &ydb) == 0) { @@ -327,6 +316,7 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs, resp, &ydb, 0); if (status == YPERR_SUCCESS) { + __libc_lock_unlock (ypbindlist_lock); __set_errno (saved_errno); return status; } @@ -334,7 +324,10 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs, /* We use ypbindlist, and the old cached data is invalid. unbind now and create a new binding */ yp_unbind_locked (domain); + + break; } + ydb = ydb->dom_pnext; } __libc_lock_unlock (ypbindlist_lock); -- cgit v1.2.3