From 2c81c415ceda41331df567ba97ab5cdf98211107 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 26 Feb 2002 09:32:21 +0000 Subject: Fix rpc + threads so it now compiles. --- include/netdb.h | 9 ++---- libc/inet/rpc/rcmd.c | 81 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/include/netdb.h b/include/netdb.h index aea6e0050..c3e07728c 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -53,13 +53,9 @@ __BEGIN_DECLS -/* Error status for non-reentrant lookup functions. - * NOTE: uClibc reuses errno for h_errno. */ -#include -#define h_errno errno +/* Error status for non-reentrant lookup functions. */ +extern int h_errno; - -#if 0 /* Function to get address of global `h_errno' variable. */ extern int *__h_errno_location (void) __THROW __attribute__ ((__const__)); @@ -80,7 +76,6 @@ __set_h_errno (int __err) /* Use a macro to access always the thread specific `h_errno' variable. */ # define h_errno (*__h_errno_location ()) #endif -#endif /* Possible values left in `h_errno'. */ diff --git a/libc/inet/rpc/rcmd.c b/libc/inet/rpc/rcmd.c index a56b99ec0..20c572b45 100644 --- a/libc/inet/rpc/rcmd.c +++ b/libc/inet/rpc/rcmd.c @@ -37,16 +37,8 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #define __FORCE_GLIBC #include -#include -#include -#include -#include - -#include -#include - -#include #define __USE_GNU +#include #include #include #include @@ -54,11 +46,17 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #include #include #include -#include #include #include - +#include +#include +#include +#include #include +#include +#include + + /* hmm. uClibc seems to have that, but it doesn't work for some reason */ #define getc_unlocked getc @@ -94,16 +92,22 @@ int rcmd(ahost, rport, locuser, remuser, cmd, fd2p) pid = getpid(); #ifdef _LIBC_REENTRANT -#error "Fix the alloca stuff" hstbuflen = 1024; +#ifdef __UCLIBC_HAS_MMU__ tmphstbuf = alloca (hstbuflen); +#else + tmphstbuf = malloc (hstbuflen); +#endif - while (__gethostbyname_r (*ahost, &hostbuf, tmphstbuf, + while (gethostbyname_r (*ahost, &hostbuf, tmphstbuf, hstbuflen, &hp, &herr) != 0 || hp == NULL) { if (herr != NETDB_INTERNAL || errno != ERANGE) { __set_h_errno (herr); +#ifndef __UCLIBC_HAS_MMU__ + free(tmphstbuf); +#endif herror(*ahost); return -1; } @@ -111,9 +115,19 @@ int rcmd(ahost, rport, locuser, remuser, cmd, fd2p) { /* Enlarge the buffer. */ hstbuflen *= 2; +#ifdef __UCLIBC_HAS_MMU__ tmphstbuf = alloca (hstbuflen); +#else + if (tmphstbuf) { + free(tmphstbuf); + } + tmphstbuf = malloc (hstbuflen); +#endif } } +#ifndef __UCLIBC_HAS_MMU__ + free(tmphstbuf); +#endif #else /* call the non-reentrant version */ if ((hp = gethostbyname(*ahost)) == NULL) { return -1; @@ -292,22 +306,38 @@ int ruserok(rhost, superuser, ruser, luser) #endif #ifdef _LIBC_REENTRANT -#error "Fix the alloca stuff!" buflen = 1024; +#ifdef __UCLIBC_HAS_MMU__ buffer = alloca (buflen); +#else + buffer = malloc (buflen); +#endif - while (__gethostbyname_r (rhost, &hostbuf, buffer, + while (gethostbyname_r (rhost, &hostbuf, buffer, buflen, &hp, &herr) != 0 || hp == NULL) { - if (herr != NETDB_INTERNAL || errno != ERANGE) + if (herr != NETDB_INTERNAL || errno != ERANGE) { +#ifndef __UCLIBC_HAS_MMU__ + free(buffer); +#endif return -1; - else + } else { /* Enlarge the buffer. */ buflen *= 2; +#ifdef __UCLIBC_HAS_MMU__ buffer = alloca (buflen); +#else + if (buffer) { + free(buffer); + } + buffer = malloc (buflen); +#endif } } +#ifndef __UCLIBC_HAS_MMU__ + free(buffer); +#endif #else if ((hp = gethostbyname(rhost)) == NULL) { return -1; @@ -402,16 +432,25 @@ iruserok2 (raddr, superuser, ruser, luser, rhost) uid_t uid; #ifdef _LIBC_REENTRANT -#error "Fix the alloca stuff" size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); - char *buffer = alloca (buflen); struct passwd pwdbuf; +#ifdef __UCLIBC_HAS_MMU__ + char *buffer = alloca (buflen); +#else + char *buffer = malloc (buflen); +#endif - if (__getpwnam_r (luser, &pwdbuf, buffer, + if (getpwnam_r (luser, &pwdbuf, buffer, buflen, &pwd) != 0 || pwd == NULL) { +#ifndef __UCLIBC_HAS_MMU__ + free(buffer); +#endif return -1; } +#ifndef __UCLIBC_HAS_MMU__ + free(buffer); +#endif #else if ((pwd = getpwnam(luser)) == NULL) return -1; @@ -519,7 +558,7 @@ __icheckhost (raddr, lhost, rhost) buffer = malloc(buflen); save_errno = errno; - while (__gethostbyname_r (lhost, &hostbuf, buffer, buflen, &hp, &herr) + while (gethostbyname_r (lhost, &hostbuf, buffer, buflen, &hp, &herr) != 0) { free(buffer); return (0); -- cgit v1.2.3