Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Aug 1999 18:07:01 +0900 (JST)
From:      kjm@rins.ryukoku.ac.jp (KOJIMA Hajime)
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/12982: last command -y option support patch
Message-ID:  <199908050907.SAA08563@ideon.st.ryukoku.ac.jp>

next in thread | raw e-mail | index | archive | help

>Number:         12982
>Category:       bin
>Synopsis:       last does not support -y option.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug  5 02:10:00 PDT 1999
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908050907.SAA08563>