From e2907bebf333ec063aca4597ff7fac2bc3be5cad Mon Sep 17 00:00:00 2001 From: Sohum Mendon Date: Sat, 13 Jul 2024 14:02:20 -0700 Subject: [PATCH 1/3] Fix fold exit status for nonexistent files --- coreutils-i18n.patch | 2 +- coreutils.spec | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/coreutils-i18n.patch b/coreutils-i18n.patch index be8e0b1..f3c42bd 100644 --- a/coreutils-i18n.patch +++ b/coreutils-i18n.patch @@ -1752,7 +1752,7 @@ index 5c0428d..2372047 100644 + if (istream == NULL) + { + error (0, errno, "%s", filename); -+ return 1; ++ return false; + } + + /* Define how ISTREAM is being folded. */ diff --git a/coreutils.spec b/coreutils.spec index f1d68b3..bf36f48 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,7 +1,7 @@ Summary: A set of basic GNU tools commonly used in shell scripts Name: coreutils Version: 9.4 -Release: 6%{?dist} +Release: 7%{?dist} # some used parts of gnulib are under various variants of LGPL License: GPL-3.0-or-later AND GFDL-1.3-no-invariants-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later Url: https://www.gnu.org/software/coreutils/ @@ -262,6 +262,9 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir %license COPYING %changelog +* Sat Jul 13 2024 Sohum Mendon - 9.4-7 +- fix incorrect exit status when fold is called with a non-existent file + * Mon Jan 29 2024 Lukáš Zaoral - 9.4-6 - fix tail on kernels with 64k page sizes (RHEL-22866) From 8bde780ab442ac8416a3d57d0bc11c0b6a935417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Fri, 27 Sep 2024 13:23:26 +0200 Subject: [PATCH 2/3] fix fold -b with UTF8 locale Resolves: RHEL-60295 --- coreutils-i18n.patch | 73 ++++++++++++++++++++++---------------------- coreutils.spec | 5 ++- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/coreutils-i18n.patch b/coreutils-i18n.patch index f3c42bd..08484a8 100644 --- a/coreutils-i18n.patch +++ b/coreutils-i18n.patch @@ -1,4 +1,4 @@ -From 3a1b92e80708319bcc89852e3da1029c3d1ff6b3 Mon Sep 17 00:00:00 2001 +From d682c6155ffb4cd1f764b1268b68419630958265 Mon Sep 17 00:00:00 2001 From: rpm-build Date: Wed, 30 Aug 2023 17:19:58 +0200 Subject: [PATCH] coreutils-i18n.patch @@ -14,7 +14,7 @@ Subject: [PATCH] coreutils-i18n.patch src/expand-common.c | 114 ++++++ src/expand-common.h | 12 + src/expand.c | 90 +++- - src/fold.c | 312 ++++++++++++-- + src/fold.c | 311 ++++++++++++-- src/join.c | 359 ++++++++++++++-- src/local.mk | 4 +- src/pr.c | 443 ++++++++++++++++++-- @@ -35,7 +35,7 @@ Subject: [PATCH] coreutils-i18n.patch tests/sort/sort.pl | 40 +- tests/unexpand/mb.sh | 172 ++++++++ tests/uniq/uniq.pl | 55 +++ - 31 files changed, 3732 insertions(+), 242 deletions(-) + 31 files changed, 3731 insertions(+), 242 deletions(-) create mode 100644 lib/mbfile.c create mode 100644 lib/mbfile.h create mode 100644 m4/mbfile.m4 @@ -1390,7 +1390,7 @@ index 0e74d0c..7080c51 100644 } diff --git a/src/fold.c b/src/fold.c -index 5c0428d..2372047 100644 +index 5c0428d..4f55c8d 100644 --- a/src/fold.c +++ b/src/fold.c @@ -22,10 +22,32 @@ @@ -1538,7 +1538,7 @@ index 5c0428d..2372047 100644 /* Look for the last blank. */ while (logical_end) { -@@ -213,13 +250,225 @@ fold_file (char const *filename, size_t width) +@@ -213,13 +250,224 @@ fold_file (char const *filename, size_t width) line_out[offset_out++] = c; } @@ -1636,39 +1636,38 @@ index 5c0428d..2372047 100644 + } + +rescan: -+ if (operating_mode == byte_mode) /* byte mode */ ++ if (convfail) ++ increment = 1; ++ else if (wc == L'\n') ++ { ++ /* preserve newline */ ++ fwrite (line_out, sizeof(char), offset_out, stdout); ++ START_NEW_LINE; ++ continue; ++ } ++ else if (operating_mode == byte_mode) /* byte mode */ + increment = mblength; + else if (operating_mode == character_mode) /* character mode */ + increment = 1; -+ else /* column mode */ ++ else /* column mode */ + { -+ if (convfail) -+ increment = 1; -+ else ++ switch (wc) + { -+ switch (wc) -+ { -+ case L'\n': -+ fwrite (line_out, sizeof(char), offset_out, stdout); -+ START_NEW_LINE; -+ continue; ++ case L'\b': ++ increment = (column > 0) ? -1 : 0; ++ break; + -+ case L'\b': -+ increment = (column > 0) ? -1 : 0; -+ break; ++ case L'\r': ++ increment = -1 * column; ++ break; + -+ case L'\r': -+ increment = -1 * column; -+ break; ++ case L'\t': ++ increment = 8 - column % 8; ++ break; + -+ case L'\t': -+ increment = 8 - column % 8; -+ break; -+ -+ default: -+ increment = wcwidth (wc); -+ increment = (increment < 0) ? 0 : increment; -+ } ++ default: ++ increment = wcwidth (wc); ++ increment = (increment < 0) ? 0 : increment; + } + } + @@ -1766,7 +1765,7 @@ index 5c0428d..2372047 100644 if (STREQ (filename, "-")) clearerr (istream); else if (fclose (istream) != 0 && !saved_errno) -@@ -250,7 +499,8 @@ main (int argc, char **argv) +@@ -250,7 +498,8 @@ main (int argc, char **argv) atexit (close_stdout); @@ -1776,7 +1775,7 @@ index 5c0428d..2372047 100644 while ((optc = getopt_long (argc, argv, shortopts, longopts, nullptr)) != -1) { -@@ -259,7 +509,15 @@ main (int argc, char **argv) +@@ -259,7 +508,15 @@ main (int argc, char **argv) switch (optc) { case 'b': /* Count bytes rather than columns. */ @@ -4758,10 +4757,10 @@ index 0000000..26c95de + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk -index b74a4a2..fe6e557 100644 +index 99e73ca..5c91acf 100644 --- a/tests/local.mk +++ b/tests/local.mk -@@ -384,6 +384,8 @@ all_tests = \ +@@ -385,6 +385,8 @@ all_tests = \ tests/sort/sort-discrim.sh \ tests/sort/sort-files0-from.pl \ tests/sort/sort-float.sh \ @@ -4770,7 +4769,7 @@ index b74a4a2..fe6e557 100644 tests/sort/sort-h-thousands-sep.sh \ tests/sort/sort-merge.pl \ tests/sort/sort-merge-fdlimit.sh \ -@@ -585,6 +587,7 @@ all_tests = \ +@@ -586,6 +588,7 @@ all_tests = \ tests/du/threshold.sh \ tests/du/trailing-slash.sh \ tests/du/two-args.sh \ @@ -4778,7 +4777,7 @@ index b74a4a2..fe6e557 100644 tests/id/gnu-zero-uids.sh \ tests/id/no-context.sh \ tests/id/context.sh \ -@@ -738,6 +741,7 @@ all_tests = \ +@@ -739,6 +742,7 @@ all_tests = \ tests/touch/read-only.sh \ tests/touch/relative.sh \ tests/touch/trailing-slash.sh \ @@ -5556,5 +5555,5 @@ index a6354dc..e43cd6e 100755 @Tests = triple_test \@Tests; -- -2.43.0 +2.46.2 diff --git a/coreutils.spec b/coreutils.spec index bf36f48..d9e2633 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,7 +1,7 @@ Summary: A set of basic GNU tools commonly used in shell scripts Name: coreutils Version: 9.4 -Release: 7%{?dist} +Release: 8%{?dist} # some used parts of gnulib are under various variants of LGPL License: GPL-3.0-or-later AND GFDL-1.3-no-invariants-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later Url: https://www.gnu.org/software/coreutils/ @@ -262,6 +262,9 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir %license COPYING %changelog +* Fri Sep 27 2024 Lukáš Zaoral - 9.4-8 +- fix fold -b with UTF8 locale (RHEL-60295) + * Sat Jul 13 2024 Sohum Mendon - 9.4-7 - fix incorrect exit status when fold is called with a non-existent file From c6c6bbd1df023728d2f225dc615550785fe20fd6 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 13 Nov 2024 09:19:32 +0100 Subject: [PATCH 3/3] Affinity mask handling in nproc for large CPU counts (rhbz#2325167) --- coreutils-nproc-affinity-1.patch | 55 +++++++++++++++++++++++++++ coreutils-nproc-affinity-2.patch | 64 ++++++++++++++++++++++++++++++++ coreutils.spec | 9 ++++- 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 coreutils-nproc-affinity-1.patch create mode 100644 coreutils-nproc-affinity-2.patch diff --git a/coreutils-nproc-affinity-1.patch b/coreutils-nproc-affinity-1.patch new file mode 100644 index 0000000..8748d4e --- /dev/null +++ b/coreutils-nproc-affinity-1.patch @@ -0,0 +1,55 @@ +commit 45c2456a56337ebcafe0dd9faa2bd995ccbc3357 +Author: Florian Weimer +Date: Mon Nov 11 14:05:53 2024 +0100 + + nproc: Use affinity mask even on systems with more than 1024 CPUs. + + * lib/nproc.c (num_processors_via_affinity_mask): Retry + with larger affinity masks if CPU_ALLOC_SIZE is available. + +diff --git a/lib/nproc.c b/lib/nproc.c +index 92a07e8289..48bc3d06fa 100644 +--- a/lib/nproc.c ++++ b/lib/nproc.c +@@ -20,6 +20,7 @@ + #include + #include "nproc.h" + ++#include + #include + #include + #include +@@ -124,6 +125,33 @@ num_processors_via_affinity_mask (void) + return count; + } + } ++#elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC \ ++ && defined CPU_ALLOC_SIZE /* glibc >= 2.6 */ ++ { ++ unsigned int alloc_count = 1024; ++ while (1) ++ { ++ cpu_set_t *set = CPU_ALLOC (alloc_count); ++ if (set == NULL) ++ return 0; ++ unsigned int size = CPU_ALLOC_SIZE (alloc_count); ++ if (sched_getaffinity (0, size, set) == 0) ++ { ++ unsigned int count = CPU_COUNT_S (size, set); ++ CPU_FREE (set); ++ return count; ++ } ++ if (errno != EINVAL) ++ { ++ CPU_FREE (set); ++ return 0; ++ } ++ CPU_FREE (set); ++ alloc_count *= 2; ++ if (alloc_count == 0) ++ return 0; ++ } ++ } + #elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC /* glibc >= 2.3.4 */ + { + cpu_set_t set; diff --git a/coreutils-nproc-affinity-2.patch b/coreutils-nproc-affinity-2.patch new file mode 100644 index 0000000..aeca09c --- /dev/null +++ b/coreutils-nproc-affinity-2.patch @@ -0,0 +1,64 @@ +commit ee0bc695303775da5026091a65e8ec2b764f4a26 +Author: Bruno Haible +Date: Mon Nov 11 15:40:52 2024 +0100 + + nproc: Use affinity mask even in out-of-memory situations. + + * lib/nproc.c (num_processors_via_affinity_mask): Use a stack-allocated + cpu_set_t as fallback. Add comments. + +diff --git a/lib/nproc.c b/lib/nproc.c +index 48bc3d06fa..0b5898d88f 100644 +--- a/lib/nproc.c ++++ b/lib/nproc.c +@@ -125,15 +125,25 @@ num_processors_via_affinity_mask (void) + return count; + } + } +-#elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC \ +- && defined CPU_ALLOC_SIZE /* glibc >= 2.6 */ ++#elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC /* glibc >= 2.3.4 */ ++ /* There are two ways to use the sched_getaffinity() function: ++ - With a statically-sized cpu_set_t. ++ - With a dynamically-sized cpu_set_t. ++ Documentation: ++ ++ ++ The second way has the advantage that it works on systems with more than ++ 1024 CPUs. The first way has the advantage that it works also when memory ++ is tight. */ ++# if defined CPU_ALLOC_SIZE /* glibc >= 2.6 */ + { + unsigned int alloc_count = 1024; +- while (1) ++ for (;;) + { + cpu_set_t *set = CPU_ALLOC (alloc_count); + if (set == NULL) +- return 0; ++ /* Out of memory. */ ++ break; + unsigned int size = CPU_ALLOC_SIZE (alloc_count); + if (sched_getaffinity (0, size, set) == 0) + { +@@ -143,16 +153,19 @@ num_processors_via_affinity_mask (void) + } + if (errno != EINVAL) + { ++ /* Some other error. */ + CPU_FREE (set); + return 0; + } + CPU_FREE (set); ++ /* Retry with some larger cpu_set_t. */ + alloc_count *= 2; + if (alloc_count == 0) ++ /* Integer overflow. Avoid an endless loop. */ + return 0; + } + } +-#elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC /* glibc >= 2.3.4 */ ++# endif + { + cpu_set_t set; + diff --git a/coreutils.spec b/coreutils.spec index d9e2633..529e09a 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,7 +1,7 @@ Summary: A set of basic GNU tools commonly used in shell scripts Name: coreutils Version: 9.4 -Release: 8%{?dist} +Release: 9%{?dist} # some used parts of gnulib are under various variants of LGPL License: GPL-3.0-or-later AND GFDL-1.3-no-invariants-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later Url: https://www.gnu.org/software/coreutils/ @@ -38,6 +38,10 @@ Patch106: coreutils-9.4-CVE-2024-0684.patch # fix tail on kernels with 64k pagesize Patch107: coreutils-9.4-tail-64k-pages.patch +# https://bugzilla.redhat.com/show_bug.cgi?id=2325167 +Patch108: coreutils-nproc-affinity-1.patch +Patch109: coreutils-nproc-affinity-2.patch + # (sb) lin18nux/lsb compliance - multibyte functionality patch Patch800: coreutils-i18n.patch @@ -262,6 +266,9 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir %license COPYING %changelog +* Wed Nov 13 2024 Florian Weimer - 9.4-9 +- Affinity mask handling in nproc for large CPU counts (rhbz#2325167) + * Fri Sep 27 2024 Lukáš Zaoral - 9.4-8 - fix fold -b with UTF8 locale (RHEL-60295)