diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
commit | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch) | |
tree | 2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /nis/nis_callback.c | |
parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz |
2.5-18.1
Diffstat (limited to 'nis/nis_callback.c')
-rw-r--r-- | nis/nis_callback.c | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/nis/nis_callback.c b/nis/nis_callback.c index b867b39ab7..e0acd9683a 100644 --- a/nis/nis_callback.c +++ b/nis/nis_callback.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1997,1998,1999,2000,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997. @@ -197,22 +197,18 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie, struct nis_cb *cb) { struct timeval TIMEOUT = {25, 0}; - bool_t cb_is_running = FALSE; + bool_t cb_is_running; data = cb; for (;;) { - struct pollfd *my_pollfd; + struct pollfd my_pollfd[svc_max_pollfd]; int i; if (svc_max_pollfd == 0 && svc_pollfd == NULL) return NIS_CBERROR; - my_pollfd = malloc (sizeof (struct pollfd) * svc_max_pollfd); - if (__builtin_expect (my_pollfd == NULL, 0)) - return NIS_NOMEMORY; - for (i = 0; i < svc_max_pollfd; ++i) { my_pollfd[i].fd = svc_pollfd[i].fd; @@ -220,20 +216,17 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie, my_pollfd[i].revents = 0; } - switch (i = __poll (my_pollfd, svc_max_pollfd, 25*1000)) + switch (i = TEMP_FAILURE_RETRY (__poll (my_pollfd, svc_max_pollfd, + 25*1000))) { case -1: - free (my_pollfd); - if (errno == EINTR) - continue; return NIS_CBERROR; case 0: - free (my_pollfd); /* See if callback 'thread' in the server is still alive. */ - memset ((char *) &cb_is_running, 0, sizeof (cb_is_running)); + cb_is_running = FALSE; if (clnt_call (bptr->clnt, NIS_CALLBACK, (xdrproc_t) xdr_netobj, (caddr_t) cookie, (xdrproc_t) xdr_bool, - (caddr_t) & cb_is_running, TIMEOUT) != RPC_SUCCESS) + (caddr_t) &cb_is_running, TIMEOUT) != RPC_SUCCESS) cb_is_running = FALSE; if (cb_is_running == FALSE) @@ -244,7 +237,6 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie, break; default: svc_getreq_poll (my_pollfd, i); - free (my_pollfd); if (data->nomore) return data->result; } @@ -274,16 +266,15 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *, struct nis_cb *cb; int sock = RPC_ANYSOCK; struct sockaddr_in sin; - int len = sizeof (struct sockaddr_in); - char addr[NIS_MAXNAMELEN + 1]; + socklen_t len = sizeof (struct sockaddr_in); unsigned short port; + int nomsg = 0; - cb = (struct nis_cb *) calloc (1, sizeof (struct nis_cb)); + cb = (struct nis_cb *) calloc (1, + sizeof (struct nis_cb) + sizeof (nis_server)); if (__builtin_expect (cb == NULL, 0)) goto failed; - cb->serv = (nis_server *) calloc (1, sizeof (nis_server)); - if (__builtin_expect (cb->serv == NULL, 0)) - goto failed; + cb->serv = (nis_server *) (cb + 1); cb->serv->name = strdup (nis_local_principal ()); if (__builtin_expect (cb->serv->name == NULL, 0)) goto failed; @@ -326,15 +317,20 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *, cb->serv->ep.ep_val[0].proto = strdup ((flags & USE_DGRAM) ? "udp" : "tcp"); if (__builtin_expect (cb->serv->ep.ep_val[0].proto == NULL, 0)) goto failed; - cb->xprt = (flags & USE_DGRAM) ? svcudp_bufcreate (sock, 100, 8192) : - svctcp_create (sock, 100, 8192); + cb->xprt = ((flags & USE_DGRAM) + ? svcudp_bufcreate (sock, 100, 8192) + : svctcp_create (sock, 100, 8192)); + if (cb->xprt == NULL) + { + nomsg = 1; + goto failed; + } cb->sock = cb->xprt->xp_sock; if (!svc_register (cb->xprt, CB_PROG, CB_VERS, cb_prog_1, 0)) { xprt_unregister (cb->xprt); svc_destroy (cb->xprt); xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); - free (cb->serv); free (cb); syslog (LOG_ERR, "NIS+: failed to register callback dispatcher"); return NULL; @@ -345,30 +341,30 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *, xprt_unregister (cb->xprt); svc_destroy (cb->xprt); xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); - free (cb->serv); free (cb); syslog (LOG_ERR, "NIS+: failed to read local socket info"); return NULL; } port = ntohs (sin.sin_port); get_myaddress (&sin); - snprintf (addr, sizeof (addr), "%s.%d.%d", inet_ntoa (sin.sin_addr), - (port & 0xFF00) >> 8, port & 0x00FF); - cb->serv->ep.ep_val[0].uaddr = strdup (addr); + + if (asprintf (&cb->serv->ep.ep_val[0].uaddr, "%s.%d.%d", + inet_ntoa (sin.sin_addr), (port & 0xFF00) >> 8, port & 0x00FF) + < 0) + goto failed; return cb; failed: if (cb) { - if (cb->serv) - { - xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); - free (cb->serv); - } + if (cb->xprt) + svc_destroy (cb->xprt); + xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); free (cb); } - syslog (LOG_ERR, "NIS+: out of memory allocating callback"); + if (!nomsg) + syslog (LOG_ERR, "NIS+: out of memory allocating callback"); return NULL; } @@ -379,7 +375,6 @@ __nis_destroy_callback (struct nis_cb *cb) svc_destroy (cb->xprt); close (cb->sock); xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); - free (cb->serv); free (cb); return NIS_SUCCESS; |