Subject: bin/1548: last should display seconds
To: None <gnats-bugs@gnats.netbsd.org>
From: John Hawkinson <jhawk@mit.edu>
List: netbsd-bugs
Date: 09/30/1995 02:51:42
>Number:         1548
>Category:       bin
>Synopsis:       last should display seconds
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 30 03:05:03 1995
>Last-Modified:
>Originator:     John Hawkinson
>Organization:
MIT SIPB
>Release:        27 Aug
>Environment:
System: NetBSD lola-granola 1.0A NetBSD 1.0A (LOLA) #102: Sun Sep 3 09:48:20 EDT 1995 jhawk@zygorthian-space-raiders:/afs/sipb.mit.edu/project/netbsd/dev/current-source/build/i386_nbsd1/sys/arch/i386/compile/LOLA i386


>Description:
  Even though it has the information available to it, last does not
  display seconds. It even fits conveniently in 80 columns, so this
  must be for historical reasons.

  The below patch adds a -T option (reminicnent of ls(1)) to display
  seconds as well as hours and minutes.
>How-To-Repeat:
	N/A
>Fix:


*** last.1	1995/09/30 06:43:35	1.1
--- last.1	1995/09/30 06:44:59
***************
*** 83,88 ****
--- 83,90 ----
  .It Fl h Ar host
  .Ar Host
  names may be names or internet numbers.
+ .It Fl T
+ Display better time information, including seconds.
  .El
  .Pp
  If
*** last.c	1995/08/12 20:27:54	1.1
--- last.c	1995/09/30 06:43:13
***************
*** 86,91 ****
--- 86,92 ----
  static time_t	currentout;			/* current logout value */
  static long	maxrec;				/* records to display */
  static char	*file = _PATH_WTMP;		/* wtmp file */
+ static int      fulltime = 0;			/* Display seconds? */
  
  void	 addarg __P((int, char *));
  TTY	*addtty __P((char *));
***************
*** 106,112 ****
  	char *p;
  
  	maxrec = -1;
! 	while ((ch = getopt(argc, argv, "0123456789f:h:t:")) != EOF)
  		switch (ch) {
  		case '0': case '1': case '2': case '3': case '4':
  		case '5': case '6': case '7': case '8': case '9':
--- 107,113 ----
  	char *p;
  
  	maxrec = -1;
! 	while ((ch = getopt(argc, argv, "0123456789f:h:t:T")) != EOF)
  		switch (ch) {
  		case '0': case '1': case '2': case '3': case '4':
  		case '5': case '6': case '7': case '8': case '9':
***************
*** 134,143 ****
  		case 't':
  			addarg(TTY_TYPE, ttyconv(optarg));
  			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 	"usage: last [-#] [-f file] [-t tty] [-h hostname] [user ...]\n");
  			exit(1);
  		}
  
--- 135,147 ----
  		case 't':
  			addarg(TTY_TYPE, ttyconv(optarg));
  			break;
+ 		case 'T':
+ 			fulltime=-1;
+ 			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 	"usage: last [-#] [-f file] [-t tty] [-h hostname] [-T] [user ...]\n");
  			exit(1);
  		}
  
***************
*** 167,172 ****
--- 171,177 ----
  	TTY	*T;				/* tty list entry */
  	struct stat	stb;			/* stat of file for size */
  	time_t	bl, delta;			/* time difference */
+ 	int     timesize;			/* how much of time string to print */
  	int	bytes, wfd;
  	char	*ct, *crmsg;
  
***************
*** 174,179 ****
--- 179,190 ----
  		err(1, "%s", file);
  	bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);
  
+ 	if (fulltime)
+ 	        timesize = 8;  /* HH:MM:SS */
+ 	else
+ 	        timesize = 5;  /* HH:MM */
+ 
+ 
  	(void)time(&buf[0].ut_time);
  	(void)signal(SIGINT, onintr);
  	(void)signal(SIGQUIT, onintr);
***************
*** 196,207 ****
  				    UT_NAMESIZE) ? "crash" : "shutdown";
  				if (want(bp, NO)) {
  					ct = ctime(&bp->ut_time);
! 				printf("%-*.*s  %-*.*s %-*.*s %10.10s %5.5s \n",
  					    UT_NAMESIZE, UT_NAMESIZE,
  					    bp->ut_name, UT_LINESIZE,
  					    UT_LINESIZE, bp->ut_line,
  					    UT_HOSTSIZE, UT_HOSTSIZE,
! 					    bp->ut_host, ct, ct + 11);
  					if (maxrec != -1 && !--maxrec)
  						return;
  				}
--- 207,219 ----
  				    UT_NAMESIZE) ? "crash" : "shutdown";
  				if (want(bp, NO)) {
  					ct = ctime(&bp->ut_time);
! 				printf("%-*.*s  %-*.*s %-*.*s %10.10s %*.*s \n",
  					    UT_NAMESIZE, UT_NAMESIZE,
  					    bp->ut_name, UT_LINESIZE,
  					    UT_LINESIZE, bp->ut_line,
  					    UT_HOSTSIZE, UT_HOSTSIZE,
! 					    bp->ut_host, ct, timesize,
! 				            timesize, ct + 11);
  					if (maxrec != -1 && !--maxrec)
  						return;
  				}
***************
*** 215,225 ****
  			    && !bp->ut_line[1]) {
  				if (want(bp, NO)) {
  					ct = ctime(&bp->ut_time);
! 				printf("%-*.*s  %-*.*s %-*.*s %10.10s %5.5s \n",
  				    UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
  				    UT_LINESIZE, UT_LINESIZE, bp->ut_line,
  				    UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host,
! 				    ct, ct + 11);
  					if (maxrec && !--maxrec)
  						return;
  				}
--- 227,237 ----
  			    && !bp->ut_line[1]) {
  				if (want(bp, NO)) {
  					ct = ctime(&bp->ut_time);
! 				printf("%-*.*s  %-*.*s %-*.*s %10.10s %*.*s \n",
  				    UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
  				    UT_LINESIZE, UT_LINESIZE, bp->ut_line,
  				    UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host,
! 				    ct, timesize, timesize, ct + 11);
  					if (maxrec && !--maxrec)
  						return;
  				}
***************
*** 237,247 ****
  			}
  			if (bp->ut_name[0] && want(bp, YES)) {
  				ct = ctime(&bp->ut_time);
! 				printf("%-*.*s  %-*.*s %-*.*s %10.10s %5.5s ",
  				UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
  				UT_LINESIZE, UT_LINESIZE, bp->ut_line,
  				UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host,
! 				ct, ct + 11);
  				if (!T->logout)
  					puts("  still logged in");
  				else {
--- 249,259 ----
  			}
  			if (bp->ut_name[0] && want(bp, YES)) {
  				ct = ctime(&bp->ut_time);
! 				printf("%-*.*s  %-*.*s %-*.*s %10.10s %*.*s ",
  				UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
  				UT_LINESIZE, UT_LINESIZE, bp->ut_line,
  				UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host,
! 				ct, timesize, timesize, ct + 11);
  				if (!T->logout)
  					puts("  still logged in");
  				else {
***************
*** 250,264 ****
  						printf("- %s", crmsg);
  					}
  					else
! 						printf("- %5.5s",
  						    ctime(&T->logout)+11);
  					delta = T->logout - bp->ut_time;
  					if (delta < SECSPERDAY)
! 						printf("  (%5.5s)\n",
  						    asctime(gmtime(&delta))+11);
  					else
! 						printf(" (%ld+%5.5s)\n",
  						    delta / SECSPERDAY,
  						    asctime(gmtime(&delta))+11);
  				}
  				if (maxrec != -1 && !--maxrec)
--- 262,279 ----
  						printf("- %s", crmsg);
  					}
  					else
! 						printf("- %*.*s",
! 						    timesize, timesize,
  						    ctime(&T->logout)+11);
  					delta = T->logout - bp->ut_time;
  					if (delta < SECSPERDAY)
! 						printf("  (%*.*s)\n",
! 						    timesize, timesize,
  						    asctime(gmtime(&delta))+11);
  					else
! 						printf(" (%ld+%*.*s)\n",
  						    delta / SECSPERDAY,
+ 						    timesize, timesize,
  						    asctime(gmtime(&delta))+11);
  				}
  				if (maxrec != -1 && !--maxrec)
***************
*** 268,274 ****
  		}
  	}
  	ct = ctime(&buf[0].ut_time);
! 	printf("\nwtmp begins %10.10s %5.5s \n", ct, ct + 11);
  }
  
  /*
--- 283,289 ----
  		}
  	}
  	ct = ctime(&buf[0].ut_time);
! 	printf("\nwtmp begins %10.10s %*.*s \n", ct, timesize, timesize, ct + 11);
  }
  
  /*
***************
*** 418,424 ****
  	char *ct;
  
  	ct = ctime(&buf[0].ut_time);
! 	printf("\ninterrupted %10.10s %5.5s \n", ct, ct + 11);
  	if (signo == SIGINT)
  		exit(1);
  	(void)fflush(stdout);			/* fix required for rsh */
--- 433,439 ----
  	char *ct;
  
  	ct = ctime(&buf[0].ut_time);
! 	printf("\ninterrupted %10.10s %8.8s \n", ct, ct + 11);
  	if (signo == SIGINT)
  		exit(1);
  	(void)fflush(stdout);			/* fix required for rsh */
>Audit-Trail:
>Unformatted: