Date: Tue, 11 Jun 2002 14:53:55 -0400 (EDT) From: Hal Burch <hburch@lumeta.com> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/39163: -nt/-ot in test(1) does not detect if tv_nsec are different Message-ID: <20020611185355.A46459340B@lumeta.com>
next in thread | raw e-mail | index | archive | help
>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020611185355.A46459340B>
