From kjm@ideon.st.ryukoku.ac.jp Thu Aug  5 02:08:00 1999
Return-Path: <kjm@ideon.st.ryukoku.ac.jp>
Received: from rins.st.ryukoku.ac.jp (rins.st.ryukoku.ac.jp [133.83.4.1])
	by hub.freebsd.org (Postfix) with ESMTP id 69F9314E33
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  5 Aug 1999 02:07:51 -0700 (PDT)
	(envelope-from kjm@ideon.st.ryukoku.ac.jp)
Received: from ideon.st.ryukoku.ac.jp (ideon.st.ryukoku.ac.jp [133.83.36.5])
	by rins.st.ryukoku.ac.jp (8.9.3+3.2W/3.7W/RINS-1.9.6-NOSPAM) with ESMTP id SAA03882
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 5 Aug 1999 18:07:02 +0900 (JST)
Received: (from kjm@localhost)
	by ideon.st.ryukoku.ac.jp (8.9.3/3.7W/kjm-19990628) id SAA08563;
	Thu, 5 Aug 1999 18:07:01 +0900 (JST)
Message-Id: <199908050907.SAA08563@ideon.st.ryukoku.ac.jp>
Date: Thu, 5 Aug 1999 18:07:01 +0900 (JST)
From: kjm@rins.ryukoku.ac.jp (KOJIMA Hajime)
Sender: kjm@ideon.st.ryukoku.ac.jp
Reply-To: kjm@rins.ryukoku.ac.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: last command -y option support patch
X-Send-Pr-Version: 3.2

>Number:         12982
>Category:       bin
>Synopsis:       last does not support -y option.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    keramida
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug  5 02:10:00 PDT 1999
>Closed-Date:    Fri Mar 1 13:12:32 PST 2002
>Last-Modified:  Fri Mar 01 13:13:18 PST 2002
>Originator:     KOJIMA Hajime
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
Ryukoku University
>Environment:

	CPU: Celeron 466MHz
	Memory: 128MB

>Description:

	FreeBSD's last command does not support -y option.
	GNU version of last command (in acct package) support -y option, 
	and its useful.  

>How-To-Repeat:

	% last -y
	last: illegal option -- y
	usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [user ...]

>Fix:
	
	Apply this patch.

--- last.1.dist	Thu Aug  5 17:37:58 1999
+++ last.1	Thu Aug  5 17:41:08 1999
@@ -45,6 +45,7 @@
 .Op Fl s
 .Op Fl t Ar tty
 .Op Fl w
+.Op Fl y
 .Op user ...
 .Sh DESCRIPTION
 .Nm Last
@@ -89,6 +90,8 @@
 .It Fl w
 Widen the duration field to show seconds, as well as the
 default days, hours and minutes.
+.It Fl y
+Report the duration of the login session with year.
 .El
 .Pp
 If
--- last.c.dist	Thu Aug  5 17:18:37 1999
+++ last.c	Thu Aug  5 18:04:12 1999
@@ -85,6 +85,8 @@
 static char	*file = _PATH_WTMP;		/* wtmp file */
 static int	sflag = 0;			/* show delta in seconds */
 static int	width = 5;			/* show seconds in delta */
+static int	showyear = NO;			/* show year */
+#define	YEAR_SIZE	4			/* Y10K BUG HERE: to fix, change 4 to 5 */
 
 void	 addarg __P((int, char *));
 void	 hostconv __P((char *));
@@ -97,7 +99,7 @@
 usage(void)
 {
 	(void)fprintf(stderr,
-	"usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [user ...]\n");
+	"usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [-y] [user ...]\n");
 	exit(1);
 }
 
@@ -114,7 +116,7 @@
 	(void) setlocale(LC_TIME, "");
 
 	maxrec = -1;
-	while ((ch = getopt(argc, argv, "0123456789f:h:st:w")) != -1)
+	while ((ch = getopt(argc, argv, "0123456789f:h:st:wy")) != -1)
 		switch (ch) {
 		case '0': case '1': case '2': case '3': case '4':
 		case '5': case '6': case '7': case '8': case '9':
@@ -148,6 +150,9 @@
 		case 'w':
 			width = 8;
 			break;
+		case 'y':
+			showyear = YES;
+			break;
 		case '?':
 		default:
 			usage();
@@ -240,11 +245,21 @@
 				if (want(bp)) {
 					tm = localtime(&bp->ut_time);
 					(void) strftime(ct, sizeof(ct), "%c", tm);
-					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 (showyear) {
+					    printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s %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, 
+						YEAR_SIZE, YEAR_SIZE, ct + 20, 
+						ct + 11);
+					} else {
+					    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;
 				}
@@ -278,11 +293,21 @@
 						bp->ut_line[4] = '\0';
 					tm = localtime(&bp->ut_time);
 					(void) strftime(ct, sizeof(ct), "%c", tm);
-					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 (showyear) {
+					    printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s %5.5s ",
+						UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
+						UT_LINESIZE, UT_LINESIZE, bp->ut_line,
+						UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host,
+						ct, 
+						YEAR_SIZE, YEAR_SIZE, ct + 20, 
+						ct + 11);
+					} else {
+					    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 (!tt->logout)
 						puts("  still logged in");
 					else {

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: iedowse 
State-Changed-When: Fri Nov 16 14:23:08 PST 2001 
State-Changed-Why:  

Hi, this looks useful, especially with old or long-running wtmp 
files that span multiple years. I think the patch needs some 
updating, and it could be simplified to always append a string 
that is normally empty instead of duplicating all the printfs. 

Anyone feel like updating and cleaning this up? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=12982 
Responsible-Changed-From-To: freebsd-bugs->keramida 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Sat Nov 17 08:32:37 PST 2001 
Responsible-Changed-Why:  
I'll take care of this.  If submitter responds to my mail, 
we'll work together on it.  Otherwise I'll see what I can do 
about it by myself. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=12982 
State-Changed-From-To: feedback->closed 
State-Changed-By: iedowse 
State-Changed-When: Fri Mar 1 13:12:32 PST 2002 
State-Changed-Why:  

Committed to -CURRENT; will be merged into -STABLE in approx 1 week. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=12982 
>Unformatted:
