misc/137365: let last(1) read from stdin via "-f -"
Jan Schaumann
jschauma at netmeister.org
Sun Aug 2 21:40:04 UTC 2009
>Number: 137365
>Category: misc
>Synopsis: let last(1) read from stdin via "-f -"
>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: Sun Aug 02 21:40:03 UTC 2009
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
More information about the freebsd-bugs
mailing list