about summary refs log tree commit diff
path: root/login/programs
diff options
context:
space:
mode:
Diffstat (limited to 'login/programs')
-rw-r--r--login/programs/database.c60
-rw-r--r--login/programs/utmpdump.c12
-rw-r--r--login/programs/xtmp.c30
-rw-r--r--login/programs/xtmp.h2
4 files changed, 68 insertions, 36 deletions
diff --git a/login/programs/database.c b/login/programs/database.c
index 00d573f336..7044cd8d87 100644
--- a/login/programs/database.c
+++ b/login/programs/database.c
@@ -88,7 +88,7 @@ open_database (const char *file, const char *old_file)
 	  error (0, errno, "%s", old_file);
 	  goto return_error;
 	}
-  
+
       database->old_file = strdup (old_file);
       if (database->old_file == NULL)
 	{
@@ -100,12 +100,12 @@ open_database (const char *file, const char *old_file)
   /* Initialize database.  */
   if (initialize_database (database) < 0)
     goto return_error;
-  
+
   return database;
 
 return_error:
   close_database (database);
-  
+
   return NULL;
 }
 
@@ -121,16 +121,16 @@ synchronize_database (utmp_database *database)
     {
       time_t curtime;
       time_t mtime;
-      
+
       curtime = time (NULL);
-      
+
       if (get_mtime (database->old_fd, &mtime) < 0)
 	{
 	  error (0, errno, _("%s: cannot get modification time"),
 		 database->old_file);
 	  return -1;
 	}
-      
+
       if (mtime >= database->mtime)
 	{
 	  int position = 0;
@@ -141,7 +141,7 @@ synchronize_database (utmp_database *database)
 	    {
 	      if (read_old_entry (database, position, &old_entry) < 0)
 		break;
-	      
+
 	      if (read_entry (database, position, &entry) < 0
 		  || !compare_entry (&old_entry, &entry))
 		{
@@ -157,7 +157,7 @@ synchronize_database (utmp_database *database)
 
 	  database->mtime = curtime;
 	}
-      
+
     }
 
   return 0;
@@ -175,7 +175,7 @@ close_database (utmp_database *database)
 
   if (database->old_fd >= 0)
     close (database->old_fd);
-  
+
   /* Free allocated memory.  */
   if (database->file)
     free (database->file);
@@ -200,7 +200,7 @@ read_entry (utmp_database *database, int position, struct utmp *entry)
   nbytes = read (database->fd, entry, sizeof (struct utmp));
   if (nbytes != sizeof (struct utmp))
     return -1;
-  
+
   return 0;
 }
 
@@ -221,7 +221,7 @@ write_entry (utmp_database *database, int position,
   fl.l_type = F_WRLCK;
   fl.l_whence = SEEK_SET;
   fcntl (database->fd, F_SETLKW, &fl);
-  
+
   offset = position * sizeof (struct utmp);
   if (lseek (database->fd, offset, SEEK_SET) < 0)
     goto fail;
@@ -259,7 +259,7 @@ append_entry (utmp_database *database, const struct utmp *entry)
   fl.l_type = F_WRLCK;
   fl.l_whence = SEEK_SET;
   fcntl (database->fd, F_SETLKW, &fl);
-  
+
   offset = lseek (database->fd, 0, SEEK_END);
   if (offset % sizeof (struct utmp) != 0)
     {
@@ -278,7 +278,7 @@ append_entry (utmp_database *database, const struct utmp *entry)
     }
 
   result = offset / sizeof (struct utmp);
-  
+
 fail:
   /* And unlock the file.  */
   fl.l_type = F_UNLCK;
@@ -303,7 +303,7 @@ read_old_entry (utmp_database *database, int position,
   nbytes = read (database->old_fd, &old_entry, sizeof (struct xtmp));
   if (nbytes != sizeof (struct xtmp))
     return -1;
-  
+
   xtmp_to_utmp (&old_entry, entry);
   return 0;
 }
@@ -318,7 +318,7 @@ write_old_entry (utmp_database *database, int position,
   off_t offset;
 
   utmp_to_xtmp (entry, &old_entry);
-  
+
   offset = position * sizeof (struct xtmp);
   if (lseek (database->old_fd, offset, SEEK_SET) < 0)
     return -1;
@@ -337,7 +337,7 @@ initialize_database (utmp_database *database)
 {
   struct utmp entry;
   int position = 0;
-  
+
   assert (database);
 
   /* Check if there is a file in the old format to read.  */
@@ -395,6 +395,7 @@ initialize_database (utmp_database *database)
 }
 
 
+#if _HAVE_UT_TYPE - 0
 static int
 store_state_entry (utmp_database *database, int old_position,
 		   const struct utmp *old_entry)
@@ -413,7 +414,7 @@ store_state_entry (utmp_database *database, int old_position,
       /* Read the next entry.  */
       if (read_entry (database, new_position, &new_entry) < 0)
 	break;
-      
+
       if (old_entry->ut_type == new_entry.ut_type)
 	{
 	  found = 1;
@@ -428,16 +429,23 @@ store_state_entry (utmp_database *database, int old_position,
     {
       const struct utmp *entry;
 
-      if (old_entry->ut_time > new_entry.ut_time)
+      if (
+#if _HAVE_UT_TV - 0
+	  old_entry->ut_tv.tv_sec > new_entry.ut_tv.tv_sec
+#else
+	  old_entry->ut_time > new_entry.ut_time
+#endif
+	  )
 	entry = old_entry;
       else
 	entry = &new_entry;
-      
+
       return replace_entry (database, old_position, new_position, entry);
     }
 
   return store_entry (database, old_position, old_entry);
 }
+#endif
 
 
 static int
@@ -468,11 +476,17 @@ store_process_entry (utmp_database *database, int old_position,
     {
       const struct utmp *entry;
 
-      if (old_entry->ut_time > new_entry.ut_time)
+      if (
+#if _HAVE_UT_TV - 0
+	  old_entry->ut_tv.tv_sec > new_entry.ut_tv.tv_sec
+#else
+	  old_entry->ut_time > new_entry.ut_time
+#endif
+	  )
 	entry = old_entry;
       else
 	entry = &new_entry;
-      
+
       return replace_entry (database, old_position, new_position, entry);
     }
 
@@ -485,7 +499,7 @@ replace_entry (utmp_database *database, int old_position, int new_position,
 	       const struct utmp *entry)
 {
   struct utmp tmp;
-  
+
   if (read_entry (database, old_position, &tmp) < 0
       || write_entry (database, old_position, entry) < 0
       || write_entry (database, new_position, &tmp) < 0)
@@ -518,7 +532,7 @@ static int
 get_mtime (int filedes, time_t *timer)
 {
   struct stat st;
-  
+
   if (fstat (filedes, &st) < 0)
     return -1;
 
diff --git a/login/programs/utmpdump.c b/login/programs/utmpdump.c
index e1422b5028..7be404ce24 100644
--- a/login/programs/utmpdump.c
+++ b/login/programs/utmpdump.c
@@ -29,9 +29,15 @@
 void
 print_entry (struct utmp *up)
 {
+#if _HAVE_UT_TV - 0
   printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s] [%ld]\n",
 	  up->ut_type, up->ut_pid, up->ut_id, up->ut_user,
-	  up->ut_line, 4 + ctime (&up->ut_time), up->ut_tv.tv_usec);
+	  up->ut_line, 4 + ctime (&up->ut_tv.tv_sec), up->ut_tv.tv_usec);
+#else
+  printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s]\n",
+	  up->ut_type, up->ut_pid, up->ut_id, up->ut_user,
+	  up->ut_line, 4 + ctime (&up->ut_time));
+#endif
 }
 
 int
@@ -41,13 +47,13 @@ main (int argc, char *argv[])
 
   if (argc > 1)
     utmpname (argv[1]);
-  
+
   setutent ();
 
   while ((up = getutent ()))
     print_entry (up);
 
   endutent ();
-  
+
   return EXIT_SUCCESS;
 }
diff --git a/login/programs/xtmp.c b/login/programs/xtmp.c
index d2d5feee3b..105145b01d 100644
--- a/login/programs/xtmp.c
+++ b/login/programs/xtmp.c
@@ -42,7 +42,11 @@ xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp)
 #if _HAVE_XT_ID - 0
   strncpy (utmp->ut_id, xtmp->xt_id, sizeof xtmp->xt_id);
 #endif
+#if _HAVE_UT_TV - 0
+  utmp->ut_tv.tv_sec = xtmp->xt_time;
+#else
   utmp->ut_time = xtmp->xt_time;
+#endif
   strncpy (utmp->ut_user, xtmp->xt_user, XT_NAMESIZE);
 #if _HAVE_XT_HOST - 0
   strncpy (utmp->ut_host, xtmp->xt_host, XT_HOSTSIZE);
@@ -66,7 +70,11 @@ utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp)
 #if _HAVE_XT_ID - 0
   strncpy (xtmp->xt_id, utmp->ut_id, sizeof xtmp->xt_id);
 #endif
+#if _HAVE_UT_TV - 0
+  xtmp->xt_time = utmp->ut_tv.tv_sec;
+#else
   xtmp->xt_time = utmp->ut_time;
+#endif
   strncpy (xtmp->xt_user, utmp->ut_user, XT_NAMESIZE);
 #if _HAVE_XT_HOST - 0
   strncpy (xtmp->xt_host, utmp->ut_host, XT_HOSTSIZE);
@@ -79,24 +87,28 @@ utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp)
    function returns 1 if the information that is in both old and new
    style entries is identical.  Otherwise this function returns 0.  */
 int
-compare_entry (const struct utmp *xtmp, const struct utmp *utmp)
+compare_entry (const struct xtmp *xtmp, const struct utmp *utmp)
 {
   return
     (
 #if _HAVE_XT_TYPE - 0
-     xtmp->ut_type == utmp->ut_type
+     xtmp->xt_type == utmp->ut_type
 #endif
 #if _HAVE_XT_PID - 0
-     && xtmp->ut_pid == utmp->ut_pid
+     && xtmp->xt_pid == utmp->ut_pid
 #endif
-     && !strncmp (xtmp->ut_line, utmp->ut_line, XT_LINESIZE - 1)
+     && !strncmp (xtmp->xt_line, utmp->ut_line, XT_LINESIZE - 1)
 #if _HAVE_XT_ID - 0
-     && !strncmp (xtmp->ut_id, utmp->ut_id, sizeof utmp->ut_id)
+     && !strncmp (xtmp->xt_id, utmp->ut_id, sizeof utmp->ut_id)
+#endif
+#if _HAVE_UT_TV - 0
+     && xtmp->xt_time == utmp->ut_tv.tv_sec
+#else
+     && xtmp->xt_time == utmp->ut_time
 #endif
-     && xtmp->ut_time == utmp->ut_time
-     && !strncmp (xtmp->ut_user, utmp->ut_user, XT_NAMESIZE)
+     && !strncmp (xtmp->xt_user, utmp->ut_user, XT_NAMESIZE)
 #if _HAVE_XT_HOST - 0
-     && !strncmp (xtmp->ut_host, utmp->ut_host, XT_HOSTSIZE - 1)
+     && !strncmp (xtmp->xt_host, utmp->ut_host, XT_HOSTSIZE - 1)
 #endif
-     && xtmp->ut_addr == utmp->ut_addr);
+     && xtmp->xt_addr == utmp->ut_addr);
 }
diff --git a/login/programs/xtmp.h b/login/programs/xtmp.h
index 8fa982ee4f..508993248a 100644
--- a/login/programs/xtmp.h
+++ b/login/programs/xtmp.h
@@ -50,7 +50,7 @@ struct xtmp
 
 extern void xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp);
 extern void utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp);
-extern int compare_entry (const struct utmp *xtmp,
+extern int compare_entry (const struct xtmp *xtmp,
 			  const struct utmp *utmp);
 
 #endif /* xtmp.h  */