Re: [PATCH]   tzset did not catch changes to localtime  [BZ #21060 ]

J William Piggott elseifthen@gmx.com
Thu Nov 2 23:48:00 GMT 2017



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



More information about the Libc-alpha mailing list