This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] tzset did not catch changes to localtime [BZ #21060 ]
- From: J William Piggott <elseifthen at gmx dot com>
- To: ma dot jiang at zte dot com dot cn, libc-alpha at sourceware dot org
- Date: Thu, 2 Nov 2017 19:47:44 -0400
- Subject: Re: [PATCH] tzset did not catch changes to localtime [BZ #21060 ]
- Authentication-results: sourceware.org; auth=none
- References: <201711021703324026436@zte.com.cn>
On 11/02/2017 05:03 AM, ma.jiang@zte.com.cn wrote:
> Hi,
> If users modified the local timezone file (usually /etc/localtime)
> while keep the TZ environment variable untouched, tzset will not
> recalculate tzname. This is not right.
Yes it is. The TZ env overrides the system timezone. If TZ exists then
tzset should ignore any system wide setting whether something modifies
it or not. Users should not have permission to modify anything in /etc/
anyway.
> Patch attached should fix this
> problem, is it OK for trunk?
>
>
> diff -Nuarp a/time/tzset.c b/time/tzset.c
> --- a/time/tzset.c 2017-10-31 17:28:58.105026060 +0800
> +++ b/time/tzset.c 2017-10-31 17:28:43.470025216 +0800
> @@ -387,21 +387,18 @@ tzset_internal (int always)
> if (tz && *tz == ':')
> ++tz;
>
> - /* Check whether the value changed since the last run. */
> - if (old_tz != NULL && tz != NULL && strcmp (tz, old_tz) == 0)
> - /* No change, simply return. */
> - return;
> -
> if (tz == NULL)
> /* No user specification; use the site-wide default. */
> tz = TZDEFAULT;
>
> - tz_rules[0].name = NULL;
> - tz_rules[1].name = NULL;
> -
> - /* Save the value of `tz'. */
> - free (old_tz);
> - old_tz = tz ? __strdup (tz) : NULL;
> + /* Check whether the value changed since the last run. */
> + if ((old_tz == NULL)
> + || (old_tz != NULL && strcmp (tz, old_tz) != 0))
> + {
> + /* Save the value of `tz'. */
> + free (old_tz);
> + old_tz = tz ? __strdup (tz) : NULL;
> + }
>
> /* Try to read a data file. */
> __tzfile_read (tz, 0, NULL);
>