[PATCH] hwclock: separate invocations settimeofday time&zone

Norbert Lange nolange79 at gmail.com
Tue Jul 14 12:28:27 UTC 2020


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