svn commit: trunk/uClibc/libc/misc/utmp

vapier at uclibc.org vapier at uclibc.org
Wed Mar 22 00:31:28 UTC 2006


Author: vapier
Date: 2006-03-21 16:31:24 -0800 (Tue, 21 Mar 2006)
New Revision: 14596

Log:
some more fixes from rholzmann in Bug 716 ... make sure the code actually functions, then we worry about shrinking it ...

Modified:
   trunk/uClibc/libc/misc/utmp/utent.c


Changeset:
Modified: trunk/uClibc/libc/misc/utmp/utent.c
===================================================================
--- trunk/uClibc/libc/misc/utmp/utent.c	2006-03-22 00:25:07 UTC (rev 14595)
+++ trunk/uClibc/libc/misc/utmp/utent.c	2006-03-22 00:31:24 UTC (rev 14596)
@@ -29,7 +29,6 @@
 libc_hidden_proto(fcntl)
 libc_hidden_proto(close)
 libc_hidden_proto(lseek)
-libc_hidden_proto(setutent)
 
 #ifdef __UCLIBC_HAS_THREADS__
 # include <pthread.h>
@@ -46,11 +45,11 @@
 static const char default_file_name[] = _PATH_UTMP;
 static const char *static_ut_name = (const char *) default_file_name;
 
-void setutent(void)
+/* This function must be called with the LOCK held */
+static void __setutent(void)
 {
     int ret;
 
-    LOCK;
     if (static_fd == -1) {
 	if ((static_fd = open(static_ut_name, O_RDWR)) < 0) {
 	    if ((static_fd = open(static_ut_name, O_RDONLY)) < 0) {
@@ -66,34 +65,39 @@
 bummer:
 	    static_fd = -1;
 	    close(static_fd);
-unlock_and_ret:
-	    UNLOCK;
 	    return;
 	}
     }
     lseek(static_fd, 0, SEEK_SET);
-    goto unlock_and_ret;
+    return;
 }
+
+libc_hidden_proto(setutent)
+void setutent(void)
+{
+    LOCK;
+    __setutent();
+    UNLOCK;
+}
 libc_hidden_def(setutent)
 
+/* This function must be called with the LOCK held */
 static struct utmp *__getutent(int utmp_fd)
 {
     struct utmp *ret = NULL;
 
     if (utmp_fd == -1) {
-	setutent();
+	__setutent();
     }
     if (utmp_fd == -1) {
 	return NULL;
     }
 
-    LOCK;
     if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp)) 
     {
 	ret = &static_utmp;
     }
 
-    UNLOCK;
     return ret;
 }
 
@@ -106,15 +110,19 @@
     UNLOCK;
 }
 
-/* Locking is done in __getutent */
 struct utmp *getutent(void)
 {
-    return __getutent(static_fd);
+    struct utmp *ret = NULL;
+
+    LOCK;
+    ret = __getutent(static_fd);
+    UNLOCK;
+
+    return ret;
 }
 
-/* Locking is done in __getutent */
-libc_hidden_proto(getutid)
-struct utmp *getutid (const struct utmp *utmp_entry)
+/* This function must be called with the LOCK held */
+static struct utmp *__getutid(const struct utmp *utmp_entry)
 {
     struct utmp *lutmp;
 
@@ -139,22 +147,34 @@
 
     return NULL;
 }
+
+libc_hidden_proto(getutid)
+struct utmp *getutid(const struct utmp *utmp_entry)
+{
+    struct utmp *ret = NULL;
+
+    LOCK;
+    ret = __getutid(utmp_entry);
+    UNLOCK;
+
+    return ret;
+}
 libc_hidden_def(getutid)
 
-/* Locking is done in __getutent */
 struct utmp *getutline(const struct utmp *utmp_entry)
 {
-    struct utmp *lutmp;
+    struct utmp *lutmp = NULL;
 
+    LOCK;
     while ((lutmp = __getutent(static_fd)) != NULL) {
 	if ((lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) &&
-		!strcmp(lutmp->ut_line, utmp_entry->ut_line))
-	{
-	    return lutmp;
+		!strcmp(lutmp->ut_line, utmp_entry->ut_line)) {
+	    break;
 	}
     }
+    UNLOCK;
 
-    return NULL;
+    return lutmp;
 }
 
 struct utmp *pututline (const struct utmp *utmp_entry)
@@ -164,7 +184,7 @@
        the file pointer where they want it, everything will work out. */
     lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
 
-    if (getutid(utmp_entry) != NULL)
+    if (__getutid(utmp_entry) != NULL)
 	lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
     else
 	lseek(static_fd, (off_t) 0, SEEK_END);




More information about the uClibc-cvs mailing list