summary refs log tree commit diff
path: root/login/utmp_file.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-08-14 04:23:40 +0000
committerUlrich Drepper <drepper@redhat.com>2008-08-14 04:23:40 +0000
commit1bfa05cfaa4177476fd57851d867c5d1a276a34b (patch)
treee4c8f50704c119835b459e3d515489ae94692f7c /login/utmp_file.c
parentc5671698c8e953513a3456dcb60344bd2e7b1125 (diff)
downloadglibc-1bfa05cfaa4177476fd57851d867c5d1a276a34b.tar.gz
glibc-1bfa05cfaa4177476fd57851d867c5d1a276a34b.tar.xz
glibc-1bfa05cfaa4177476fd57851d867c5d1a276a34b.zip
[BZ #6634]
2008-08-13  Ulrich Drepper  <drepper@redhat.com>
	[BZ #6634]
	* login/utmp_file.c (getutent_r_file): Take additional parameter.
	Set to true if locking failed.
	(getutid_r_file): Adjust caller.
	(pututline_file): Likewise.  Return NULL in this case.
	Patch mostly by halesh.s@gmail.com.
Diffstat (limited to 'login/utmp_file.c')
-rw-r--r--login/utmp_file.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/login/utmp_file.c b/login/utmp_file.c
index c0bd229952..9033f72a4e 100644
--- a/login/utmp_file.c
+++ b/login/utmp_file.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -244,12 +245,16 @@ getutent_r_file (struct utmp *buffer, struct utmp **result)
 
 
 static int
-internal_getut_r (const struct utmp *id, struct utmp *buffer)
+internal_getut_r (const struct utmp *id, struct utmp *buffer,
+		  bool *lock_failed)
 {
   int result = -1;
 
   LOCK_FILE (file_fd, F_RDLCK)
-    LOCKING_FAILED ();
+    {
+      *lock_failed = true;
+      LOCKING_FAILED ();
+    }
 
 #if _HAVE_UT_TYPE - 0
   if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
@@ -320,7 +325,10 @@ getutid_r_file (const struct utmp *id, struct utmp *buffer,
       return -1;
     }
 
-  if (internal_getut_r (id, &last_entry) < 0)
+  /* We don't have to distinguish whether we can lock the file or
+     whether there is no entry.  */
+  bool lock_failed = false;
+  if (internal_getut_r (id, &last_entry, &lock_failed) < 0)
     {
       *result = NULL;
       return -1;
@@ -410,7 +418,16 @@ pututline_file (const struct utmp *data)
 	  __utmp_equal (&last_entry, data)))
     found = 1;
   else
-    found = internal_getut_r (data, &buffer);
+    {
+      bool lock_failed = false;
+      found = internal_getut_r (data, &buffer, &lock_failed);
+
+      if (__builtin_expect (lock_failed, false))
+	{
+	  __set_errno (EAGAIN);
+	  return NULL;
+	}
+    }
 
   LOCK_FILE (file_fd, F_WRLCK)
     {