!89 coreutils:backport some patches from upstream

From: @ship_harbour 
Reviewed-by: @openeuler-basic 
Signed-off-by: @openeuler-basic
This commit is contained in:
openeuler-ci-bot 2023-03-17 07:11:19 +00:00 committed by Gitee
commit afdf4d4f80
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 481 additions and 1 deletions

View File

@ -0,0 +1,86 @@
From 708ae170c987dab83273cb885496e1a8a90233e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Sat, 27 Aug 2022 18:40:14 +0100
Subject: [PATCH] comm: fix NUL --output-delimiter with --total
* src/comm.c (compare_files): Handle the single character
--output-delimeter case separately so that NUL is appropriately
handled.
* doc/coreutils.texi (comm invocation): Fix the description
of --output-delimiter to say an empty delimeter is treated
as a NUL separator, rather than being disallowed.
* tests/misc/comm.pl: Add a test case.
Reported at https://bugs.debian.org/1014008
Reference:https://github.com/coreutils/coreutils/commit/708ae170c987dab83273cb885496e1a8a90233e8
Conflict:Context adaptation
---
doc/coreutils.texi | 3 ++-
src/comm.c | 21 ++++++++++++++++-----
tests/misc/comm.pl | 3 +++
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 9f31f6768..de819b6dc 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -5427,7 +5427,8 @@ Other options are:
Print @var{str} between adjacent output columns,
rather than the default of a single TAB character.
-The delimiter @var{str} may not be empty.
+The delimiter @var{str} may be empty, in which case
+the ASCII NUL character is used to delimit output columns.
@item --total
Output a summary at the end.
diff --git a/src/comm.c b/src/comm.c
index 721139cb8..ed9d97d0a 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -395,11 +395,22 @@ compare_files (char **infiles)
char buf1[INT_BUFSIZE_BOUND (uintmax_t)];
char buf2[INT_BUFSIZE_BOUND (uintmax_t)];
char buf3[INT_BUFSIZE_BOUND (uintmax_t)];
- printf ("%s%s%s%s%s%s%s%c",
- umaxtostr (total[0], buf1), col_sep,
- umaxtostr (total[1], buf2), col_sep,
- umaxtostr (total[2], buf3), col_sep,
- _("total"), delim);
+ if (col_sep_len == 1)
+ { /* Separate to handle NUL char. */
+ printf ("%s%c%s%c%s%c%s%c",
+ umaxtostr (total[0], buf1), *col_sep,
+ umaxtostr (total[1], buf2), *col_sep,
+ umaxtostr (total[2], buf3), *col_sep,
+ _("total"), delim);
+ }
+ else
+ {
+ printf ("%s%s%s%s%s%s%s%c",
+ umaxtostr (total[0], buf1), col_sep,
+ umaxtostr (total[1], buf2), col_sep,
+ umaxtostr (total[2], buf3), col_sep,
+ _("total"), delim);
+ }
}
}
diff --git a/tests/misc/comm.pl b/tests/misc/comm.pl
index 73e8c3720..5d0c4f175 100755
--- a/tests/misc/comm.pl
+++ b/tests/misc/comm.pl
@@ -157,6 +157,9 @@ my @Tests =
{OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"} ],
['zdelim-empty', '-z', '-z --output-delimiter=', @zinputs,
{OUT=>"1\000\0002\000\0002\000\000\0003\000\000\0003\000\000\0003\000"} ],
+ ['total-delim-empty', '--total --output-delimiter=', @inputs,
+ {OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"
+ . "1\0002\0003\000total\n"} ],
# invalid dual delimiter
['delim-dual', '--output-delimiter=,', '--output-delimiter=+', @inputs,
--
2.27.0

View File

@ -0,0 +1,54 @@
From 7fc84d1c0f6b35231b0b4577b70aaa26bf548a7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Sat, 7 Jan 2023 16:10:01 +0000
Subject: [PATCH] copy: copy_file_range: handle ENOENT for CIFS
* src/copy.c (sparse_copy): Fallback to standard copy upon ENOENT,
which was seen intermittently across CIFS file systems.
* NEWS: Mention the bug fix, though qualify it as an "issue"
rather than a bug, as coreutils is likely only highlighting
a CIFS bug in this case.
Fixes https://bugs.gnu.org/60455
Reference:https://github.com/coreutils/coreutils/commit/7fc84d1c0f6b35231b0b4577b70aaa26bf548a7c
Conflict:NEWS context adapation
---
NEWS | 4 ++++
src/copy.c | 5 +++++
2 files changed, 9 insertions(+)
diff --git a/NEWS b/NEWS
index 9d3f253..b65bc85 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 9.0 (2021-09-24) [stable]
** Bug fixes
+ cp, mv, and install now handle ENOENT failures across CIFS file systems,
+ falling back from copy_file_range to a better supported standard copy.
+ [issue introduced in coreutils-9.0]
+
stty now wraps output appropriately for the terminal width.
Previously it may have output 1 character too wide for certain widths.
[bug introduced in coreutils-5.3]
diff --git a/src/copy.c b/src/copy.c
index 519c43b00..98f2ba45a 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -290,6 +290,11 @@ sparse_copy (int src_fd, int dest_fd, char **abuf, size_t buf_size,
if (errno == EPERM && *total_n_read == 0)
break;
+ /* ENOENT was seen sometimes across CIFS shares, resulting in
+ no data being copied, but subsequent standard copies succeed. */
+ if (errno == ENOENT && *total_n_read == 0)
+ break;
+
if (errno == EINTR)
n_copied = 0;
else
--
2.27.0

View File

@ -0,0 +1,96 @@
From 440b528b1d81dd31b2a2e4dde20d5c837c147811 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 6 Dec 2022 10:27:43 -0800
Subject: [PATCH] fts: fix race + mishandling of fstatat failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
I hope this fixes a Luke Dashjr coreutils bug report about ext4
ramdisks; see “9.1: du Aborted (corrupt filesystem)”
<https://debbugs.gnu.org/59821>.
* lib/fts.c (fts_build): Fix two bugs. First, fts_stat was being
called without checking its return value, causing a later abort.
Second, there was a race between opening a directory and statting
it, fixed by using fstat on the file descriptor rather than
fstatat on the directory name.
Reference:https://github.com/coretuils/gnulib/commit/440b528b1d81dd31b2a2e4dde20d5c837c147811
Conflict:Context adapation
---
ChangeLog | 10 ++++++++++
lib/fts.c | 32 ++++++++++++++++++++++++--------
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 44fe270..1785234 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-12-06 Paul Eggert <eggert@cs.ucla.edu>
+
+ fts: fix race + mishandling of fstatat failure
+ I hope this fixes a Luke Dashjr coreutils bug report about ext4
+ ramdisks; see “9.1: du Aborted (corrupt filesystem)”
+ <https://debbugs.gnu.org/59821>.
+ * lib/fts.c (fts_build): Fix two bugs. First, fts_stat was being
+ called without checking its return value, causing a later abort.
+ Second, there was a race between opening a directory and statting
+ it, fixed by using fstat on the file descriptor rather than
+ fstatat on the directory name.
+
2021-09-24 Pádraig Brady <P@draigBrady.com>
version 9.0
diff --git a/lib/fts.c b/lib/fts.c
index 27354d39c8..74a08f7ec8 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1316,19 +1316,35 @@ fts_build (register FTS *sp, int type)
/* Rather than calling fts_stat for each and every entry encountered
in the readdir loop (below), stat each directory only right after
opening it. */
- if (cur->fts_info == FTS_NSOK)
- cur->fts_info = fts_stat(sp, cur, false);
- else if (sp->fts_options & FTS_TIGHT_CYCLE_CHECK)
- {
- /* Now read the stat info again after opening a directory to
+ bool stat_optimization = cur->fts_info == FTS_NSOK;
+
+ if (stat_optimization
+ /* Also read the stat info again after opening a directory to
reveal eventual changes caused by a submount triggered by
the traversal. But do it only for utilities which use
FTS_TIGHT_CYCLE_CHECK. Therefore, only find and du
benefit/suffer from this feature for now. */
- LEAVE_DIR (sp, cur, "4");
- fts_stat (sp, cur, false);
- if (! enter_dir (sp, cur))
+ || ISSET (FTS_TIGHT_CYCLE_CHECK))
+ {
+ if (!stat_optimization)
+ LEAVE_DIR (sp, cur, "4");
+ if (fstat (dir_fd, cur->fts_statp) != 0)
+ {
+ int fstat_errno = errno;
+ closedir_and_clear (cur->fts_dirp);
+ if (type == BREAD)
+ {
+ cur->fts_errno = fstat_errno;
+ cur->fts_info = FTS_NS;
+ }
+ __set_errno (fstat_errno);
+ return NULL;
+ }
+ if (stat_optimization)
+ cur->fts_info = FTS_D;
+ else if (! enter_dir (sp, cur))
{
+ closedir_and_clear (cur->fts_dirp);
__set_errno (ENOMEM);
return NULL;
}
--
2.27.0

View File

@ -0,0 +1,66 @@
From c9a21ec3173b93de4839e5ff9eddadb020431656 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Sat, 31 Dec 2022 17:03:39 +0000
Subject: [PATCH] stty: fix off by one column wrapping on output
* src/stty.c (wrapf): Adjust the comparison by 1,
to account for the space we're adding.
* tests/misc/stty.sh: Add a test case.
* NEWS: Mention the fix.
Reported in https://bugs.debian.org/1027442
Refernece:https://github.com/coreutils/coreutils/commit/c9a21ec3173b93de4839e5ff9eddadb020431656
Conflict:NEWS Context adapation
---
NEWS | 4 ++++
src/stty.c | 2 +-
tests/misc/stty.sh | 6 ++++++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 805f012..9d3f253 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ GNU coreutils NEWS
* Noteworthy changes in release 9.0 (2021-09-24) [stable]
** Bug fixes
+ stty now wraps output appropriately for the terminal width.
+ Previously it may have output 1 character too wide for certain widths.
+ [bug introduced in coreutils-5.3]
+
stty ispeed and ospeed options no longer accept and silently ignore
invalid speed arguments. Now they're validated against both the
general accepted set, and the system supported set of valid speeds.
diff --git a/src/stty.c b/src/stty.c
index b4c2cbecd..f3c7915e1 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -519,7 +519,7 @@ wrapf (char const *message,...)
if (0 < current_col)
{
- if (max_col - current_col < buflen)
+ if (max_col - current_col <= buflen)
{
putchar ('\n');
current_col = 0;
diff --git a/tests/misc/stty.sh b/tests/misc/stty.sh
index bcdc80e87..7abcec5af 100755
--- a/tests/misc/stty.sh
+++ b/tests/misc/stty.sh
@@ -89,4 +89,10 @@ returns_ 1 strace -o log2 -e ioctl stty -blahblah || fail=1
n_ioctl2=$(wc -l < log2) || framework_failure_
test "$n_ioctl1" = "$n_ioctl2" || fail=1
+# Ensure we wrap output appropriately
+for W in $(seq 80 90); do
+ output_width=$(COLUMNS="$W" stty -a | wc -L)
+ test "$output_width" -le "$W" || fail=1
+done
+
Exit $fail
--
2.27.0

View File

@ -0,0 +1,110 @@
From f87a78f334f25cbaac89507c8fda24d4f780b908 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Wed, 31 Aug 2022 00:17:21 +0100
Subject: [PATCH] stty: validate ispeed and ospeed arguments
* src/stty.c (apply_settings): Validate [io]speed arguments
against the internal accepted set.
(set_speed): Check the cfset[io]speed() return value so
that we validate against the system supported set.
* tests/misc/stty-invalid.sh: Add a test case.
* NEWS: Mention the bug fix.
Reported in https://bugs.debian.org/1018790
Reference:https://github.com/coreutils/coreutils/commit/f87a78f334f25cbaac89507c8fda24d4f780b908
Conflict:Context adapation
---
NEWS | 5 +++++
src/stty.c | 29 +++++++++++++++++++++++++----
tests/misc/stty-invalid.sh | 3 +++
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index f2fbcbb..805f012 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ GNU coreutils NEWS
* Noteworthy changes in release 9.0 (2021-09-24) [stable]
** Bug fixes
+ stty ispeed and ospeed options no longer accept and silently ignore
+ invalid speed arguments. Now they're validated against both the
+ general accepted set, and the system supported set of valid speeds.
+ [This bug was present in "the beginning".]
chmod -v no longer misreports modes of dangling symlinks.
[bug introduced in coreutils-5.3.0]
diff --git a/src/stty.c b/src/stty.c
index 3b6a592a9..3d515223e 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -1159,6 +1159,11 @@ apply_settings (bool checking, char const *device_name,
{
check_argument (arg);
++k;
+ if (string_to_baud (settings[k]) == (speed_t) -1)
+ {
+ error (0, 0, _("invalid ispeed %s"), quote (settings[k]));
+ usage (EXIT_FAILURE);
+ }
if (checking)
continue;
set_speed (input_speed, settings[k], mode);
@@ -1169,6 +1174,11 @@ apply_settings (bool checking, char const *device_name,
{
check_argument (arg);
++k;
+ if (string_to_baud (settings[k]) == (speed_t) -1)
+ {
+ error (0, 0, _("invalid ospeed %s"), quote (settings[k]));
+ usage (EXIT_FAILURE);
+ }
if (checking)
continue;
set_speed (output_speed, settings[k], mode);
@@ -1696,13 +1706,24 @@ set_control_char (struct control_info const *info, char const *arg,
static void
set_speed (enum speed_setting type, char const *arg, struct termios *mode)
{
- speed_t baud;
+ /* Note cfset[io]speed(), do not check with the device,
+ and only check whether the system logic supports the specified speed.
+ Therefore we don't report the device name in any errors. */
+
+ speed_t baud = string_to_baud (arg);
+
+ assert (baud != (speed_t) -1);
- baud = string_to_baud (arg);
if (type == input_speed || type == both_speeds)
- cfsetispeed (mode, baud);
+ {
+ if (cfsetispeed (mode, baud))
+ die (EXIT_FAILURE, 0, "unsupported ispeed %s", quotef (arg));
+ }
if (type == output_speed || type == both_speeds)
- cfsetospeed (mode, baud);
+ {
+ if (cfsetospeed (mode, baud))
+ die (EXIT_FAILURE, 0, "unsupported ospeed %s", quotef (arg));
+ }
}
#ifdef TIOCGWINSZ
diff --git a/tests/misc/stty-invalid.sh b/tests/misc/stty-invalid.sh
index 58e51311d..af49b8d89 100755
--- a/tests/misc/stty-invalid.sh
+++ b/tests/misc/stty-invalid.sh
@@ -50,6 +50,9 @@ if tty -s </dev/tty; then
returns_ 1 stty eol -F/dev/tty eol || fail=1
fi
+# coreutils <= 9.1 would not validate speeds to ispeed or ospeed
+returns_ 1 stty ispeed 420 || fail=1
+
# Just in case either of the above mistakenly succeeds (and changes
# the state of our tty), try to restore the initial state.
stty $saved_state || fail=1
--
2.27.0

View File

@ -0,0 +1,53 @@
From c0c63e9735908a9579f8735001957db6bd81afc3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Mon, 30 Jan 2023 21:44:10 +0000
Subject: [PATCH] tail: fix support for -F with non seekable files
This was seen to be an issue when following a
symlink that was being updated to point to
different underlying devices.
* src/tail.c (recheck): Guard the lseek() call to only
be performed for regular files.
* NEWS: Mention the bug fix.
Reference:https://github.com/coreutils/coreutils/commit/c0c63e9735908a9579f8735001957db6bd81afc3
Conflict:NEWS Context adapation
---
NEWS | 4 ++++
src/tail.c | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index b65bc85..f65eb95 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 9.0 (2021-09-24) [stable]
** Bug fixes
+ tail --follow=name works again with non seekable files. Previously it
+ exited with an "Illegal seek" error when such a file was replaced.
+ [bug introduced in fileutils-4.1.6]
+
cp, mv, and install now handle ENOENT failures across CIFS file systems,
falling back from copy_file_range to a better supported standard copy.
[issue introduced in coreutils-9.0]
diff --git a/src/tail.c b/src/tail.c
index 2244509dd..03061e8bf 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1122,7 +1122,8 @@ recheck (struct File_spec *f, bool blocking)
{
/* Start at the beginning of the file. */
record_open_fd (f, fd, 0, &new_stats, (is_stdin ? -1 : blocking));
- xlseek (fd, 0, SEEK_SET, pretty_name (f));
+ if (S_ISREG (new_stats.st_mode))
+ xlseek (fd, 0, SEEK_SET, pretty_name (f));
}
}
--
2.27.0

View File

@ -1,6 +1,6 @@
Name: coreutils
Version: 9.0
Release: 7
Release: 8
License: GPLv3+
Summary: A set of basic GNU tools commonly used in shell scripts
Url: https://www.gnu.org/software/coreutils/
@ -30,6 +30,12 @@ Patch14: backport-config-color-alias-for-ls.patch
Patch15: backport-coreutils-i18n.patch
Patch16: backport-sort-fix-sort-g-infloop-again.patch
Patch17: backport-tests-sort-NaN-infloop-augment-testing-for-recent-fi.patch
Patch18: backport-comm-fix-NUL-output-delimiter-with-total.patch
Patch19: backport-stty-validate-ispeed-and-ospeed-arguments.patch
Patch20: backport-fts-fix-race-mishandling-of-fstatat-failure.patch
Patch21: backport-stty-fix-off-by-one-column-wrapping-on-output.patch
Patch22: backport-copy-copy_file_range-handle-ENOENT-for-CIFS.patch
Patch23: backport-tail-fix-support-for-F-with-non-seekable-files.patch
Patch9000: openEuler-coreutils-df-direct.patch
%ifarch sw_64
@ -157,6 +163,15 @@ fi
%{_mandir}/man*/*
%changelog
* Fri Mar 17 2023 jiangchuangang<jiangchuangang@huawei.com> - 9.0-8
- sync patches from community
- add backport-comm-fix-NUL-output-delimiter-with-total.patch
backport-stty-validate-ispeed-and-ospeed-arguments.patch
backport-fts-fix-race-mishandling-of-fstatat-failure.patch
backport-stty-fix-off-by-onecolumn-wrapping-on-output.patch
backport-copy-copy_file_range-handle-ENOENT-for-CIFS.patch
backport-tail-fix-support-for-F-with-non-seekable-files.patch
* Wed Oct 19 2022 wuzx<wuzx1226@qq.com> - 9.0-7
- add sw64 patch