[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



On 2016-12-14 15:48, Marga Manterola wrote:
> Package: tzdata
> Version: 2016a-1
> Severity: minor
> 
> The fix for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=803144
> <https://www.google.com/url?q=https://bugs.debian.org/cgi-bin/bugreport.cgi?bug%3D803144&sa=D&usg=AFQjCNFpL_n8tg3iXyS6B09KW1sWkMLIcQ>
> 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.

I think it can be as simple as "ln -sf /usr/share/zoneinfo/$(TIMEZONE)
/etc/localtime", followed by a dpkg-reconfigure tzdata to update
/etc/timezone.

> 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)

This will break setting timezone from systemd and from most desktop
environments which just update /etc/localtime and not /etc/timezone as
the latter is a Debianism. Therefore the timezone is correctly selected,
until the moment where the tzdata maintainer scripts are run again,
which just revert the change.

> 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>

Which wasn't possible before the above change...

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

I am not sure that yet another Debianism tool is going to help in the
long term. One solution could be to stop creating /etc/timezone if it
doesn't exist. That way there is no need to keep /etc/localtime and
/etc/timezone in sync, and changing the timezone would just be a matter
of updating the symlink. What do you think?

Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net


Reply to: