From owner-freebsd-bugs@FreeBSD.ORG Mon May 17 10:30:18 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6F72116A4CE for ; Mon, 17 May 2004 10:30:18 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9515243D1F for ; Mon, 17 May 2004 10:30:17 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i4HHUHEd095139 for ; Mon, 17 May 2004 10:30:17 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i4HHUHXL095138; Mon, 17 May 2004 10:30:17 -0700 (PDT) (envelope-from gnats) Resent-Date: Mon, 17 May 2004 10:30:17 -0700 (PDT) Resent-Message-Id: <200405171730.i4HHUHXL095138@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dan Nelson Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7628316A4CE for ; Mon, 17 May 2004 10:25:45 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2EB3143D1D for ; Mon, 17 May 2004 10:25:44 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i4HHPgJN002107; Mon, 17 May 2004 12:25:42 -0500 (CDT) (envelope-from dan) Message-Id: <200405171725.i4HHPgJN002107@dan.emsphone.com> Date: Mon, 17 May 2004 12:25:42 -0500 (CDT) From: Dan Nelson To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/66765: "lastcomm string" is broken on -current X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2004 17:30:18 -0000 >Number: 66765 >Category: bin >Synopsis: "lastcomm string" is broken on -current >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon May 17 10:30:17 PDT 2004 >Closed-Date: >Last-Modified: >Originator: Dan Nelson >Release: FreeBSD 5.2-CURRENT i386 >Organization: >Environment: System: FreeBSD dan.emsphone.com 5.2-CURRENT FreeBSD 5.2-CURRENT #329: Wed May 12 01:05:37 CDT 2004 dan@dan.emsphone.com:/usr/src/sys/i386/compile/DANSMP i386 >Description: The lastcomm code has an ugly hack where lseek and fread are mixed in an attempt to access file offsets past 4gb. Unfortunately, the last attempt to fix it ended up breaking the case where a match string is passed on the argument. >How-To-Repeat: Run "lastcomm zzz" and notice you either get no results or an error. >Fix: Remove all the lseek code and use good old fseeko. Simplifies the loop a lot. Index: lastcomm.c =================================================================== RCS file: /home/ncvs/src/usr.bin/lastcomm/lastcomm.c,v retrieving revision 1.18 diff -u -p -r1.18 lastcomm.c --- lastcomm.c 27 Jan 2003 18:16:32 -0000 1.18 +++ lastcomm.c 14 Apr 2004 03:18:39 -0000 @@ -134,7 +134,7 @@ main(int argc, char *argv[]) /* Open the file. */ if ((fp = fopen(acctfile, "r")) == NULL || fstat(fileno(fp), &sb)) - err(1, "%s", acctfile); + err(1, "could not open %s", acctfile); /* * Round off to integral number of accounting records, probably @@ -146,17 +146,13 @@ main(int argc, char *argv[]) if ((unsigned)size < sizeof(struct acct)) exit(0); - /* - * Seek to before the last entry in the file; use lseek(2) in case - * the file is bigger than a "long". - */ - size -= sizeof(struct acct); - if (lseek(fileno(fp), size, SEEK_SET) == -1) - err(1, "%s", acctfile); - - for (;;) { - if (fread(&ab, sizeof(struct acct), 1, fp) != 1) - err(1, "%s", acctfile); + do { + int rv; + size -= sizeof(struct acct); + if (fseeko(fp, size, SEEK_SET) == -1) + err(1, "seek %s failed", acctfile); + if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1) + err(1, "read %s returned %d", acctfile, rv); if (ab.ac_comm[0] == '\0') { ab.ac_comm[0] = '?'; @@ -211,12 +207,7 @@ main(int argc, char *argv[]) } printf("\n"); - if (size == 0) - break; - size -= sizeof(struct acct); - if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1) - err(1, "%s", acctfile); - } + } while (size > 0); exit(0); } >Release-Note: >Audit-Trail: >Unformatted: