Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1458008 - test builtin ignores subsecond while comparing file modification times
Summary: test builtin ignores subsecond while comparing file modification times
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: bash
Version: 25
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Siteshwar Vashisht
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1458178
TreeView+ depends on / blocked
 
Reported: 2017-06-01 18:21 UTC by Roman Žilka
Modified: 2017-09-24 13:13 UTC (History)
4 users (show)

Fixed In Version: bash-4.4.12-6.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1458178 (view as bug list)
Environment:
Last Closed: 2017-07-07 23:06:56 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Roman Žilka 2017-06-01 18:21:04 UTC
If the mtimes of two files differ by less than 1 second while the component of secs in the same in both timestamps, the command "[ file1 -nt/-ot file2 ]" gives a wrong result. Here '[' is the bash builtin.

Version-Release number of selected component (if applicable):
bash-4.3.43-4.fc25.x86_64
bash-4.2.46-20.el7_2.x86_64 (RHEL 7.3)

Steps to Reproduce:
$ while true; do touch a; sleep 0.6; touch b; stat a b|grep Modify; [ b -nt a ] && echo test_cmd_ok; echo; done

Actual results:

Modify: 2017-06-01 19:31:05.699921567 +0200
Modify: 2017-06-01 19:31:06.303918131 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:06.309918097 +0200
Modify: 2017-06-01 19:31:06.913914657 +0200

Modify: 2017-06-01 19:31:06.918914629 +0200
Modify: 2017-06-01 19:31:07.522911187 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:07.527911159 +0200
Modify: 2017-06-01 19:31:08.132907713 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:08.137907685 +0200
Modify: 2017-06-01 19:31:08.742904235 +0200

Modify: 2017-06-01 19:31:08.748904201 +0200
Modify: 2017-06-01 19:31:09.351900765 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:09.357900731 +0200
Modify: 2017-06-01 19:31:09.961897294 +0200

Modify: 2017-06-01 19:31:09.967897260 +0200
Modify: 2017-06-01 19:31:10.570893817 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:10.576893783 +0200
Modify: 2017-06-01 19:31:11.180890345 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:11.186890311 +0200
Modify: 2017-06-01 19:31:11.789886880 +0200

Modify: 2017-06-01 19:31:11.795886846 +0200
Modify: 2017-06-01 19:31:12.399883404 +0200
test_cmd_ok


Expected results:

Modify: 2017-06-01 19:31:05.699921567 +0200
Modify: 2017-06-01 19:31:06.303918131 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:06.309918097 +0200
Modify: 2017-06-01 19:31:06.913914657 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:06.918914629 +0200
Modify: 2017-06-01 19:31:07.522911187 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:07.527911159 +0200
Modify: 2017-06-01 19:31:08.132907713 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:08.137907685 +0200
Modify: 2017-06-01 19:31:08.742904235 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:08.748904201 +0200
Modify: 2017-06-01 19:31:09.351900765 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:09.357900731 +0200
Modify: 2017-06-01 19:31:09.961897294 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:09.967897260 +0200
Modify: 2017-06-01 19:31:10.570893817 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:10.576893783 +0200
Modify: 2017-06-01 19:31:11.180890345 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:11.186890311 +0200
Modify: 2017-06-01 19:31:11.789886880 +0200
test_cmd_ok

Modify: 2017-06-01 19:31:11.795886846 +0200
Modify: 2017-06-01 19:31:12.399883404 +0200
test_cmd_ok


Additional info:
Note that the '[' command from coreutils works as expected.

A quick recursive grep of the filesystem reveals a certain number of instances of "[ -nt/-ot" in files belonging to some common packages like elfutils, git, grub as well as sendmail and postfix (at least in RHEL). I came accross this bug while debugging weird behavior of /etc/mail/make (part of sendmail, called e.g. from its systemd unit file) which wouldn't refresh the main config file sometimes if called in fast repetition.

As far as RHEL is concerned, this issue might be of interest to the developers of packages that call "[ -nt/-ot". I'm at least adding CC: sendmail/posftix's Jaroslav Skarvada.

Comment 1 Kamil Dudka 2017-06-02 06:57:37 UTC
Thank you for reporting the bug!

This seems to be caused by the get_stat_mtime_ns() function returning 0 because of STAT_TIMESPEC and STAT_TIMESPEC_NS not being defined.

The autoconf tests check for sub-second precision for atime only, so we end up with HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC not being defined.  But it doe not mean that we cannot obtain mtime with sub-second precision.  In fact, strace shows that bash gets precise enough data but, if I stop gdb in timespec_cmp(), the tv_nsec fields are always zero.

Note that this bug is specific to bash.  ksh, zsh, and coreutils seem compare mtime with sub-second precision.

Comment 4 Fedora Update System 2017-06-30 16:08:29 UTC
bash-4.4.12-6.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-2b6507886b

Comment 5 Fedora Update System 2017-07-01 20:54:20 UTC
bash-4.4.12-6.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-2b6507886b

Comment 6 Fedora Update System 2017-07-07 23:06:56 UTC
bash-4.4.12-6.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.