tzname[1] empty after tzset() with env TZ="UTC"

Bug #2030684 reported by Nick Rosbrook
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
django-mailman3 (Ubuntu)
Fix Released
Undecided
Unassigned
php8.2 (Ubuntu)
Triaged
Undecided
Unassigned
php8.3 (Ubuntu)
Triaged
Undecided
Unassigned
postgresql-15 (Ubuntu)
Fix Released
Undecided
Unassigned
python-django (Ubuntu)
Fix Released
Undecided
Unassigned
systemd (Ubuntu)
Invalid
Undecided
Unassigned
tzdata (Debian)
Fix Released
Unknown
tzdata (Ubuntu)
Fix Released
Critical
Unassigned

Bug Description

The following program prints different output when run with tzdata 2023c-7ubuntu1 from mantic, versus tzdata 2023c-8ubuntu1 from mantic-proposed:

root@mantic:~# cat bug.c
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void) {
        int r;

        r = setenv("TZ", ":UTC", 1);
        if (r < 0) {
                printf("Failed to set TZ env var: %s\n", strerror(errno));
                return 1;
        }

        tzset();

        printf("timezone = %lu, daylight = %d\n", timezone, daylight);
        printf("tzname[0] = %s, tzname[1] = %s\n", tzname[0], tzname[1]);
}

root@mantic:~# gcc bug.c
root@mantic:~# ./a.out
timezone = 0, daylight = 0
tzname[0] = UTC, tzname[1] = UTC
root@mantic:~# apt-cache policy tzdata
tzdata:
  Installed: 2023c-7ubuntu1
  Candidate: 2023c-7ubuntu1
  Version table:
 *** 2023c-7ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu mantic/main amd64 Packages
        100 /var/lib/dpkg/status

If I install tzdata from mantic-proposed, I get different output:

root@mantic:~# vi /etc/apt/sources.list
root@mantic:~# apt update && apt install tzdata
Hit:1 http://archive.ubuntu.com/ubuntu mantic InRelease
Hit:2 http://security.ubuntu.com/ubuntu mantic-security InRelease
Get:3 http://archive.ubuntu.com/ubuntu mantic-proposed InRelease [118 kB]
Hit:4 http://archive.ubuntu.com/ubuntu mantic-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu mantic-backports InRelease
Get:6 http://archive.ubuntu.com/ubuntu mantic-proposed/main amd64 Packages [35.9 kB]
Get:7 http://archive.ubuntu.com/ubuntu mantic-proposed/main Translation-en [14.8 kB]
Get:8 http://archive.ubuntu.com/ubuntu mantic-proposed/main amd64 DEP-11 Metadata [2376 B]
Get:9 http://archive.ubuntu.com/ubuntu mantic-proposed/main amd64 c-n-f Metadata [1004 B]
Get:10 http://archive.ubuntu.com/ubuntu mantic-proposed/restricted amd64 Packages [15.9 kB]
Get:11 http://archive.ubuntu.com/ubuntu mantic-proposed/restricted Translation-en [3564 B]
Get:12 http://archive.ubuntu.com/ubuntu mantic-proposed/restricted amd64 c-n-f Metadata [336 B]
Fetched 192 kB in 1s (324 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
72 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@mantic:~# apt install tzdata=2023c-8ubuntu1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libefiboot1 libefivar1
Use 'apt autoremove' to remove them.
The following packages will be upgraded:
  tzdata
1 upgraded, 0 newly installed, 0 to remove and 72 not upgraded.
Need to get 269 kB of archives.
After this operation, 142 kB disk space will be freed.
Get:1 http://archive.ubuntu.com/ubuntu mantic-proposed/main amd64 tzdata all 2023c-8ubuntu1 [269 kB]
Fetched 269 kB in 0s (867 kB/s)
Preconfiguring packages ...
(Reading database ... 39935 files and directories currently installed.)
Preparing to unpack .../tzdata_2023c-8ubuntu1_all.deb ...
Unpacking tzdata (2023c-8ubuntu1) over (2023c-7ubuntu1) ...
Setting up tzdata (2023c-8ubuntu1) ...

Current default time zone: 'Etc/UTC'
Local time is now: Mon Aug 7 21:18:35 UTC 2023.
Universal Time is now: Mon Aug 7 21:18:35 UTC 2023.
Run 'dpkg-reconfigure tzdata' if you wish to change it.

Scanning processes...
Scanning candidates...

Restarting services...
Service restarts being deferred:
 systemctl restart systemd-logind.service
 systemctl restart unattended-upgrades.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

root@mantic:~# ./a.out
timezone = 0, daylight = 0
tzname[0] = UTC, tzname[1] =
root@mantic:~# apt-cache policy tzdata-legacy
tzdata-legacy:
  Installed: (none)
  Candidate: 2023c-7ubuntu1
  Version table:
     2023c-8ubuntu1 100
        100 http://archive.ubuntu.com/ubuntu mantic-proposed/main amd64 Packages
     2023c-7ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu mantic/main amd64 Packages

In particular, note that tzname[1] (the name of the daylight zone) is empty, whereas it previously printed "UTC".

Revision history for this message
Nick Rosbrook (enr0n) wrote :

The program works again whenever tzdata-legacy is installed, but is this the intended behavior? This causes some tests to fail in systemd at build time, so systemd is currently FTBFS with mantic-proposed.

tags: added: update-excuse
Revision history for this message
Benjamin Drung (bdrung) wrote :

This behaviour is a side effect of moving the /usr/share/zoneinfo/UTC to tzdata-legacy. We could move this file back to quickly unbreak the autopkgtest.

The better solution is to set TZ=UTC0 instead of TZ=UTC because UTC0 is defined to be available on all systems even with an empty /usr/share/zoneinfo.

I verified that the output of bug.c is correct with tzdata 2023c-8ubuntu1 and without tzdata-legacy when changing to TZ=UTC0.

See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1043250

Revision history for this message
Benjamin Drung (bdrung) wrote :
Revision history for this message
Nick Rosbrook (enr0n) wrote :

Thanks, Benjamin. Moving UTC back is helpful, but we have the same issue with other timezones, e.g. CET.

If there is a wider motivation or justification for this change, then I could look at making the necessary changes upstream. But right now, unless we revert the tzdata change entirely, the apparent solution would be for systemd to Depends: tzdata-legacy. This effectively defeats the purpose of having the -legacy package, though, right?

Benjamin Drung (bdrung)
Changed in tzdata (Ubuntu):
status: New → Triaged
importance: Undecided → Critical
Revision history for this message
Benjamin Drung (bdrung) wrote :

From the 2023c-7 upload:

  * Ship only timezones in tzdata that follow the current rules of geographical
    region (continent or ocean) and city name. Move all legacy timezone symlinks
    (that are upgraded during package update) to tzdata-legacy. This includes
    dropping the special handling for US/* timezones. (Closes: #1040997)

The symlinks that were moved to tzdata-legacy come from the upstream backward file. The backward says:

# This file provides links from old or merged timezone names to current ones.
# Many names changed in 1993 and in 1995, and many merged names moved here
# in the period from 2013 through 2022. Several of these names are
# also present in the file 'backzone', which has data important only
# for pre-1970 timestamps and so is out of scope for tzdb proper.

Which of these legacy timezone names are needed for systemd except for UTC?

Revision history for this message
Nick Rosbrook (enr0n) wrote :

Taking a glance at the test cases, I see at least CET, EET, and IST. However, it's not clear to me looking at the upstream backward file why these timezones (among others) were moved to -legacy. I see UTC listed in that file, but not CET etc.

Benjamin Drung (bdrung)
Changed in tzdata (Ubuntu):
status: Triaged → Fix Committed
Revision history for this message
Benjamin Drung (bdrung) wrote :

postgresql-15 still fails, because the sysviews test uses Pacific/Enderbury.

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

A postgresql-15 upload isbeing prepared by the debian maintainer which will add tzdata-legacy as a dependency for the DEP8 tests. This should be enough to fix this one for now.

https://salsa.debian.org/postgresql/postgresql/-/commit/d3cdc3decf7d30fca79ebdcfbaffb9d504be0466

Revision history for this message
Luca Boccassi (bluca) wrote :

Note that for systemd it's just the unit tests that need the legacy files, so in Debian I've just added a build-dep on tzdata-legacy | tzdata (same for autopkgtest). No change in runtime dependencies.

Changed in postgresql-15 (Ubuntu):
status: New → Fix Committed
Changed in php8.2 (Ubuntu):
status: New → Triaged
Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

PHP carries a patch (in debian) to allow the interpreter to use the symtem's tzdata. This issue triggered a (until now) concealed issue which leads to a null pointer deref.

While the latest tzdata upload fixes the issue in PHP, it should be nice to re-visit that PHP patch to ensure that it either falls back to the php internal tz data db or to make php fail gracefully when there are inconsistencies between the hardcoded assumptions (e.g., setting a default to UTC when no data is found) and the actual tzdata in the system (e.g., the UTC value set as default is not available in the system).

I am adding this bug to the server team backlog so we can re-visit the patch when time allows. Once the other components are fixed, we should remove the update-excuse tag from this bug.

Nick Rosbrook (enr0n)
Changed in systemd (Ubuntu):
status: New → Invalid
Changed in tzdata (Debian):
status: Unknown → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package tzdata - 2023c-9ubuntu1

---------------
tzdata (2023c-9ubuntu1) mantic; urgency=medium

  * Merge with Debian unstable. Remaining changes:
    - Ship 2023c ICU timezone data which are utilized by PHP in tzdata-icu
    - Add autopkgtest test case for ICU timezone data
    - Do not rename NEWS into changelog.gz, this fixes a build failure on
      moment-timezone.js
    - Point Vcs-Browser/Git to Launchpad
    - generate_debconf_templates: Work around AttributeError on icu import

tzdata (2023c-9) unstable; urgency=medium

  * Partially revert 2023c-8: Move top-level timezones like UTC and CET back to
    tzdata. Only the old or merged timezones mentioned in the upstream backward
    file stay in tzdata-legacy (Closes: #1043250, LP: #2030684)

 -- Benjamin Drung <email address hidden> Wed, 09 Aug 2023 22:16:36 +0200

Changed in tzdata (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

This bug is no more an issue marking fixed

Changed in python-django (Ubuntu):
status: New → Fix Released
Changed in django-mailman3 (Ubuntu):
status: New → Fix Released
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote (last edit ):

According to comment #10 from Athos, the php8.2 task has been added to this bug only to serve as a reminder for a future investigation when time permits. Since everything else affected by the bug has been marked as Fix Released, I removed the update-excuses tag.

tags: removed: update-excuse
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

postgresql-15 has been Fix Released a while ago. Marking the task accordingly.

Changed in postgresql-15 (Ubuntu):
status: Fix Committed → Fix Released
Changed in php8.3 (Ubuntu):
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.