diff options
author | Eric Andersen <andersen@codepoet.org> | 2006-12-07 23:24:02 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2006-12-07 23:24:02 +0000 |
commit | 1478c2de052374c6356db5513749a144c13791b1 (patch) | |
tree | 3b22a3f8361f94c99508c497e240ecb71acf8641 | |
parent | 99d6c367c4820a072dc4ada51561df17e2093778 (diff) |
Major cleanup of internal mutex locking. Be more consistant in how we do
things, and avoid potential deadlocks caused when a thread holding a uClibc
internal lock get canceled and terminates without releasing the lock. This
change also provides a single place, bits/uClibc_mutex.h, for thread libraries
to modify to change all instances of internal locking.
39 files changed, 998 insertions, 998 deletions
diff --git a/include/printf.h b/include/printf.h index 569397cd2..a68c6daad 100644 --- a/include/printf.h +++ b/include/printf.h @@ -75,6 +75,7 @@ struct printf_info unsigned int is_short:1; /* h flag. */ unsigned int is_long:1; /* l flag. */ unsigned int is_long_double:1;/* L flag. */ + unsigned int __padding:20;/* non-gnu -- total of 32 bits on 32bit arch */ #elif __BYTE_ORDER == __BIG_ENDIAN diff --git a/libc/inet/getnetent.c b/libc/inet/getnetent.c index d3fdb988a..d5c25034c 100644 --- a/libc/inet/getnetent.c +++ b/libc/inet/getnetent.c @@ -29,12 +29,8 @@ libc_hidden_proto(rewind) libc_hidden_proto(fgets) libc_hidden_proto(abort) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; -#endif -#define LOCK __pthread_mutex_lock(&mylock) -#define UNLOCK __pthread_mutex_unlock(&mylock) +#include <bits/uClibc_mutex.h> +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); @@ -50,13 +46,13 @@ int _net_stayopen attribute_hidden; libc_hidden_proto(setnetent) void setnetent(int f) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (netf == NULL) netf = fopen(NETDB, "r" ); else rewind(netf); _net_stayopen |= f; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return; } libc_hidden_def(setnetent) @@ -64,13 +60,13 @@ libc_hidden_def(setnetent) libc_hidden_proto(endnetent) void endnetent(void) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (netf) { fclose(netf); netf = NULL; } _net_stayopen = 0; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } libc_hidden_def(endnetent) @@ -92,11 +88,11 @@ struct netent *getnetent(void) { char *p; register char *cp, **q; + struct netent *rv = NULL; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) { - UNLOCK; - return (NULL); + goto DONE; } again: @@ -108,8 +104,7 @@ again: p = fgets(line, BUFSIZ, netf); if (p == NULL) { - UNLOCK; - return (NULL); + goto DONE; } if (*p == '#') goto again; @@ -144,7 +139,9 @@ again: *cp++ = '\0'; } *q = NULL; - UNLOCK; - return (&net); + rv = &net; +DONE: + __UCLIBC_MUTEX_UNLOCK(mylock); + return rv; } libc_hidden_def(getnetent) diff --git a/libc/inet/getproto.c b/libc/inet/getproto.c index a54532ede..7800eecb4 100644 --- a/libc/inet/getproto.c +++ b/libc/inet/getproto.c @@ -70,12 +70,8 @@ libc_hidden_proto(fgets) libc_hidden_proto(fclose) libc_hidden_proto(abort) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; -#endif -#define LOCK __pthread_mutex_lock(&mylock) -#define UNLOCK __pthread_mutex_unlock(&mylock) +#include <bits/uClibc_mutex.h> +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); @@ -99,26 +95,26 @@ static void __initbuf(void) libc_hidden_proto(setprotoent) void setprotoent(int f) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (protof == NULL) protof = fopen(_PATH_PROTOCOLS, "r" ); else rewind(protof); proto_stayopen |= f; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } libc_hidden_def(setprotoent) libc_hidden_proto(endprotoent) void endprotoent(void) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (protof) { fclose(protof); protof = NULL; } proto_stayopen = 0; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } libc_hidden_def(endprotoent) @@ -131,6 +127,7 @@ int getprotoent_r(struct protoent *result_buf, register char *cp, **q; char **proto_aliases; char *line; + int rv; *result = NULL; @@ -138,28 +135,27 @@ int getprotoent_r(struct protoent *result_buf, errno=ERANGE; return errno; } - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); proto_aliases=(char **)buf; buf+=sizeof(*proto_aliases)*MAXALIASES; buflen-=sizeof(*proto_aliases)*MAXALIASES; if (buflen < BUFSIZ+1) { - UNLOCK; - errno=ERANGE; - return errno; + errno=rv=ERANGE; + goto DONE; } line=buf; buf+=BUFSIZ+1; buflen-=BUFSIZ+1; if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) { - UNLOCK; - return errno; + rv=errno; + goto DONE; } again: if ((p = fgets(line, BUFSIZ, protof)) == NULL) { - UNLOCK; - return TRY_AGAIN; + rv=TRY_AGAIN; + goto DONE; } if (*p == '#') @@ -196,7 +192,9 @@ again: } *q = NULL; *result=result_buf; - UNLOCK; + rv = 0; +DONE: + __UCLIBC_MUTEX_UNLOCK(mylock); return 0; } libc_hidden_def(getprotoent_r) @@ -220,7 +218,7 @@ int getprotobyname_r(const char *name, register char **cp; int ret; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); setprotoent(proto_stayopen); while (!(ret=getprotoent_r(result_buf, buf, buflen, result))) { if (strcmp(result_buf->p_name, name) == 0) @@ -232,7 +230,7 @@ int getprotobyname_r(const char *name, found: if (!proto_stayopen) endprotoent(); - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; } libc_hidden_def(getprotobyname_r) @@ -256,14 +254,14 @@ int getprotobynumber_r (int proto_num, { int ret; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); setprotoent(proto_stayopen); while (!(ret=getprotoent_r(result_buf, buf, buflen, result))) if (result_buf->p_proto == proto_num) break; if (!proto_stayopen) endprotoent(); - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; } libc_hidden_def(getprotobynumber_r) diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c index 7f4939bbd..5a94c9c69 100644 --- a/libc/inet/getservice.c +++ b/libc/inet/getservice.c @@ -72,12 +72,8 @@ libc_hidden_proto(rewind) libc_hidden_proto(fgets) libc_hidden_proto(abort) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; -#endif -#define LOCK __pthread_mutex_lock(&mylock) -#define UNLOCK __pthread_mutex_unlock(&mylock) +#include <bits/uClibc_mutex.h> +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); @@ -102,26 +98,26 @@ static void __initbuf(void) libc_hidden_proto(setservent) void setservent(int f) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (servf == NULL) servf = fopen(_PATH_SERVICES, "r" ); else rewind(servf); serv_stayopen |= f; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } libc_hidden_def(setservent) libc_hidden_proto(endservent) void endservent(void) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (servf) { fclose(servf); servf = NULL; } serv_stayopen = 0; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } libc_hidden_def(endservent) @@ -134,6 +130,7 @@ int getservent_r(struct servent * result_buf, register char *cp, **q; char **serv_aliases; char *line; + int rv; *result=NULL; @@ -141,30 +138,27 @@ int getservent_r(struct servent * result_buf, errno=ERANGE; return errno; } - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); serv_aliases=(char **)buf; buf+=sizeof(*serv_aliases)*MAXALIASES; buflen-=sizeof(*serv_aliases)*MAXALIASES; if (buflen < BUFSIZ+1) { - UNLOCK; - errno=ERANGE; - return errno; + errno=rv=ERANGE; + goto DONE; } line=buf; buf+=BUFSIZ+1; buflen-=BUFSIZ+1; if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) { - UNLOCK; - errno=EIO; - return errno; + errno=rv=EIO; + goto DONE; } again: if ((p = fgets(line, BUFSIZ, servf)) == NULL) { - UNLOCK; - errno=EIO; - return errno; + errno=rv=EIO; + goto DONE; } if (*p == '#') goto again; @@ -202,8 +196,10 @@ again: } *q = NULL; *result=result_buf; - UNLOCK; - return 0; + rv = 0; +DONE: + __UCLIBC_MUTEX_UNLOCK(mylock); + return rv; } libc_hidden_def(getservent_r) @@ -224,7 +220,7 @@ int getservbyname_r(const char *name, const char *proto, register char **cp; int ret; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); setservent(serv_stayopen); while (!(ret=getservent_r(result_buf, buf, buflen, result))) { if (strcmp(name, result_buf->s_name) == 0) @@ -239,7 +235,7 @@ gotname: } if (!serv_stayopen) endservent(); - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; } libc_hidden_def(getservbyname_r) @@ -261,7 +257,7 @@ int getservbyport_r(int port, const char *proto, { int ret; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); setservent(serv_stayopen); while (!(ret=getservent_r(result_buf, buf, buflen, result))) { if (result_buf->s_port != port) @@ -271,7 +267,7 @@ int getservbyport_r(int port, const char *proto, } if (!serv_stayopen) endservent(); - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; } libc_hidden_def(getservbyport_r) diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index 26d68d26a..fab534ddf 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -7,7 +7,7 @@ * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. -*/ + */ /* * Portions Copyright (c) 1985, 1993 @@ -153,6 +153,8 @@ #include <arpa/nameser.h> #include <sys/utsname.h> #include <sys/un.h> +#include <bits/uClibc_mutex.h> + libc_hidden_proto(memcpy) libc_hidden_proto(memset) @@ -207,6 +209,9 @@ libc_hidden_proto(__ctype_b_loc) libc_hidden_proto(__ctype_b) #endif +__UCLIBC_MUTEX_EXTERN(__resolv_lock); + + #define MAX_RECURSE 5 #define REPLY_TIMEOUT 10 #define MAX_RETRIES 3 @@ -216,7 +221,7 @@ libc_hidden_proto(__ctype_b) #define MAX_ALIASES 5 /* 1:ip + 1:full + MAX_ALIASES:aliases + 1:NULL */ -#define ALIAS_DIM (2 + MAX_ALIASES + 1) +#define ALIAS_DIM (2 + MAX_ALIASES + 1) #undef DEBUG /* #define DEBUG */ @@ -235,12 +240,6 @@ extern int __searchdomains attribute_hidden; extern char * __searchdomain[MAX_SEARCH] attribute_hidden; -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -extern pthread_mutex_t __resolv_lock; -#endif -#define BIGLOCK __pthread_mutex_lock(&__resolv_lock) -#define BIGUNLOCK __pthread_mutex_unlock(&__resolv_lock) @@ -608,11 +607,11 @@ int __encode_packet(struct resolv_header *h, struct resolv_answer **ar, unsigned char *dest, int maxlen) attribute_hidden; int __encode_packet(struct resolv_header *h, - struct resolv_question **q, - struct resolv_answer **an, - struct resolv_answer **ns, - struct resolv_answer **ar, - unsigned char *dest, int maxlen) + struct resolv_question **q, + struct resolv_answer **an, + struct resolv_answer **ns, + struct resolv_answer **ar, + unsigned char *dest, int maxlen) { int i, total = 0; int j; @@ -674,7 +673,7 @@ int __decode_packet(unsigned char *data, struct resolv_header *h) #ifdef L_formquery int __form_query(int id, const char *name, int type, unsigned char *packet, int maxlen); int __form_query(int id, const char *name, int type, unsigned char *packet, - int maxlen) + int maxlen) { struct resolv_header h; struct resolv_question q; @@ -700,16 +699,8 @@ int __form_query(int id, const char *name, int type, unsigned char *packet, } #endif -#if defined(L_dnslookup) || defined(L_gethostent) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; -#endif -#define LOCK __pthread_mutex_lock(&mylock) -#define UNLOCK __pthread_mutex_unlock(&mylock) -#endif - #ifdef L_dnslookup +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); /* Just for the record, having to lock __dns_lookup() just for these two globals * is pretty lame. I think these two variables can probably be de-global-ized, @@ -746,10 +737,10 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char DPRINTF("Looking up type %d answer for '%s'\n", type, name); /* Mess with globals while under lock */ - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); local_ns = ns % nscount; local_id = id; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); while (retries < MAX_RETRIES) { if (fd != -1) @@ -775,13 +766,13 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char strncpy(lookup,name,MAXDNAME); if (variant >= 0) { - BIGLOCK; - if (variant < __searchdomains) { - strncat(lookup,".", MAXDNAME); - strncat(lookup,__searchdomain[variant], MAXDNAME); - } - BIGUNLOCK; - } + __UCLIBC_MUTEX_LOCK(__resolv_lock); + if (variant < __searchdomains) { + strncat(lookup,".", MAXDNAME); + strncat(lookup,__searchdomain[variant], MAXDNAME); + } + __UCLIBC_MUTEX_UNLOCK(__resolv_lock); + } DPRINTF("lookup name: %s\n", lookup); q.dotted = (char *)lookup; q.qtype = type; @@ -803,7 +794,7 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); #endif if (fd < 0) { - retries++; + retries++; continue; } @@ -825,11 +816,11 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char #endif if (rc < 0) { if (errno == ENETUNREACH) { - /* routing error, presume not transient */ - goto tryall; + /* routing error, presume not transient */ + goto tryall; } else - /* retry */ - retries++; + /* retry */ + retries++; continue; } @@ -891,55 +882,55 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char first_answer = 1; for (j=0;j<h.ancount;j++,pos += i) - { - i = __decode_answer(packet, pos, &ma); + { + i = __decode_answer(packet, pos, &ma); - if (i<0) { - DPRINTF("failed decode %d\n", i); - goto again; - } + if (i<0) { + DPRINTF("failed decode %d\n", i); + goto again; + } - if ( first_answer ) - { - ma.buf = a->buf; - ma.buflen = a->buflen; - ma.add_count = a->add_count; - memcpy(a, &ma, sizeof(ma)); - if (a->atype != T_SIG && (0 == a->buf || (type != T_A && type != T_AAAA))) - { - break; - } - if (a->atype != type) - { - free(a->dotted); - continue; - } - a->add_count = h.ancount - j - 1; - if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen) - { - break; - } - a->add_count = 0; - first_answer = 0; - } - else - { - free(ma.dotted); - if (ma.atype != type) - { - continue; - } - if (a->rdlength != ma.rdlength) - { - free(a->dotted); - DPRINTF("Answer address len(%u) differs from original(%u)\n", - ma.rdlength, a->rdlength); - goto again; + if ( first_answer ) + { + ma.buf = a->buf; + ma.buflen = a->buflen; + ma.add_count = a->add_count; + memcpy(a, &ma, sizeof(ma)); + if (a->atype != T_SIG && (0 == a->buf || (type != T_A && type != T_AAAA))) + { + break; + } + if (a->atype != type) + { + free(a->dotted); + continue; + } + a->add_count = h.ancount - j - 1; + if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen) + { + break; + } + a->add_count = 0; + first_answer = 0; + } + else + { + free(ma.dotted); + if (ma.atype != type) + { + continue; + } + if (a->rdlength != ma.rdlength) + { + free(a->dotted); + DPRINTF("Answer address len(%u) differs from original(%u)\n", + ma.rdlength, a->rdlength); + goto again; + } + memcpy(a->buf + (a->add_count * ma.rdlength), ma.rdata, ma.rdlength); + ++a->add_count; + } } - memcpy(a->buf + (a->add_count * ma.rdlength), ma.rdata, ma.rdlength); - ++a->add_count; - } - } DPRINTF("Answer name = |%s|\n", a->dotted); DPRINTF("Answer type = |%d|\n", a->atype); @@ -953,48 +944,48 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char free(lookup); /* Mess with globals while under lock */ - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); ns = local_ns; id = local_id; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return (len); /* success! */ - tryall: + tryall: /* if there are other nameservers, give them a go, otherwise return with error */ { variant = -1; - local_ns = (local_ns + 1) % nscount; - if (local_ns == 0) - retries++; + local_ns = (local_ns + 1) % nscount; + if (local_ns == 0) + retries++; - continue; + continue; } - again: + again: /* if there are searchdomains, try them or fallback as passed */ { int sdomains; - BIGLOCK; + __UCLIBC_MUTEX_LOCK(__resolv_lock); sdomains=__searchdomains; - BIGUNLOCK; + __UCLIBC_MUTEX_UNLOCK(__resolv_lock); if (variant < sdomains - 1) { - /* next search */ - variant++; + /* next search */ + variant++; } else { - /* next server, first search */ - local_ns = (local_ns + 1) % nscount; - if (local_ns == 0) - retries++; + /* next server, first search */ + local_ns = (local_ns + 1) % nscount; + if (local_ns == 0) + retries++; - variant = -1; + variant = -1; } } } -fail: + fail: if (fd != -1) close(fd); if (lookup) @@ -1004,10 +995,10 @@ fail: h_errno = NETDB_INTERNAL; /* Mess with globals while under lock */ if (local_ns != -1) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); ns = local_ns; id = local_id; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } return -1; } @@ -1019,10 +1010,8 @@ int __nameservers; char * __nameserver[MAX_SERVERS]; int __searchdomains; char * __searchdomain[MAX_SEARCH]; -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -pthread_mutex_t __resolv_lock = PTHREAD_MUTEX_INITIALIZER; -#endif + +__UCLIBC_MUTEX_STATIC(__resolv_lock, PTHREAD_MUTEX_INITIALIZER); /* * we currently read formats not quite the same as that on normal @@ -1036,60 +1025,63 @@ int attribute_hidden __open_nameservers() #define RESOLV_ARGS 5 char szBuffer[128], *p, *argv[RESOLV_ARGS]; int argc; + int rv = 0; - BIGLOCK; + __UCLIBC_MUTEX_LOCK(__resolv_lock); if (__nameservers > 0) { - BIGUNLOCK; - return 0; + goto DONE; } if ((fp = fopen("/etc/resolv.conf", "r")) || - (fp = fopen("/etc/config/resolv.conf", "r"))) - { - - while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) { - - for (p = szBuffer; *p && isspace(*p); p++) - /* skip white space */; - if (*p == '\0' || *p == '\n' || *p == '#') /* skip comments etc */ - continue; - argc = 0; - while (*p && argc < RESOLV_ARGS) { - argv[argc++] = p; - while (*p && !isspace(*p) && *p != '\n') - p++; - while (*p && (isspace(*p) || *p == '\n')) /* remove spaces */ - *p++ = '\0'; - } + (fp = fopen("/etc/config/resolv.conf", "r"))) + { - if (strcmp(argv[0], "nameserver") == 0) { - for (i = 1; i < argc && __nameservers < MAX_SERVERS; i++) { - __nameserver[__nameservers++] = strdup(argv[i]); - DPRINTF("adding nameserver %s\n", argv[i]); + while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) { + + for (p = szBuffer; *p && isspace(*p); p++) + /* skip white space */; + if (*p == '\0' || *p == '\n' || *p == '#') /* skip comments etc */ + continue; + argc = 0; + while (*p && argc < RESOLV_ARGS) { + argv[argc++] = p; + while (*p && !isspace(*p) && *p != '\n') + p++; + while (*p && (isspace(*p) || *p == '\n')) /* remove spaces */ + *p++ = '\0'; } - } - /* domain and search are mutually exclusive, the last one wins */ - if (strcmp(argv[0],"domain")==0 || strcmp(argv[0],"search")==0) { - while (__searchdomains > 0) { - free(__searchdomain[--__searchdomains]); - __searchdomain[__searchdomains] = NULL; + if (strcmp(argv[0], "nameserver") == 0) { + for (i = 1; i < argc && __nameservers < MAX_SERVERS; i++) { + __nameserver[__nameservers++] = strdup(argv[i]); + DPRINTF("adding nameserver %s\n", argv[i]); + } } - for (i=1; i < argc && __searchdomains < MAX_SEARCH; i++) { - __searchdomain[__searchdomains++] = strdup(argv[i]); - DPRINTF("adding search %s\n", argv[i]); + + /* domain and search are mutually exclusive, the last one wins */ + if (strcmp(argv[0],"domain")==0 || strcmp(argv[0],"search")==0) { + while (__searchdomains > 0) { + free(__searchdomain[--__searchdomains]); + __searchdomain[__searchdomains] = NULL; + } + for (i=1; i < argc && __searchdomains < MAX_SEARCH; i++) { + __searchdomain[__searchdomains++] = strdup(argv[i]); + DPRINTF("adding search %s\n", argv[i]); + } } } + fclose(fp); + DPRINTF("nameservers = %d\n", __nameservers); + goto DONE; } - fclose(fp); - DPRINTF("nameservers = %d\n", __nameservers); - BIGUNLOCK; - return 0; - } DPRINTF("failed to open %s\n", "resolv.conf"); h_errno = NO_RECOVERY; - BIGUNLOCK; - return -1; + + rv = -1; + + DONE: + __UCLIBC_MUTEX_UNLOCK(__resolv_lock); + return rv; } #endif @@ -1098,7 +1090,7 @@ int attribute_hidden __open_nameservers() void attribute_hidden __close_nameservers(void) { - BIGLOCK; + __UCLIBC_MUTEX_LOCK(__resolv_lock); while (__nameservers > 0) { free(__nameserver[--__nameservers]); __nameserver[__nameservers] = NULL; @@ -1107,7 +1099,7 @@ void attribute_hidden __close_nameservers(void) free(__searchdomain[--__searchdomains]); __searchdomain[__searchdomains] = NULL; } - BIGUNLOCK; + __UCLIBC_MUTEX_U |