From owner-freebsd-bugs Tue Jun 11 12: 0:32 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id E169537B40F for ; Tue, 11 Jun 2002 12:00:08 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g5BJ08S94422; Tue, 11 Jun 2002 12:00:08 -0700 (PDT) (envelope-from gnats) Received: from exgw2.lumeta.com (exgw2.lumeta.com [65.198.68.66]) by hub.freebsd.org (Postfix) with ESMTP id 0042337B40F for ; Tue, 11 Jun 2002 11:53:53 -0700 (PDT) Received: from lucy.corp.lumeta.com (h65-198-68-133.lumeta.com [65.198.68.133]) by exgw2.lumeta.com (Postfix) with ESMTP id 682D8373834 for ; Tue, 11 Jun 2002 14:53:53 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by lucy.corp.lumeta.com (Postfix) with ESMTP id F03601084A for ; Tue, 11 Jun 2002 14:53:52 -0400 (EDT) Received: from lumeta.com (hburch.corp.lumeta.com [65.198.68.240]) by lucy.corp.lumeta.com (Postfix) with ESMTP id 6704A10849 for ; Tue, 11 Jun 2002 14:53:49 -0400 (EDT) Received: by lumeta.com (Postfix, from userid 1000) id A46459340B; Tue, 11 Jun 2002 14:53:55 -0400 (EDT) Message-Id: <20020611185355.A46459340B@lumeta.com> Date: Tue, 11 Jun 2002 14:53:55 -0400 (EDT) From: Hal Burch Reply-To: Hal Burch To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/39163: -nt/-ot in test(1) does not detect if tv_nsec are different Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 39163 >Category: bin >Synopsis: -nt/-ot in test(1) does not detect if tv_nsec are different >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: Tue Jun 11 12:00:08 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Hal Burch >Release: FreeBSD 5.0-CURRENT i386 >Organization: Lumeta Corporation >Environment: System: FreeBSD hburch-lap.corp.lumeta.com 5.0-CURRENT FreeBSD 5.0-CURRENT #5: Tue May 7 18:46:05 EDT 2002 hburch@hburch-lap.corp.lumeta.com:/usr/src/sys/i386/compile/LOCAL i386 (Testing on 4.3-RELEASE, 4.5-RELEASE, 4.1.1-RELEASE all had the same behavior) >Description: Because newerf only checks st_mtime, if the files have the same value for st_mtimespec.tv_sec but not for st_mtimespec.tv_nsec, test will improperly say that the files have the same modification time. This may be required for POSIX conformance, but that seems unlikely. >How-To-Repeat: $ touch a ; echo pass time; touch b Expect: pass time Received: pass time $ test b -nt a && echo NEWER Expect: NEWER Received: [blank] (if the second does not increment, which is ~99.7% of the time on my system) >Fix: Add code to newerf to check both st_mtimespec.tv_sec and st_mtimespec.tv_nsec. The old way was using the st_mtime hook, so switched it to st_mtimespec.tv_sec for consistency. Change olderf to just a call to newerf with the parameters reversed to reduce code duplication. Diff from current head (src/bin/test/test.c 1.47) diff -c /usr/src/bin/test/test.c ./test.c *** /usr/src/bin/test/test.c Mon Jun 10 21:43:24 2002 --- ./test.c Mon Jun 10 21:56:13 2002 *************** *** 520,540 **** static int newerf (const char *f1, const char *f2) { ! struct stat b1, b2; ! ! return (stat (f1, &b1) == 0 && ! stat (f2, &b2) == 0 && ! b1.st_mtime > b2.st_mtime); } static int olderf (const char *f1, const char *f2) { ! struct stat b1, b2; ! ! return (stat (f1, &b1) == 0 && ! stat (f2, &b2) == 0 && ! b1.st_mtime < b2.st_mtime); } static int --- 520,540 ---- static int newerf (const char *f1, const char *f2) { ! if (stat(f1, &b1) != 0) return 0; ! if (stat(f2, &b2) != 0) return 0; ! ! if (b1.st_mtimespec.tv_sec > b2.st_mtimespec.tv_sec) ! return 1; ! if (b1.st_mtimespec.tv_sec < b2.st_mtimespec.tv_sec) ! return 0; ! ! return (b1.st_mtimespec.tv_nsec > b2.st_mtimespec.tv_nsec); } static int olderf (const char *f1, const char *f2) { ! return newerf(f2, f1); } static int >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message