diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/inet/rpc/clnt_generic.c | 29 | ||||
-rw-r--r-- | libc/inet/rpc/getrpcent.c | 191 | ||||
-rw-r--r-- | libc/inet/rpc/rcmd.c | 25 | ||||
-rw-r--r-- | libc/stdlib/Makefile | 4 | ||||
-rw-r--r-- | libc/string/wstring.c | 1 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/create_module.c | 2 | ||||
-rw-r--r-- | libc/sysdeps/linux/powerpc/Makefile | 4 |
7 files changed, 174 insertions, 82 deletions
diff --git a/libc/inet/rpc/clnt_generic.c b/libc/inet/rpc/clnt_generic.c index 349c0f62d..c8fe545c3 100644 --- a/libc/inet/rpc/clnt_generic.c +++ b/libc/inet/rpc/clnt_generic.c @@ -53,7 +53,9 @@ clnt_create (const char *hostname, u_long prog, u_long vers, struct hostent hostbuf, *h; size_t hstbuflen; char *hsttmpbuf; - struct protoent *p; + struct protoent protobuf, *p; + size_t prtbuflen; + char *prttmpbuf; struct sockaddr_in sin; struct sockaddr_un sun; int sock; @@ -113,14 +115,23 @@ clnt_create (const char *hostname, u_long prog, u_long vers, memset (sin.sin_zero, 0, sizeof (sin.sin_zero)); memcpy ((char *) &sin.sin_addr, h->h_addr, h->h_length); -#warning getprotobyname is not reentrant... Add getprotobyname_r - p = getprotobyname(proto); - if (p == NULL) { - struct rpc_createerr *ce = &get_rpc_createerr (); - ce->cf_stat = RPC_UNKNOWNPROTO; - ce->cf_error.re_errno = EPFNOSUPPORT; - return NULL; - } + prtbuflen = 1024; + prttmpbuf = alloca (prtbuflen); + while (getprotobyname_r (proto, &protobuf, prttmpbuf, prtbuflen, &p) != 0 + || p == NULL) + if (errno != ERANGE) + { + struct rpc_createerr *ce = &get_rpc_createerr (); + ce->cf_stat = RPC_UNKNOWNPROTO; + ce->cf_error.re_errno = EPFNOSUPPORT; + return NULL; + } + else + { + /* Enlarge the buffer. */ + prtbuflen *= 2; + prttmpbuf = alloca (prtbuflen); + } sock = RPC_ANYSOCK; switch (p->p_proto) diff --git a/libc/inet/rpc/getrpcent.c b/libc/inet/rpc/getrpcent.c index e290449c0..b796d856d 100644 --- a/libc/inet/rpc/getrpcent.c +++ b/libc/inet/rpc/getrpcent.c @@ -42,6 +42,7 @@ #include <netdb.h> #include <sys/socket.h> #include <arpa/inet.h> +#include <errno.h> /* * Internet version. @@ -58,46 +59,37 @@ static struct rpcdata { char *domain; } *rpcdata; -static struct rpcent *interpret(const char *val, int len); - static char RPCDB[] = "/etc/rpc"; static struct rpcdata *_rpcdata(void) { register struct rpcdata *d = rpcdata; - if (d == 0) { + if (d == NULL) { d = (struct rpcdata *) calloc(1, sizeof(struct rpcdata)); rpcdata = d; } - return (d); + return d; } -struct rpcent *getrpcbynumber(number) -register int number; +struct rpcent *getrpcbynumber(register int number) { register struct rpcdata *d = _rpcdata(); - register struct rpcent *p; + register struct rpcent *rpc; - if (d == 0) - return (0); + if (d == NULL) + return NULL; setrpcent(0); - while ((p = getrpcent())) { - if (p->r_number == number) + while ((rpc = getrpcent())) { + if (rpc->r_number == number) break; } endrpcent(); - return (p); + return rpc; } -struct rpcent * -#ifdef __linux__ -getrpcbyname(const char *name) -#else -getrpcbyname(name) -char *name; -#endif +struct rpcent *getrpcbyname(const char *name) { struct rpcent *rpc; char **rp; @@ -105,25 +97,21 @@ char *name; setrpcent(0); while ((rpc = getrpcent())) { if (strcmp(rpc->r_name, name) == 0) - return (rpc); + return rpc; for (rp = rpc->r_aliases; *rp != NULL; rp++) { if (strcmp(*rp, name) == 0) - return (rpc); + return rpc; } } endrpcent(); - return (NULL); + return NULL; } -#ifdef __linux__ -void -#endif -setrpcent(f) -int f; +void setrpcent(int f) { register struct rpcdata *d = _rpcdata(); - if (d == 0) + if (d == NULL) return; if (d->rpcf == NULL) d->rpcf = fopen(RPCDB, "r"); @@ -135,36 +123,42 @@ int f; d->stayopen |= f; } -#ifdef __linux__ -void -#endif -endrpcent() +void endrpcent() { register struct rpcdata *d = _rpcdata(); - if (d == 0) + if (d == NULL) return; - if (d->current && !d->stayopen) { + if (d->stayopen) + return; + if (d->current) { free(d->current); d->current = NULL; } - if (d->rpcf && !d->stayopen) { + if (d->rpcf) { fclose(d->rpcf); d->rpcf = NULL; } } +static struct rpcent *interpret(struct rpcdata *); + +static struct rpcent *__get_next_rpcent(struct rpcdata *d) +{ + if (fgets(d->line, BUFSIZ, d->rpcf) == NULL) + return NULL; + return interpret(d); +} + struct rpcent *getrpcent() { register struct rpcdata *d = _rpcdata(); - if (d == 0) - return (NULL); + if (d == NULL) + return NULL; if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL) - return (NULL); - if (fgets(d->line, BUFSIZ, d->rpcf) == NULL) - return (NULL); - return interpret(d->line, strlen(d->line)); + return NULL; + return __get_next_rpcent(d); } #ifdef __linux__ @@ -184,37 +178,33 @@ static char *firstwhite(char *s) } #endif -static struct rpcent *interpret(const char *val, int len) +static struct rpcent *interpret(register struct rpcdata *d) { - register struct rpcdata *d = _rpcdata(); char *p; register char *cp, **q; - if (d == 0) - return NULL; - strncpy(d->line, val, len); p = d->line; - d->line[len] = '\n'; + d->line[strlen(p)-1] = '\n'; if (*p == '#') - return (getrpcent()); + return __get_next_rpcent(d); cp = index(p, '#'); if (cp == NULL) { cp = index(p, '\n'); if (cp == NULL) - return (getrpcent()); + return __get_next_rpcent(d); } *cp = '\0'; #ifdef __linux__ if ((cp = firstwhite(p))) *cp++ = 0; else - return (getrpcent()); + return __get_next_rpcent(d); #else cp = index(p, ' '); if (cp == NULL) { cp = index(p, '\t'); if (cp == NULL) - return (getrpcent()); + return __get_next_rpcent(d); } *cp++ = '\0'; #endif @@ -259,5 +249,102 @@ static struct rpcent *interpret(const char *val, int len) #endif } *q = NULL; - return (&d->rpc); + return &d->rpc; +} + +#if defined(__UCLIBC_HAS_REENTRANT_RPC__) + +#if defined(__UCLIBC_HAS_THREADS__) +# include <pthread.h> +static pthread_mutex_t rpcdata_lock = PTHREAD_MUTEX_INITIALIZER; +# define LOCK __pthread_mutex_lock(&rpcdata_lock) +# define UNLOCK __pthread_mutex_unlock(&rpcdata_lock); +#else +# define LOCK +# define UNLOCK +#endif + +static int __copy_rpcent(struct rpcent *r, struct rpcent *result_buf, char *buffer, + size_t buflen, struct rpcent **result) +{ + size_t i, s; + + *result = NULL; + + if (!r) + return ENOENT; + + /* copy the struct from the shared mem */ + memset(result_buf, 0x00, sizeof(*result_buf)); + memset(buffer, 0x00, buflen); + + result_buf->r_number = r->r_number; + + /* copy the aliases ... need to not only copy the alias strings, + * but the array of pointers to the alias strings */ + i = 0; + while (r->r_aliases[i++]) ; + + s = i-- * sizeof(char*); + if (buflen < s) + goto err_out; + result_buf->r_aliases = (char**)buffer; + buffer += s; + buflen -= s; + + while (i-- > 0) { + s = strlen(r->r_aliases[i]) + 1; + if (buflen < s) + goto err_out; + result_buf->r_aliases[i] = buffer; + buffer += s; + buflen -= s; + memcpy(result_buf->r_aliases[i], r->r_aliases[i], s); + } + + /* copy the name */ + i = strlen(r->r_name); + if (buflen <= i) + goto err_out; + result_buf->r_name = buffer; + memcpy(result_buf->r_name, r->r_name, i); + + /* that was a hoot eh ? */ + *result = result_buf; + + return 0; +err_out: + return ERANGE; +} + +int getrpcbynumber_r(int number, struct rpcent *result_buf, char *buffer, + size_t buflen, struct rpcent **result) +{ + int ret; + LOCK; + ret = __copy_rpcent(getrpcbynumber(number), result_buf, buffer, buflen, result); + UNLOCK; + return ret; +} + +int getrpcbyname_r(const char *name, struct rpcent *result_buf, char *buffer, + size_t buflen, struct rpcent **result) +{ + int ret; + LOCK; + ret = __copy_rpcent(getrpcbyname(name), result_buf, buffer, buflen, result); + UNLOCK; + return ret; +} + +int getrpcent_r(struct rpcent *result_buf, char *buffer, + size_t buflen, struct rpcent **result) +{ + int ret; + LOCK; + ret = __copy_rpcent(getrpcent(), result_buf, buffer, buflen, result); + UNLOCK; + return ret; } + +#endif /* __UCLIBC_HAS_REENTRANT_RPC__ */ diff --git a/libc/inet/rpc/rcmd.c b/libc/inet/rpc/rcmd.c index cf839f4c6..af0e2e17a 100644 --- a/libc/inet/rpc/rcmd.c +++ b/libc/inet/rpc/rcmd.c @@ -57,11 +57,6 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #include <netinet/in.h> #include <arpa/inet.h> -#ifdef __UCLIBC_HAS_THREADS__ -#undef __UCLIBC_HAS_THREADS__ -#warning FIXME I am not reentrant yet... -#endif - /* some forward declarations */ static int __ivaliduser2(FILE *hostf, u_int32_t raddr, @@ -76,13 +71,13 @@ int rcmd(ahost, rport, locuser, remuser, cmd, fd2p) const char *locuser, *remuser, *cmd; int *fd2p; { -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ int herr; - struct hostent hostbuf; + struct hostent hostbuf; size_t hstbuflen; char *tmphstbuf; #endif - struct hostent *hp; + struct hostent *hp; struct sockaddr_in sin, from; struct pollfd pfd[2]; int32_t oldmask; @@ -92,7 +87,7 @@ int rcmd(ahost, rport, locuser, remuser, cmd, fd2p) pid = getpid(); -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ hstbuflen = 1024; #ifdef __ARCH_HAS_MMU__ tmphstbuf = alloca (hstbuflen); @@ -299,14 +294,14 @@ int ruserok(rhost, superuser, ruser, luser) struct hostent *hp; u_int32_t addr; char **ap; -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ size_t buflen; char *buffer; int herr; struct hostent hostbuf; #endif -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ buflen = 1024; #ifdef __ARCH_HAS_MMU__ buffer = alloca (buflen); @@ -432,7 +427,7 @@ iruserok2 (raddr, superuser, ruser, luser, rhost) size_t dirlen; uid_t uid; -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); struct passwd pwdbuf; #ifdef __ARCH_HAS_MMU__ @@ -515,7 +510,7 @@ __icheckhost (u_int32_t raddr, char *lhost, const char *rhost) int negate=1; /* Multiply return with this to get -1 instead of 1 */ char **pp; -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ int save_errno; size_t buflen; char *buffer; @@ -545,7 +540,7 @@ __icheckhost (u_int32_t raddr, char *lhost, const char *rhost) return negate * (! (raddr ^ laddr)); /* Better be a hostname. */ -#ifdef __UCLIBC_HAS_THREADS__ +#ifdef __UCLIBC_HAS_REENTRANT_RPC__ buflen = 1024; buffer = malloc(buflen); save_errno = errno; @@ -559,7 +554,7 @@ __icheckhost (u_int32_t raddr, char *lhost, const char *rhost) __set_errno (save_errno); #else hp = gethostbyname(lhost); -#endif /* __UCLIBC_HAS_THREADS__ */ +#endif /* __UCLIBC_HAS_REENTRANT_RPC__ */ if (hp == NULL) return 0; diff --git a/libc/stdlib/Makefile b/libc/stdlib/Makefile index 5a3ffe631..40d03521f 100644 --- a/libc/stdlib/Makefile +++ b/libc/stdlib/Makefile @@ -1,7 +1,7 @@ # Makefile for uClibc # # Copyright (C) 2000 by Lineo, inc. -# Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org> +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org> # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU Library General Public License as published by the Free @@ -86,7 +86,7 @@ CSRC = abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c mkstemp64.c \ getpt.c ptsname.c grantpt.c unlockpt.c gcvt.c drand48-iter.c jrand48.c \ jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \ nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \ - valloc.c + valloc.c posix_memalign.c ifeq ($(UCLIBC_HAS_FLOATS),y) CSRC += drand48.c drand48_r.c erand48.c erand48_r.c endif diff --git a/libc/string/wstring.c b/libc/string/wstring.c index acf1a2b0a..6f54ae615 100644 --- a/libc/string/wstring.c +++ b/libc/string/wstring.c @@ -1572,7 +1572,6 @@ int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen) #ifdef L___glibc_strerror_r weak_alias(__glibc_strerror_r,__strerror_r); -weak_alias(__glibc_strerror_r,_glibc_strerror_r); /* for 0.9.27 compat ... remove after 0.9.28 */ char *__glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen) { diff --git a/libc/sysdeps/linux/common/create_module.c b/libc/sysdeps/linux/common/create_module.c index e1a4cfb04..e37f8e804 100644 --- a/libc/sysdeps/linux/common/create_module.c +++ b/libc/sysdeps/linux/common/create_module.c @@ -31,7 +31,7 @@ #ifdef __NR_create_module -#if defined(__i386__) || defined(__m68k__) || defined(__arm__) || defined(__cris__) || defined(__i960__) +#if defined(__i386__) || defined(__m68k__) || defined(__arm__) || defined(__thumb__) || defined(__cris__) || defined(__i960__) #define __NR___create_module __NR_create_module #ifdef __STR_NR_create_module #define __STR_NR___create_module __STR_NR_create_module diff --git a/libc/sysdeps/linux/powerpc/Makefile b/libc/sysdeps/linux/powerpc/Makefile index eb212bac0..4c345c00f 100644 --- a/libc/sysdeps/linux/powerpc/Makefile +++ b/libc/sysdeps/linux/powerpc/Makefile @@ -25,10 +25,10 @@ SCRT_OBJ = $(patsubst %,S%, $(CRT_OBJ)) CTOR_TARGETS=$(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o SSRC=__longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S brk.S \ - clone.S __uClibc_syscall.S syscall.S + clone.S __uClibc_syscall.S syscall.S vfork.S SOBJS=$(patsubst %.S,%.o, $(SSRC)) -CSRC=mmap.c vfork.c __syscall_error.c pread_write.c ioctl.c +CSRC=mmap.c __syscall_error.c pread_write.c ioctl.c COBJS=$(patsubst %.c,%.o, $(CSRC)) OBJS=$(SOBJS) $(COBJS) |