From nobody@FreeBSD.org  Sun Aug  2 21:31:57 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0E05A106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Aug 2009 21:31:57 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id F02728FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Aug 2009 21:31:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n72LVub5024658
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 2 Aug 2009 21:31:56 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n72LVunR024657;
	Sun, 2 Aug 2009 21:31:56 GMT
	(envelope-from nobody)
Message-Id: <200908022131.n72LVunR024657@www.freebsd.org>
Date: Sun, 2 Aug 2009 21:31:56 GMT
From: Jan Schaumann <jschauma@netmeister.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: let last(1) read from stdin via "-f -"
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         137365
>Category:       bin
>Synopsis:       [patch] let last(1) read from stdin via "-f -"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          feedback
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 02 21:40:03 UTC 2009
>Closed-Date:    
>Last-Modified:  Thu May 23 15:21:14 CDT 2013
>Originator:     Jan Schaumann
>Release:        
>Organization:
>Environment:
>Description:
last -f <file>  lets you read from a specified file.  However, there's no way to read from a pipe.  NetBSD's last(1) let's you use "-f -" to specify reading from stdin -- port this to FreeBSD.
>How-To-Repeat:
cat /var/tmp/wtmp | last -f -
>Fix:
Index: last.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/last/last.c,v
retrieving revision 1.34
diff -b -u -r1.34 last.c
--- last.c      8 Aug 2004 18:59:19 -0000       1.34
+++ last.c      2 Aug 2009 21:24:51 -0000
@@ -216,7 +216,10 @@

        LIST_INIT(&ttylist);

-       if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1)
+       if (!strcmp(file, "-")) {
+               wfd = STDIN_FILENO;
+               file = "<stdin>";
+       } else if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1)
                err(1, "%s", file);
        bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);

@@ -226,9 +229,11 @@
        (void)signal(SIGQUIT, onintr);

        while (--bl >= 0) {
-               if (lseek(wfd, (off_t)(bl * sizeof(buf)), L_SET) == -1 ||
-                   (bytes = read(wfd, buf, sizeof(buf))) == -1)
+               if (((lseek(wfd, (off_t)(bl * sizeof(buf)), L_SET) == -1) &&
+                       (ESPIPE != errno)) ||
+                               ((bytes = read(wfd, buf, sizeof(buf))) == -1)) {
                        err(1, "%s", file);
+               }
                for (bp = &buf[bytes / sizeof(buf[0]) - 1]; bp >= buf; --bp)
                        doentry(bp);
        }


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: ghelmer 
State-Changed-When: Thu May 23 15:17:42 CDT 2013 
State-Changed-Why:  
Since last(1) was changed to use utmpx, this patch no longer applies. 
It seems lib/libc/gen/getutxent.c would need to be changed to support 
this functionality. I would suggest either closing this PR and submitting 
a new patch for -current, or attach a new patch for -current to this bug. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=137365 
>Unformatted:
