Repository navigation
fix(rotate): date runs like the shell script's date for empty env vars and odd TZ - #18
Conversation
The shell script reads now as ${EB_KEEP_LOGS_NOW:-$(date +%s)}, so an
empty value is the current time, as an unset one is. The Zig build
parsed any value that was set, and refused an empty one with exit 2:
"EB_KEEP_LOGS_NOW must be seconds since the epoch, not ''". It now
takes an empty value as unset too. A value that is neither empty nor an
integer is still refused, as COMPAT.md lists among the deliberate
differences.
The command-line suite rotates runs dated 40 and 20 days back with an
empty EB_KEEP_LOGS_NOW and --compress-after 30, and only the older run
is compressed; tests/differential.sh runs the shell script and the
binary on the same invocation and compares exit code and output. Both
fail on the previous commit. COMPAT.md drops the row from its
unintended differences, the cli reference says what an empty value
means, and the fragment on COMPAT.md lists the two that remain.
glibc looks zone files up under /usr/share/zoneinfo when TZDIR is unset or empty, so the shell script's date finds TZ=Asia/Tokyo there with TZDIR set to the empty string. The Zig build took an empty TZDIR as the directory itself: the zone name became a path relative to the working directory, which holds no such file, and runs were dated in UTC. A run of 20261101 came to be 30 days old nine hours late. localtime.load now takes an empty TZDIR as unset. A unit test loads Asia/Tokyo with TZDIR empty and expects the local midnight `TZDIR= TZ=Asia/Tokyo date -d 20261101 +%s` prints; it is skipped where the zone files are missing. The command-line suite checks that a run is 29 days old a second before date's midnight thirty days on and 30 days old at it, with TZ naming a zone file and with TZDIR empty as well, against the shell script and the binary. Both tests fail on the previous commit. COMPAT.md, the cli reference, the explanation of local time and the comment at the top of src/localtime.zig no longer list the case, and the fragments from the docs work name the one left.
glibc drops a leading ':' from TZ and then reads the rest as it reads a value without one: a zone file if one is there by that name, otherwise a POSIX rule string. The shell script's date therefore dates a run in CET or CEST under TZ=':CET-1CEST,M3.5.0,M10.5.0/3'. The Zig build took a value with a leading ':' for a zone file only, and a name with no file behind it made the zone UTC. localtime.load now reads the rule string after the ':' as well; a TZ of ':' alone is still UTC, as it is in glibc. A unit test loads that rule with the ':' and expects the local midnights date prints for 20260701 and 20261101, in summer and in winter time, and UTC for TZ=':'. The command-line suite runs its local midnight check against date with TZ=':AEST-10AEDT,M10.1.0,M4.1.0/3', in daylight time on the run's date, against the shell script and the binary. Both fail on the previous commit. COMPAT.md now lists no unintended difference, the cli reference and the explanation of local time no longer describe the case, and the comment at the top of src/localtime.zig no longer sets it apart from glibc.
The comment on runAgeDays, and the one on _run_age_days in the shell script, said a run is dated by its name because a later chmod moves its directory's mtime. A chmod changes the ctime and leaves the mtime. What moves the mtime is an entry added, removed or renamed in the directory, as when rotate compresses the run's logs, writing FILE.gz and removing FILE beside it. Both comments now say so. The command-line suite checks what the comments state, against the shell script and the binary: a chmod leaves a run directory's mtime, compressing the logs in it moves the mtime, a run whose mtime is years old but whose name is three days old is not compressed, and a run whose logs were just compressed, with a new mtime, is deleted once its name is past --delete-after. No behaviour changes here, so these checks pass on the previous commit as well; a check of the old comment's claim, that the chmod moves the mtime, fails on either.
glibc reads a TZ rule string as far as it can and ignores the rest, so the shell script's date takes TZ='CET-1CEST,M3.5.0,M10.5.0/3x' as the rule without the x, and TZ='CET-1CEST,M3.5.0' with daylight time ending on the first Sunday in November at 02:00. The Zig build refused both, and anything else it could not read to the end, and dated runs in UTC. It also took the changes of a rule in the year of local standard time, where glibc takes the year in UTC, and in years before 1971, where glibc puts them in 1970. localtime.parsePosix now follows parse_tzname, parse_offset and parse_rule in glibc 2.39's tzset.c: numbers are read as sscanf's %hu reads them, offsets are capped as compute_offset caps them, and a rule that cannot be read keeps what was read of it, with the end rule left unread when the start rule fails. posixOffset works the changes out as compute_change and __tz_compute do. Only a string whose standard time cannot be read is UTC, as in glibc. TZif footers go through the same code. A unit test checks the local midnight of sixteen strings and dates against what date prints with glibc 2.39: text after the rules, no end rule, rules and times cut short, no daylight name, offsets out of range or after white space, a name glibc refuses, J0, years before 1971, and a change near the new year in UTC. The command-line suite runs its local midnight check against date with the first two strings above. Both fail on the previous commit. COMPAT.md lists the differences that are left, in place of "None is known", each with a command that shows it: a rule string without rules where TZDIR holds a posixrules file, which glibc dates from that file's transitions; a rule month outside 1 to 12, which glibc reads out of bounds; zone files with leap seconds, which glibc counts; and three kinds of zone file tzdata has none of, shown by one that zic writes for a zone that starts in daylight time. Its row on run ages, the cli reference and the explanation of local time point to them.
The suite's local midnight checks under TZ took the expected midnight from whatever date was first on PATH. On Ubuntu from 25.10, and so on the ubuntu-latest runners since they moved to 26.04, that is uutils' date 0.10.0, which reads as UTC some rule strings that glibc reads, such as one after a ':' or one without an end rule. The Zig build reads them as glibc does, so three checks failed in the zig job there, while the shell script, which uses the same date as the checks, passed. GNU date 9.7 on that runner's glibc 2.43 gives the midnights the Zig build gives, as GNU date does on glibc 2.39, with and without posixrules. The checks now take the midnight from GNU date, which is gnudate where date is uutils', and run the tool with GNU date as date, so the shell script is checked with the date it needs. Where there is no GNU date they are skipped, each with a line on stderr that says why. zig build test shows a script's stderr and drops its stdout, so the log did not say which checks failed. The suite now prints a failed check's name, expected and actual output on stderr, and the differential run prints a difference there too. Both steps were cached on the binary and their command line alone, and CI restores the Zig cache of earlier runs under a key that names neither the scripts nor the runner image, so a change to the scripts alone, as here, or to the host's date or tzdata could pass them again without running them. Both now run on every zig build test. COMPAT.md lists a date other than GNU's among the deliberate differences: the shell script's run ages follow that date, and the Zig build's are GNU date's whatever date is.
|
The zig job failed on ubuntu-latest because that runner is now 26.04, whose The checks now take the midnight from GNU COMPAT.md lists a The docs build's link-check failure was a connection reset talking to sphinx-doc.org; it only needs a re-run. |
rotatedated runs in UTC, or refused the request, in four cases the shell script'sdatehandles: an emptyEB_KEEP_LOGS_NOW, an emptyTZDIR, aTZwith a leading:that names no zone file, and aTZrule string glibc 2.39's tzset reads only in part.The Zig build takes an empty
EB_KEEP_LOGS_NOWas the current time, and an emptyTZDIRas unset, so the zoneTZnames is looked up under/usr/share/zoneinfo. A leading:is dropped and the rest is read as without one.localtime.parsePosixfollowsparse_tzname,parse_offsetandparse_rulein glibc 2.39's tzset.c, andposixOffsetfollowscompute_changeand__tz_compute: text after the rules is ignored, a missing end rule is the first Sunday in November at 02:00, a rule cut short keeps what was read of it, and only a string whose standard time cannot be read is UTC. The changes of a rule are those of the year in UTC, and of 1970 in years before 1971.The comment on
runAgeDays, and the one on_run_age_daysin the shell script, said a later chmod moves the run directory's mtime. A chmod changes the ctime. What moves the mtime is an entry added, removed or renamed in the directory, as whenrotatecompresses the run's logs. The comments now say so. No behaviour changes in that commit.COMPAT.md lists the differences that remain, each with a command that shows it: a rule string without rules where
TZDIRholds aposixrulesfile, a rule month outside 1 to 12, zone files with leap seconds, and three kinds of zone file tzdata has none of.A unit test checks the local midnight of sixteen rule strings and dates against what
dateprints with glibc 2.39, and the emptyTZDIRand leading:cases the same way. The command-line suite rotates with an emptyEB_KEEP_LOGS_NOW, checks ages at date's midnight withTZDIRempty and withTZa rule after a:, and checks that a chmod leaves the mtime while compressing the logs moves it.tests/differential.shruns the shell script and the binary on the same invocations.