Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
Florian Weimer
c6c6bbd1df Affinity mask handling in nproc for large CPU counts (rhbz#2325167) 2024-11-13 09:58:28 +01:00
Lukáš Zaoral
8bde780ab4
fix fold -b with UTF8 locale
Resolves: RHEL-60295
2024-09-27 13:23:26 +02:00
Sohum Mendon
e2907bebf3
Fix fold exit status for nonexistent files 2024-07-13 14:20:35 -07:00
4 changed files with 170 additions and 39 deletions

View file

@ -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 <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;
+ }
+ }
+
@ -1752,7 +1751,7 @@ index 5c0428d..2372047 100644
+ if (istream == NULL)
+ {
+ error (0, errno, "%s", filename);
+ return 1;
+ return false;
+ }
+
+ /* Define how ISTREAM is being folded. */
@ -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

View file

@ -0,0 +1,55 @@
commit 45c2456a56337ebcafe0dd9faa2bd995ccbc3357
Author: Florian Weimer <fweimer@redhat.com>
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 <config.h>
#include "nproc.h"
+#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
@@ -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;

View file

@ -0,0 +1,64 @@
commit ee0bc695303775da5026091a65e8ec2b764f4a26
Author: Bruno Haible <bruno@clisp.org>
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:
+ <https://www.kernel.org/doc/man-pages/online/pages/man2/sched_getaffinity.2.html>
+ <https://www.kernel.org/doc/man-pages/online/pages/man3/CPU_SET.3.html>
+ 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;

View file

@ -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: 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,15 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir
%license COPYING
%changelog
* Wed Nov 13 2024 Florian Weimer <fweimer@redhat.com> - 9.4-9
- Affinity mask handling in nproc for large CPU counts (rhbz#2325167)
* Fri Sep 27 2024 Lukáš Zaoral <lzaoral@redhat.com> - 9.4-8
- fix fold -b with UTF8 locale (RHEL-60295)
* Sat Jul 13 2024 Sohum Mendon <sohum.mendon@proton.me> - 9.4-7
- fix incorrect exit status when fold is called with a non-existent file
* Mon Jan 29 2024 Lukáš Zaoral <lzaoral@redhat.com> - 9.4-6
- fix tail on kernels with 64k page sizes (RHEL-22866)