From 4b94d5ddf0a671e6fc7bbda51c59dcf5f05a3f0dc387fe4eabc238c30bf1c064 Mon Sep 17 00:00:00 2001
From: Jan Engelhardt <jengelh@inai.de>
Date: Tue, 9 May 2023 18:33:25 +0000
Subject: [PATCH 1/2] Accepting request 1085768 from
 home:dgarcia:branches:Base:System

- Call fdupes without -s to avoid broken symlinks, pointing to
  different subpackage. boo#1209990
- Add upstream patch fix-lib-internal-cache-size.patch
  bsc#1210164, gh#util-linux/util-linux@2fa4168c8bc9

OBS-URL: https://build.opensuse.org/request/show/1085768
OBS-URL: https://build.opensuse.org/package/show/Base:System/util-linux?expand=0&rev=510
---
 fix-lib-internal-cache-size.patch | 83 +++++++++++++++++++++++++++++++
 util-linux.changes                | 12 +++++
 util-linux.spec                   |  4 +-
 3 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 fix-lib-internal-cache-size.patch

diff --git a/fix-lib-internal-cache-size.patch b/fix-lib-internal-cache-size.patch
new file mode 100644
index 0000000..a00bafb
--- /dev/null
+++ b/fix-lib-internal-cache-size.patch
@@ -0,0 +1,83 @@
+From 2fa4168c8bc9d5438bc1dfadda293c7c21b6fa59 Mon Sep 17 00:00:00 2001
+From: Michael Trapp <michael.trapp@sap.com>
+Date: Mon, 6 Mar 2023 10:40:20 +0000
+Subject: [PATCH] libuuid: fix lib internal cache size
+
+The lib internal cache improves throughput in high load
+scenarios but for applications with a low request rate,
+the cache size must be adapted to this situation.
+Therefore the cache size should be changed to the current
+requirements of the application during runtime.
+---
+ libuuid/src/gen_uuid.c | 30 ++++++++++++++++++++++--------
+ 1 file changed, 22 insertions(+), 8 deletions(-)
+
+Index: util-linux-2.38.1/libuuid/src/gen_uuid.c
+===================================================================
+--- util-linux-2.38.1.orig/libuuid/src/gen_uuid.c
++++ util-linux-2.38.1/libuuid/src/gen_uuid.c
+@@ -442,25 +442,35 @@ int __uuid_generate_time(uuid_t out, int
+  */
+ static int uuid_generate_time_generic(uuid_t out) {
+ #ifdef HAVE_TLS
++	/* thread local cache for uuidd based requests */
++	const int			cs_min = (1<<6);
++	const int			cs_max = (1<<18);
++	const int			cs_factor = 2;
+ 	THREAD_LOCAL int		num = 0;
+-	THREAD_LOCAL int		cache_size = 1;
++	THREAD_LOCAL int		cache_size = cs_min;
++	THREAD_LOCAL int		last_used = 0;
+ 	THREAD_LOCAL struct uuid	uu;
+ 	THREAD_LOCAL time_t		last_time = 0;
+ 	time_t				now;
+ 
+-	if (num > 0) {
++	if (num > 0) { /* expire cache */
+ 		now = time(NULL);
+-		if (now > last_time+1)
++		if (now > last_time+1) {
++			last_used = cache_size - num;
+ 			num = 0;
++		}
+ 	}
+-	if (num <= 0) {
++	if (num <= 0) { /* fill cache */
+ 		/*
+ 		 * num + OP_BULK provides a local cache in each application.
+ 		 * Start with a small cache size to cover short running applications
+-		 * and increment the cache size over the runntime.
++		 * and adjust the cache size over the runntime.
+ 		 */
+-		if (cache_size < 1000000)
+-			cache_size *= 10;
++		if ((last_used == cache_size) && (cache_size < cs_max))
++			cache_size *= cs_factor;
++		else if ((last_used < (cache_size / cs_factor)) && (cache_size > cs_min))
++			cache_size /= cs_factor;
++
+ 		num = cache_size;
+ 
+ 		if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
+@@ -470,9 +480,11 @@ static int uuid_generate_time_generic(uu
+ 			num--;
+ 			return 0;
+ 		}
++		/* request to daemon failed, reset cache */
+ 		num = 0;
++		cache_size = cs_min;
+ 	}
+-	if (num > 0) {
++	if (num > 0) { /* serve uuid from cache */
+ 		uu.time_low++;
+ 		if (uu.time_low == 0) {
+ 			uu.time_mid++;
+@@ -481,6 +493,8 @@ static int uuid_generate_time_generic(uu
+ 		}
+ 		num--;
+ 		uuid_pack(&uu, out);
++		if (num == 0)
++			last_used = cache_size;
+ 		return 0;
+ 	}
+ #else
diff --git a/util-linux.changes b/util-linux.changes
index 0dcd8f1..272e76c 100644
--- a/util-linux.changes
+++ b/util-linux.changes
@@ -1,3 +1,15 @@
+-------------------------------------------------------------------
+Tue May  9 16:31:55 UTC 2023 - Daniel Garcia <daniel.garcia@suse.com>
+
+- Call fdupes without -s to avoid broken symlinks, pointing to
+  different subpackage. boo#1209990
+
+-------------------------------------------------------------------
+Fri Apr 28 09:42:27 UTC 2023 - Daniel Garcia <daniel.garcia@suse.com>
+
+- Add upstream patch fix-lib-internal-cache-size.patch
+  bsc#1210164, gh#util-linux/util-linux@2fa4168c8bc9
+
 -------------------------------------------------------------------
 Fri Mar 31 13:02:13 UTC 2023 - Michal Koutný <mkoutny@suse.com>
 
diff --git a/util-linux.spec b/util-linux.spec
index 2f11f0b..c6364c0 100644
--- a/util-linux.spec
+++ b/util-linux.spec
@@ -114,6 +114,8 @@ Patch4:         util-linux-bash-completion-su-chsh-l.patch
 Patch5:         util-linux-fix-tests-when-at-symbol-in-path.patch
 # https://github.com/util-linux/util-linux/commit/0c0fb46dcef6c63c74094486e499e376fdb33a04.diff
 Patch6:         util-linux-honor-noclear-when-reprint-issue.patch
+# Patch-FIX_UPSTREAM: fix-lib-internal-cache-size.patch bsc#1210164 -- gh#util-linux/util-linux@2fa4168c8bc9
+Patch7:         fix-lib-internal-cache-size.patch
 BuildRequires:  audit-devel
 BuildRequires:  bc
 BuildRequires:  binutils-devel
@@ -663,7 +665,7 @@ rm -r %{buildroot}{%{_bindir},%{_mandir},%{_datadir},%{_includedir},%{_libdir}/{
 
 # fdupes for all multibuild flavors
 # Link duplicate manpages or python bindings.
-%fdupes -s %{buildroot}%{_prefix}
+%fdupes %{buildroot}%{_prefix}
 
 ##############
 # Base check #

From bbaf74ce95a3cfb83c3f5f856db363212567cc5e6dce6988e4efc4ce467956bf Mon Sep 17 00:00:00 2001
From: Jan Engelhardt <jengelh@inai.de>
Date: Tue, 9 May 2023 20:35:45 +0000
Subject: [PATCH 2/2] Accepting request 1085798 from
 home:ateixeira:branches:Base:System

- Suppress error messages for grep command where the input file
  might not exist (boo#1169835)

OBS-URL: https://build.opensuse.org/request/show/1085798
OBS-URL: https://build.opensuse.org/package/show/Base:System/util-linux?expand=0&rev=511
---
 util-linux.changes | 6 ++++++
 util-linux.spec    | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/util-linux.changes b/util-linux.changes
index 272e76c..51ad497 100644
--- a/util-linux.changes
+++ b/util-linux.changes
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Tue May  9 19:46:41 UTC 2023 - Antonio Teixeira <antonio.teixeira@suse.com>
+
+- Suppress error messages for grep command where the input file 
+  might not exist (boo#1169835)
+
 -------------------------------------------------------------------
 Tue May  9 16:31:55 UTC 2023 - Daniel Garcia <daniel.garcia@suse.com>
 
diff --git a/util-linux.spec b/util-linux.spec
index c6364c0..98fd428 100644
--- a/util-linux.spec
+++ b/util-linux.spec
@@ -754,7 +754,7 @@ done
 # Perform one-time config replace.
 # Applies for: Update from SLE11, online update for SLE15 SP1, Leap15.1.
 # Not needed for /etc/default/runuser. It was first packaged after the change.
-if ! grep -q "^# /etc/default/su is an override" %{_sysconfdir}/default/su ; then
+if ! grep -qs "^# /etc/default/su is an override" %{_sysconfdir}/default/su ; then
 	if test -f %{_sysconfdir}/default/su.rpmnew ; then
 		if ! test -f %{_sysconfdir}/default/su.rpmorig ; then
 			cp -a %{_sysconfdir}/default/su %{_sysconfdir}/default/su.rpmorig