From 49d6fe435f496cb3e02ed868f2a1f3599915d734 Mon Sep 17 00:00:00 2001 From: "yunqi.zwt" Date: Mon, 23 Aug 2021 16:48:48 +0800 Subject: [PATCH] [Patch] hwclock: better compatibility for both glibc2.28 and glibc2.32 Signed-off-by: yunqi.zwt Signed-off-by: weitao zhou --- 1001-hwclock-make-glibc-2.31-compatible.patch | 162 ++++++++++++++++++ util-linux.spec | 11 +- 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 1001-hwclock-make-glibc-2.31-compatible.patch diff --git a/1001-hwclock-make-glibc-2.31-compatible.patch b/1001-hwclock-make-glibc-2.31-compatible.patch new file mode 100644 index 0000000..81a48e3 --- /dev/null +++ b/1001-hwclock-make-glibc-2.31-compatible.patch @@ -0,0 +1,162 @@ +From cd781c405be82540484da3bfe3d3f17a39b8eb5c Mon Sep 17 00:00:00 2001 +From: J William Piggott +Date: Fri, 21 Feb 2020 20:03:47 -0500 +Subject: [PATCH] hwclock: make glibc 2.31 compatible + +______________________________________________________ +GNU C Library NEWS -- history of user-visible changes. +Version 2.31 +Deprecated and removed features, and other changes affecting compatibility: + +* The settimeofday function can still be used to set a system-wide time + zone when the operating system supports it. This is because the Linux + kernel reused the API, on some architectures, to describe a system-wide + time-zone-like offset between the software clock maintained by the kernel, + and the "RTC" clock that keeps time when the system is shut down. + + However, to reduce the odds of this offset being set by accident, + settimeofday can no longer be used to set the time and the offset + simultaneously. If both of its two arguments are non-null, the call + will fail (setting errno to EINVAL). + + Callers attempting to set this offset should also be prepared for the call + to fail and set errno to ENOSYS; this already happens on the Hurd and on + some Linux architectures. The Linux kernel maintainers are discussing a + more principled replacement for the reused API. After a replacement + becomes available, we will change settimeofday to fail with ENOSYS on all + platforms when its 'tzp' argument is not a null pointer. + + settimeofday itself is obsolescent according to POSIX. Programs that set + the system time should use clock_settime and/or the adjtime family of + functions instead. We may cease to make settimeofday available to newly + linked binaries after there is a replacement for Linux's time-zone-like + offset API. +______________________________________________________ + +hwclock(8) had one settimeofday(2) call where both args were set for +--hctosys when the RTC was ticking UTC. This allowed setting the system +time, timezone, and locking the warp_clock function with a single call. +That operation now takes 3 calls of settimeofday(2). + +Although this common operation now takes three calls, the overall logic +for the set_system_clock() function was simplified. + +Co-Author: Karel Zak +Signed-off-by: J William Piggott +--- + sys-utils/hwclock.c | 71 +++++++++++++++++++++++---------------------- + 1 file changed, 37 insertions(+), 34 deletions(-) + +diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c +index e736da7179..1191a85715 100644 +--- a/sys-utils/hwclock.c ++++ b/sys-utils/hwclock.c +@@ -643,28 +643,28 @@ display_time(struct timeval hwctime) + * tz.tz_minuteswest argument and sets PCIL (see below). At boot settimeofday(2) + * has one-shot access to this function as shown in the table below. + * +- * +-------------------------------------------------------------------+ +- * | settimeofday(tv, tz) | +- * |-------------------------------------------------------------------| +- * | Arguments | System Time | PCIL | | warp_clock | +- * | tv | tz | set | warped | set | firsttime | locked | +- * |---------|---------|---------------|------|-----------|------------| +- * | pointer | NULL | yes | no | no | 1 | no | +- * | pointer | pointer | yes | no | no | 0 | yes | +- * | NULL | ptr2utc | no | no | no | 0 | yes | +- * | NULL | pointer | no | yes | yes | 0 | yes | +- * +-------------------------------------------------------------------+ ++ * +-------------------------------------------------------------------------+ ++ * | settimeofday(tv, tz) | ++ * |-------------------------------------------------------------------------| ++ * | Arguments | System Time | TZ | PCIL | | warp_clock | ++ * | tv | tz | set | warped | set | set | firsttime | locked | ++ * |---------|---------|---------------|-----|------|-----------|------------| ++ * | pointer | NULL | yes | no | no | no | 1 | no | ++ * | NULL | ptr2utc | no | no | yes | no | 0 | yes | ++ * | NULL | pointer | no | yes | yes | yes | 0 | yes | ++ * +-------------------------------------------------------------------------+ + * ptr2utc: tz.tz_minuteswest is zero (UTC). + * PCIL: persistent_clock_is_local, sets the "11 minute mode" timescale. + * firsttime: locks the warp_clock function (initialized to 1 at boot). ++ * Since glibc v2.31 settimeofday() will fail if both args are non NULL + * + * +---------------------------------------------------------------------------+ + * | op | RTC scale | settimeofday calls | + * |---------|-----------|-----------------------------------------------------| + * | systz | Local | 1) warps system time*, sets PCIL* and kernel tz | + * | systz | UTC | 1st) locks warp_clock* 2nd) sets kernel tz | +- * | hctosys | Local | 1st) sets PCIL* 2nd) sets system time and kernel tz | +- * | hctosys | UTC | 1) sets system time and kernel tz | ++ * | hctosys | Local | 1st) sets PCIL* & kernel tz 2nd) sets system time | ++ * | hctosys | UTC | 1st) locks warp* 2nd) sets tz 3rd) sets system time | + * +---------------------------------------------------------------------------+ + * * only on first call after boot + */ +@@ -675,42 +675,45 @@ set_system_clock(const struct hwclock_control *ctl, + struct tm broken; + int minuteswest; + int rc = 0; +- const struct timezone tz_utc = { 0 }; + + localtime_r(&newtime.tv_sec, &broken); + minuteswest = -get_gmtoff(&broken) / 60; + + if (ctl->verbose) { +- if (ctl->hctosys && !ctl->universal) +- printf(_("Calling settimeofday(NULL, %d) to set " +- "persistent_clock_is_local.\n"), minuteswest); +- if (ctl->systz && ctl->universal) ++ if (ctl->universal) { + puts(_("Calling settimeofday(NULL, 0) " +- "to lock the warp function.")); ++ "to lock the warp_clock function.")); ++ if (!( ctl->universal && !minuteswest )) ++ printf(_("Calling settimeofday(NULL, %d) " ++ "to set the kernel timezone.\n"), ++ minuteswest); ++ } else ++ printf(_("Calling settimeofday(NULL, %d) to warp " ++ "System time, set PCIL and the kernel tz.\n"), ++ minuteswest); ++ + if (ctl->hctosys) +- printf(_("Calling settimeofday(%ld.%06ld, %d)\n"), +- newtime.tv_sec, newtime.tv_usec, minuteswest); +- else { +- printf(_("Calling settimeofday(NULL, %d) "), minuteswest); +- if (ctl->universal) +- puts(_("to set the kernel timezone.")); +- else +- puts(_("to warp System time.")); +- } ++ printf(_("Calling settimeofday(%ld.%06ld, NULL) " ++ "to set the System time.\n"), ++ newtime.tv_sec, newtime.tv_usec); + } + + if (!ctl->testing) { ++ const struct timezone tz_utc = { 0 }; + const struct timezone tz = { minuteswest }; + +- if (ctl->hctosys && !ctl->universal) /* set PCIL */ +- rc = settimeofday(NULL, &tz); +- if (ctl->systz && ctl->universal) /* lock warp_clock */ ++ /* If UTC RTC: lock warp_clock and PCIL */ ++ if (ctl->universal) + rc = settimeofday(NULL, &tz_utc); +- if (!rc && ctl->hctosys) +- rc = settimeofday(&newtime, &tz); +- else if (!rc) ++ ++ /* Set kernel tz; if localtime RTC: warp_clock and set PCIL */ ++ if (!rc && !( ctl->universal && !minuteswest )) + rc = settimeofday(NULL, &tz); + ++ /* Set the System Clock */ ++ if ((!rc || errno == ENOSYS) && ctl->hctosys) ++ rc = settimeofday(&newtime, NULL); ++ + if (rc) { + warn(_("settimeofday() failed")); + return EXIT_FAILURE; diff --git a/util-linux.spec b/util-linux.spec index bbf8f05..ffab874 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -1,8 +1,9 @@ +%define anolis_release .0.1 ### Header Summary: A collection of basic system utilities Name: util-linux Version: 2.32.1 -Release: 27%{?dist} +Release: 27%{anolis_release}%{?dist} License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://en.wikipedia.org/wiki/Util-linux @@ -205,6 +206,11 @@ Patch55: 0055-lscpu-arm-read-vendor-and-model-from-BIOS.patch # 1900498 - libfdisk/libmount: backport two patches for upstream systemd Patch56: 0056-tests-update-sfdisk-resize.patch +# Begin: Anolis customized patches +# hwclock: make glibc 2.31 compatible +Patch1001: 1001-hwclock-make-glibc-2.31-compatible.patch +# End: Anolis customized patches + %description The util-linux package contains a large variety of low-level system @@ -1070,6 +1076,9 @@ fi %{_libdir}/python*/site-packages/libmount/ %changelog +* Wed Dec 01 2021 Weitao Zhou 2.32.1-27.0.1 +- [Patch] hwclock: better compatibility for both glibc2.28 and glibc2.31 + * Tue Jan 19 2021 Karel Zak 2.32.1-27 - update lscpu-show-physical-socket-on-aarch64-without-ACPI-P.patch (#1882740) -- Gitee