From 1478c2de052374c6356db5513749a144c13791b1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 7 Dec 2006 23:24:02 +0000 Subject: 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. --- libc/misc/ttyent/getttyent.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libc/misc/ttyent') 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) -- cgit v1.2.3