]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2002-08-25 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@gnu.org>
Sun, 25 Aug 2002 23:15:57 +0000 (23:15 +0000)
committerRoland McGrath <roland@gnu.org>
Sun, 25 Aug 2002 23:15:57 +0000 (23:15 +0000)
* sysdeps/generic/utmp_file.c (LOCK_FILE): Check for error from fcntl.
(getutent_r_file, internal_getut_r): Updated all callers.
(getutline_r_file, pututline_file, updwtmp_file): Likewise.

sysdeps/generic/utmp_file.c

index d2a2b33ce0f2c08220b0e3eae502611165377901..1bd56f444949a45d4c79a905c3a6ac658faa3371 100644 (file)
@@ -67,7 +67,7 @@ static void timeout_handler (int signum) {};
   memset (&fl, '\0', sizeof (struct flock));                            \
   fl.l_type = (type);                                                   \
   fl.l_whence = SEEK_SET;                                               \
-  __fcntl ((fd), F_SETLKW, &fl)
+  if (__fcntl ((fd), F_SETLKW, &fl) < 0)
 
 #define UNLOCK_FILE(fd) \
   /* Unlock the file.  */                                               \
@@ -171,7 +171,11 @@ getutent_r_file (struct utmp *buffer, struct utmp **result)
       return -1;
     }
 
-  LOCK_FILE (file_fd, F_RDLCK);
+  LOCK_FILE (file_fd, F_RDLCK)
+    {
+      *result = NULL;
+      return -1;
+    }
 
   /* Read the next entry.  */
   nbytes = __read (file_fd, &last_entry, sizeof (struct utmp));
@@ -227,7 +231,8 @@ internal_getut_r (const struct utmp *id, struct utmp *buffer)
 {
   int result = -1;
 
-  LOCK_FILE (file_fd, F_RDLCK);
+  LOCK_FILE (file_fd, F_RDLCK)
+    return result;
 
 #if _HAVE_UT_TYPE - 0
   if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
@@ -325,7 +330,11 @@ getutline_r_file (const struct utmp *line, struct utmp *buffer,
       return -1;
     }
 
-  LOCK_FILE (file_fd, F_RDLCK);
+  LOCK_FILE (file_fd, F_RDLCK)
+    {
+      *result = NULL;
+      return -1;
+    }
 
   while (1)
     {
@@ -386,7 +395,8 @@ pututline_file (const struct utmp *data)
   else
     found = internal_getut_r (data, &buffer);
 
-  LOCK_FILE (file_fd, F_WRLCK);
+  LOCK_FILE (file_fd, F_WRLCK)
+    return NULL;
 
   if (found < 0)
     {
@@ -455,7 +465,11 @@ updwtmp_file (const char *file, const struct utmp *utmp)
   if (fd < 0)
     return -1;
 
-  LOCK_FILE (fd, F_WRLCK);
+  LOCK_FILE (fd, F_WRLCK)
+    {
+      __close (fd);
+      return result;
+    }
 
   /* Remember original size of log file.  */
   offset = __lseek64 (fd, 0, SEEK_END);