[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MiNTOS 1.4.X: bug in last.c



 Hi Steve!

 I've always wondered why `last' seems to choke on my wtmp from time to
time. Point is that wtmp data is binary, but last reads it with fread()
and therefore struggles over the old CRLF/LF problem again. Since all
other parts of MiNTOS work quite well without setting UNIXMODE I consider
this a bug rather than a feature.

 Here's a fix. And once I'm at it, why not make it `gcc -Wall' clean? :)

ciao,
TeSche
--
Torsten Scherer (TeSche, Schiller...), itschere@techfak.uni-bielefeld.de
Faculty of Technology, University of Bielefeld, Germany, Europe, Earth...
| Use any of "finger itschere@129.70.131.2-15" for adresses and more.	|


--- last.c	Wed Dec  7 18:31:22 1994
+++ last2.c	Wed Dec  7 19:00:22 1994
@@ -41,7 +41,11 @@
  *
  *		Fred van Kempen, January 1990
  *		 -Final edit for 1.5
+ *
+ *		Torsten Scherer (TeSche), December 1994
+ *		 - bug fix for MiNTOS 1.4.X
  */
+
 #include <sys/types.h>
 #include <signal.h>
 #include <string.h>
@@ -67,6 +71,10 @@
   struct logout *next;		/* Next in linked list */
 } logout;
 
+/* TeSche: some prototypes */
+int Print_Record(struct utmp *wtmp);
+void Record_Logout_Time(struct utmp *wtmp);
+void Print_Duration(long from, long to);
 
 static char *Version = "@(#) LAST 1.6 (01/09/90)";
 
@@ -151,8 +159,8 @@
  *
  *	   terry     tty0    Thu May 26 21:19   still logged in
  */
-Process(wtmp)
-struct utmp *wtmp;
+
+void Process(struct utmp *wtmp)
 {
   logout *link;
   logout *next_link;
@@ -211,8 +219,8 @@
 /* Print_Record(wtmp) If the record was requested, then print out
  * the user name, terminal, host and time.
  */
-Print_Record(wtmp)
-struct utmp *wtmp;
+
+int Print_Record(struct utmp *wtmp)
 {
   int i;
   char print_flag = FALSE;
@@ -243,9 +251,8 @@
 /* Print_Duration(from, to) Calculate and print the days and hh:mm between
  * the log-in and the log-out.
  */
-Print_Duration(from, to)
-long from;
-long to;
+
+void Print_Duration(long from, long to)
 {
   long delta, days, hours, minutes;
 
@@ -268,8 +275,8 @@
 /* Record_Logout_Time(wtmp) A linked list of "last logout time" is kept.
  * Each element of the list is for one terminal.
  */
-Record_Logout_Time(wtmp)
-struct utmp *wtmp;
+
+void Record_Logout_Time(struct utmp *wtmp)
 {
   logout *link;
 
@@ -293,7 +300,7 @@
 }
 
 
-main(argc, argv)
+void main(argc, argv)
 int argc;
 char *argv[];
 {
@@ -326,11 +333,16 @@
   arg_count = argc;
   args = argv;
 
+#ifdef __MINT__
+  /* TeSche: Grrr... Yet again this bug. :( */
+  if ((f = fopen(wtmp_file, "rb")) == (FILE *) NULL) {
+#else
   if ((f = fopen(wtmp_file, "r")) == (FILE *) NULL) {
+#endif
 	perror(wtmp_file);
 	exit(1);
   }
-  if (fseek(f, 0L, 2) != 0 || (size = ftell(f)) % sizeof(struct utmp) != 0) {
+  if (fseek(f, 0L, SEEK_END) || (size = ftell(f)) % sizeof(struct utmp)) {
 	fprintf(stderr, "last: invalid wtmp file\n");
 	exit(1);
   }
@@ -352,8 +364,7 @@
 	fseek(f, size * sizeof(struct utmp), 0);
 
 
-	if (fread(&wtmp_buffer[0], sizeof(struct utmp), wtmp_count, f)
-	    != wtmp_count) {
+	if (fread(&wtmp_buffer[0], sizeof(struct utmp), wtmp_count, f) != wtmp_count) {
 		fprintf(stderr, "last: read error on wtmp file\n");
 		exit(1);
 	}