From a334319f6530564d22e775935d9c91663623a1b4 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 22 Dec 2004 20:10:10 +0000 Subject: (CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4. --- nis/nis_callback.c | 65 +++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'nis/nis_callback.c') diff --git a/nis/nis_callback.c b/nis/nis_callback.c index e0acd9683a..b867b39ab7 100644 --- a/nis/nis_callback.c +++ b/nis/nis_callback.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997,1998,1999,2000,2005,2006 Free Software Foundation, Inc. +/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk , 1997. @@ -197,18 +197,22 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie, struct nis_cb *cb) { struct timeval TIMEOUT = {25, 0}; - bool_t cb_is_running; + bool_t cb_is_running = FALSE; data = cb; for (;;) { - struct pollfd my_pollfd[svc_max_pollfd]; + struct pollfd *my_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; @@ -216,17 +220,20 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie, my_pollfd[i].revents = 0; } - switch (i = TEMP_FAILURE_RETRY (__poll (my_pollfd, svc_max_pollfd, - 25*1000))) + switch (i = __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. */ - cb_is_running = FALSE; + memset ((char *) &cb_is_running, 0, sizeof (cb_is_running)); 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) @@ -237,6 +244,7 @@ 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; } @@ -266,15 +274,16 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *, struct nis_cb *cb; int sock = RPC_ANYSOCK; struct sockaddr_in sin; - socklen_t len = sizeof (struct sockaddr_in); + int len = sizeof (struct sockaddr_in); + char addr[NIS_MAXNAMELEN + 1]; unsigned short port; - int nomsg = 0; - cb = (struct nis_cb *) calloc (1, - sizeof (struct nis_cb) + sizeof (nis_server)); + cb = (struct nis_cb *) calloc (1, sizeof (struct nis_cb)); if (__builtin_expect (cb == NULL, 0)) goto failed; - cb->serv = (nis_server *) (cb + 1); + cb->serv = (nis_server *) calloc (1, sizeof (nis_server)); + if (__builtin_expect (cb->serv == NULL, 0)) + goto failed; cb->serv->name = strdup (nis_local_principal ()); if (__builtin_expect (cb->serv->name == NULL, 0)) goto failed; @@ -317,20 +326,15 @@ __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)); - if (cb->xprt == NULL) - { - nomsg = 1; - goto failed; - } + cb->xprt = (flags & USE_DGRAM) ? svcudp_bufcreate (sock, 100, 8192) : + svctcp_create (sock, 100, 8192); 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; @@ -341,30 +345,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); - - 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; + 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); return cb; failed: if (cb) { - if (cb->xprt) - svc_destroy (cb->xprt); - xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); + if (cb->serv) + { + xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv); + free (cb->serv); + } free (cb); } - if (!nomsg) - syslog (LOG_ERR, "NIS+: out of memory allocating callback"); + syslog (LOG_ERR, "NIS+: out of memory allocating callback"); return NULL; } @@ -375,6 +379,7 @@ __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; -- cgit v1.2.3