[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#848143: No non-systemd way of programmatically changing the timezone without re-doing what tzdata does



Package: tzdata
Version: 2016a-1
Severity: minor

The fix for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=803144 means that it's no longer possible to change the timezone without user interaction unless one does what tzdata is already doing.

In the past, it was possible to replace the contents of /etc/timezone, run dpkg-reconfigure tzdata and have the system update it's timezone without any user interaction.  This is particularly handy when combined with DHCP servers that serve the timezone information.

However, since the move to the symlink instead of a file, this is no longer possible.  This is caused by this snippet in tzdata's config file:

https://sources.debian.net/src/tzdata/2016j-2/debian/tzdata.config/#L332
# If /etc/localtime is a link, update /etc/timezone
if [ -L /etc/localtime ] ; then
    TIMEZONE="$(readlink /etc/localtime)"
    TIMEZONE="${TIMEZONE#/usr/share/zoneinfo/}"
    if [ -f "/usr/share/zoneinfo/$TIMEZONE" ] ; then
        echo ${TIMEZONE} > /etc/timezone
    fi
fi

# Read /etc/timezone
if [ -e /etc/timezone ]; then
    TIMEZONE="$(head -n 1 /etc/timezone)"
    TIMEZONE="${TIMEZONE%% *}"
    TIMEZONE="${TIMEZONE##/}"
    TIMEZONE="${TIMEZONE%%/}"
    TIMEZONE="$(convert_timezone $TIMEZONE)"
    if [ -f "/usr/share/zoneinfo/$TIMEZONE" ] ; then
        AREA="${TIMEZONE%%/*}"
        ZONE="${TIMEZONE#*/}"
    else
        rm -f /etc/timezone
    fi
fi

Which means that the symlink takes precedence over the file.  In the end, in order to make a programmatical change, I would need to re do what tzdata does regarding translating the string into a symlink (fixing the timezone along the way), which means unnecessary code duplication.

Some possibilities to change this:
A) Remove the symlink reading code from the config (or only use it if the /etc/timezone file is missing)
B) Provide a separate tool that takes a string and does what tzdata maint scripts do (convert the timezone, split it, update the symlink, etc).

For systemd systems, it's possible to do:
timedatectl set-timezone <timezone>

However, for non systemd systems, this is now impossible.

Thanks!
--
Cheers,
Marga

Reply to: