0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b Mon Sep 17 00:00:00 2001
  2. From: Eddie James <eajames@linux.ibm.com>
  3. Date: Mon, 10 Aug 2020 09:59:02 -0500
  4. Subject: [PATCH] hwclock: Fix settimeofday for glibc v2.31+
  5. The glibc implementation changed for settimeofday, resulting in "invalid
  6. argument" error when attempting to set both timezone and time with a single
  7. call. Fix this by calling settimeofday twice
  8. Signed-off-by: Eddie James <eajames@linux.ibm.com>
  9. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
  10. ---
  11. util-linux/hwclock.c | 14 +++++++++++---
  12. 1 file changed, 11 insertions(+), 3 deletions(-)
  13. diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
  14. index dc97d8fb4..2479e7416 100644
  15. --- a/util-linux/hwclock.c
  16. +++ b/util-linux/hwclock.c
  17. @@ -122,16 +122,20 @@ static void to_sys_clock(const char **pp_rtcname, int utc)
  18. struct timeval tv;
  19. struct timezone tz;
  20. - tz.tz_minuteswest = timezone/60;
  21. + tz.tz_minuteswest = timezone / 60;
  22. /* ^^^ used to also subtract 60*daylight, but it's wrong:
  23. * daylight!=0 means "this timezone has some DST
  24. * during the year", not "DST is in effect now".
  25. */
  26. tz.tz_dsttime = 0;
  27. + /* glibc v2.31+ returns an error if both args are non-NULL */
  28. + if (settimeofday(NULL, &tz))
  29. + bb_simple_perror_msg_and_die("settimeofday");
  30. +
  31. tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
  32. tv.tv_usec = 0;
  33. - if (settimeofday(&tv, &tz))
  34. + if (settimeofday(&tv, NULL))
  35. bb_simple_perror_msg_and_die("settimeofday");
  36. }
  37. @@ -283,7 +287,11 @@ static void set_system_clock_timezone(int utc)
  38. gettimeofday(&tv, NULL);
  39. if (!utc)
  40. tv.tv_sec += tz.tz_minuteswest * 60;
  41. - if (settimeofday(&tv, &tz))
  42. +
  43. + /* glibc v2.31+ returns an error if both args are non-NULL */
  44. + if (settimeofday(NULL, &tz))
  45. + bb_simple_perror_msg_and_die("settimeofday");
  46. + if (settimeofday(&tv, NULL))
  47. bb_simple_perror_msg_and_die("settimeofday");
  48. }
  49. --
  50. 2.17.1