summaryrefslogtreecommitdiff
path: root/libc/misc/ttyent/getttyent.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/misc/ttyent/getttyent.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/misc/ttyent/getttyent.c')
-rw-r--r--libc/misc/ttyent/getttyent.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c
index 89c39876f..c9c68f1cc 100644
--- a/libc/misc/ttyent/getttyent.c
+++ b/libc/misc/ttyent/getttyent.c
@@ -126,6 +126,7 @@ struct ttyent * getttyent(void)
register int c;
register char *p;
static char *line = NULL;
+ struct ttyent *retval = NULL;
if (!tf && !setttyent())
return (NULL);
@@ -140,8 +141,7 @@ struct ttyent * getttyent(void)
for (;;) {
if (!fgets_unlocked(p = line, BUFSIZ, tf)) {
- __STDIO_ALWAYS_THREADUNLOCK(tf);
- return (NULL);
+ goto DONE;
}
/* skip lines that are too big */
if (!strchr(p, '\n')) {
@@ -184,8 +184,6 @@ struct ttyent * getttyent(void)
else
break;
}
- /* We can release the lock only here since `zapchar' is global. */
- __STDIO_ALWAYS_THREADUNLOCK(tf);
if (zapchar == '#' || *p == '#')
while ((c = *++p) == ' ' || c == '\t')
@@ -195,7 +193,11 @@ struct ttyent * getttyent(void)
tty.ty_comment = 0;
if ((p = strchr(p, '\n')))
*p = '\0';
- return (&tty);
+ retval = &tty;
+
+ DONE:
+ __STDIO_ALWAYS_THREADUNLOCK(tf);
+ return retval;
}
libc_hidden_def(getttyent)