summaryrefslogtreecommitdiff
path: root/libc/inet/getnetent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2006-12-07 23:24:02 +0000
committerEric Andersen <andersen@codepoet.org>2006-12-07 23:24:02 +0000
commit1478c2de052374c6356db5513749a144c13791b1 (patch)
tree3b22a3f8361f94c99508c497e240ecb71acf8641 /libc/inet/getnetent.c
parent99d6c367c4820a072dc4ada51561df17e2093778 (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.
Diffstat (limited to 'libc/inet/getnetent.c')
-rw-r--r--libc/inet/getnetent.c31
1 files changed, 14 insertions, 17 deletions
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)