SV: [PATCH] hwclock: separate invocations settimeofday time&zone

Lukasz Serafin Lukasz.Serafin at axis.com
Mon Jul 20 17:12:46 UTC 2020


"So this will just silently stop to work if someone upgrades glibc?"

Yes, unfortunately that is how it is.

"Whats the downside by just always doing it the 'new way' "

Good question. We have the "#if" because of a comment by Markus Gothe:

http://lists.busybox.net/pipermail/busybox/2020-July/088083.html

BR
Lukasz


________________________________________
Från: Norbert Lange <nolange79 at gmail.com>
Skickat: den 14 juli 2020 14:28
Till: Lukasz Serafin
Kopia: busybox at busybox.net; Fredrik M Olsson
Ämne: Re: [PATCH] hwclock: separate invocations settimeofday time&zone

Am Di., 14. Juli 2020 um 14:09 Uhr schrieb Lukasz Serafin
<Lukasz.Serafin at axis.com>:
>
> Refactor usage of settimeofday to be compatible with glibc v2.31.
>
> Signed-off-by: Fredrik M Olsson <fredriol at axis.com>
> ---
>  util-linux/hwclock.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
> index 29f5102..d3884f6 100644
> --- a/util-linux/hwclock.c
> +++ b/util-linux/hwclock.c
> @@ -117,6 +117,20 @@ static void show_clock(const char **pp_rtcname, int utc)
>  #endif
>  }
>
> +static void set_time_and_zone(const struct timeval *tv, const struct timezone *tz)
> +{
> +#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 31
> +    if (settimeofday(NULL, tz))
> +        bb_perror_msg_and_die("settimeofday tz");
> +
> +    if (settimeofday(tv, NULL))
> +        bb_perror_msg_and_die("settimeofday tv");
> +#else
> +    if (settimeofday(tv, tz))
> +        bb_perror_msg_and_die("settimeofday");
> +#endif
> +}
> +

So this will just silently stop to work if someone upgrades glibc?
Whats the downside by just always doing it the "new way"
(until that wont work either, see https://lwn.net/Articles/811275/)



>  static void to_sys_clock(const char **pp_rtcname, int utc)
>  {
>      struct timeval tv;
> @@ -131,8 +145,7 @@ static void to_sys_clock(const char **pp_rtcname, int utc)
>
>      tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
>      tv.tv_usec = 0;
> -    if (settimeofday(&tv, &tz))
> -        bb_perror_msg_and_die("settimeofday");
> +    set_time_and_zone(&tv, &tz);
>  }
>
>  static void from_sys_clock(const char **pp_rtcname, int utc)
> @@ -283,8 +296,7 @@ static void set_system_clock_timezone(int utc)
>      gettimeofday(&tv, NULL);
>      if (!utc)
>          tv.tv_sec += tz.tz_minuteswest * 60;
> -    if (settimeofday(&tv, &tz))
> -        bb_perror_msg_and_die("settimeofday");
> +    set_time_and_zone(&tv, &tz);
>  }
>
>  //usage:#define hwclock_trivial_usage
> --
> 2.11.0
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox

Norbert


More information about the busybox mailing list