Bruno Haible [Thu, 16 Dec 2021 16:24:30 +0000 (08:24 -0800)]
build: non-recursive Automake in a less hacky way
* bootstrap.conf (gnulib_modules): Remove
non-recursive-gnulib-prefix-hack.
(gnulib_tool_option_extras): Add --automake-subdir.
(bootstrap_post_import_hook): No need to massage lib/gnulib.mk.
Paul Eggert [Mon, 6 Dec 2021 22:39:22 +0000 (14:39 -0800)]
uname: port to recent macOS
Problem reported by Jakub Sokołowski (bug #52330).
* src/uname.c [__APPLE__]: Don’t include sys/syctl.h,
mach/machine.h, mach-o/arch.h.
(print_element_env): New function. With __APPLE__, it defers to the
env var UNAME_MACHINE (if given) for uname -m, and similarly for -nrsv.
(main): Use it. For -p with __APPLE__, rely on predefined macros
and omit any 64-bit indication, for compatibility with macOS uname.
Paul Eggert [Sun, 21 Nov 2021 23:07:18 +0000 (15:07 -0800)]
cp: clone on macOS
* configure.ac: Check for fclonefileat.
* src/copy.c [HAVE_FCLONEFILEAT && !USE_XATTR]:
Include <sys/clonefile.h>.
(copy_reg): If possible, use fclonefileat to clone.
Paul Eggert [Sat, 20 Nov 2021 21:48:40 +0000 (13:48 -0800)]
cp: fix --preserve=ownership permissions bug
This fixes a bug that I introduced in
2006-12-06T19:44:08Z!eggert@cs.ucla.edu.
* src/copy.c (USE_XATTR): New macro.
(copy_reg): Use it to help the compiler. Prefer open u+w to a
later chmod u=rw; u+r isn’t needed for xattr. For the later u-r,
do only one (or zero) chmod calls instead of two (or one).
In the last chmod, respect the umask instead of ignoring it.
* tests/cp/preserve-mode.sh: Test for the bug.
Paul Eggert [Fri, 19 Nov 2021 05:36:47 +0000 (21:36 -0800)]
maint: prefer MAYBE_UNUSED
Prefer MAYBE_UNUSED to _GL_UNUSED, since the C2x syntax
will be [[maybe_unused]] at the start of the declaration,
and we want to look forward to that. All uses of _GL_UNUSED
either changed to MAYBE_UNUSED, or (when not needed) removed.
Paul Eggert [Wed, 17 Nov 2021 21:22:06 +0000 (13:22 -0800)]
cp: fix security context race
This fixes an issue introduced in the fix for Bug#11100.
* NEWS: Mention this.
* src/copy.c (copy_reg): Fix obscure bug where open-without-CREAT
failed with ENOENT and we forget to call set_process_security_ctx
before calling open-with-CREAT. Also, don’t bother to unlink
DST_NAME if open failed with ENOENT; and if unlink fails with
ENOENT, don’t consider that to be an error (someone else could
have removed the file for us, and that’s OK). Also, don’t worry
about move mode, since we use O_EXCL|O_CREAT and so won’t open
an existing file.
Pádraig Brady [Sat, 13 Nov 2021 12:15:17 +0000 (12:15 +0000)]
tests: avoid false failure in env-signal-handler.sh
* tests/misc/env-signal-handler.sh: Use retry_delay_ to
avoid a false failure under load, where env hasn't setup
the SIGINT handling before timeout(1) sends the SIGINT.
Fixes https://bugs.gnu.org/51793
Pádraig Brady [Mon, 1 Nov 2021 13:36:43 +0000 (13:36 +0000)]
maint: fix recent syntax-check failures
* cfg.mk (exclude_file_name_regexp--sc_system_h_headers):
Add chown-core.h to the regexp, to better decouple from system.h.
* src/env.c: Remove minmax.h include already included in system.h.
* src/libstdbuf.c: Likewise.
* src/prog-fprintf.h: Remove doubled semicolon.
Paul Eggert [Mon, 1 Nov 2021 05:30:38 +0000 (22:30 -0700)]
maint: add function attributes to .h files
Add _GL_ATTRIBUTE_NONNULL, _GL_ATTRIBUTE_MALLOC,
_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DALLOC_FREE,
_GL_ATTRIBUTE_RETURNS_NONNULL to .h files when appropriate.
* gl/lib/mbsalign.h, gl/lib/randperm.h, src/chown-core.h:
Include stdlib.h, for the benefit of _GL_ATTRIBUTE_DALLOC_FREE.
* gl/lib/randread.c (randread_free_body): New static function.
(randread_new, randread_free): Use it.
* src/copy.c (valid_options): Remove assert that is no longer
needed because it is now checked statically.
Paul Eggert [Mon, 1 Nov 2021 05:30:38 +0000 (22:30 -0700)]
maint: enable -Wsuggest-attribute=format
* configure.ac (WERROR_CFLAGS): Enable -Wsuggest-attribute=format
for lib/ and src/.
* src/copy.c (copy_attr_error, copy_attr_allerror):
Add ATTRIBUTE_FORMAT.
(copy_attr): Ignore -Wsuggest-attribute=format in the
small section of code that needs it ignored.
* src/test.c (test_syntax_error): Mark with ATTRIBUTE_FORMAT.
(binary_operator): Omit unnecessary NULL args, pacifying
-Wsuggest-attribute=format.
Paul Eggert [Mon, 1 Nov 2021 05:30:38 +0000 (22:30 -0700)]
maint: modernize attribute usage
* src/system.h (__attribute__): Remove. Replace all uses that
rely on this by _GL_ATTRIBUTE_xxx or ATTRIBUTE_xxx.
(ATTRIBUTE_WARN_UNUSED_RESULT): Remove. Replace all uses by
NODISCARD.
Paul Eggert [Mon, 1 Nov 2021 05:30:38 +0000 (22:30 -0700)]
maint: prefer attribute.h in .c files
This will help us make the transition to C2x, where some
attributes must come at the start of function decls.
Leave the attributes alone in .h files for now,
as the Gnulib tradition is to not expose attribute.h to users.
* bootstrap.conf (gnulib_modules): Add ‘attribute’.
* gl/lib/randperm.c, src/make-prime-list.c, src/system.h:
Include attribute.h.
* gl/lib/strnumcmp.c (strnumcmp): Remove _GL_ATTRIBUTE_PURE here,
as this belongs in the .h file.
* gl/lib/strnumcmp.h (strnumcmp): Add _GL_ATTRIBUTE_PURE here.
* src/sort.c (human_numcompare, numcompare): Now ATTRIBUTE_PURE;
discovered due to strnumcmp.h change.
* gl/lib/randperm.c, src/copy.c, src/dd.c, src/df.c, src/digest.c:
* src/env.c, src/expr.c, src/factor.c, src/ls.c:
* src/make-prime-list.c, src/numfmt.c, src/od.c, src/pathchk.c:
* src/pinky.c, src/pr.c, src/ptx.c, src/realpath.c, src/relpath.c:
* src/seq.c, src/sort.c, src/stat.c, src/stty.c, src/system.h:
* src/tr.c, src/uniq.c, src/wc.c:
In .c files, crefer ATTRIBUTE_CONST to _GL_ATTRIBUTE_CONST, and
similarly for ATTRIBUTE_FORMAT and ATTRIBUTE_PURE.
* src/system.h (FALLTHROUGH): Remove; attribute.h defines it.
Pádraig Brady [Sun, 10 Oct 2021 17:35:59 +0000 (18:35 +0100)]
sort: --debug: add warnings about sign, radix, and grouping chars
New warnings are added related to the handling
of thousands grouping characters, decimal points, and sign characters.
Examples now diagnosed are:
$ printf '0,9\n1,a\n' | sort -nk1 --debug -t, -s
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a group separator in numbers
1,a
_
0,9
___
$ printf '1,a\n0,9\n' | LC_ALL=fr_FR.utf8 sort -gk1 --debug -t, -s
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a decimal point in numbers
0,9
___
1,a
__
$ printf '1.0\n0.9\n' | LC_ALL=fr_FR.utf8 sort -s -k1,1g --debug
sort: note numbers use ‘,’ as a decimal point in this locale
0.9
_
1.0
_
$ LC_ALL=fr_FR.utf8 sort -n --debug /dev/null
sort: text ordering performed using ‘fr_FR.utf8’ sorting rules
sort: note numbers use ‘,’ as a decimal point in this locale
sort: the multi-byte number group separator in this locale \
is not supported
$ sort --debug -t- -k1n /dev/null
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘-’ is treated as a minus sign in numbers
sort: note numbers use ‘.’ as a decimal point in this locale
$ sort --debug -t+ -k1g /dev/null
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘+’ is treated as a plus sign in numbers
sort: note numbers use ‘.’ as a decimal point in this locale
* src/sort.c (key_warnings): Add the warnings above.
* tests/misc/sort-debug-warn.sh: Add test cases.
Also check that all sort invocations succeed.
* NEWS: Mention the improvement.
Addresses https://bugs.gnu.org/51011
Paul Eggert [Sat, 30 Oct 2021 17:00:10 +0000 (10:00 -0700)]
cp: revert unnecessary FreeBSD workaround
That was a false alarm due to a bug in FreeBSD 9.1 truss;
see Pádraig Brady’s report (Bug#51433#29).
* src/copy.c (lseek_copy, infer_scantype): Don’t bother checking
whether lseek returned -1. This doesn’t entirely revert the
previous change, as it keeps the code simplification of the
previous change while reverting the check for -1.
Paul Eggert [Sat, 30 Oct 2021 01:01:34 +0000 (18:01 -0700)]
cp: defend better against FreeBSD 9.1 zfs bug
Problem reported by Pádraig Brady (Bug#51433#14).
* src/copy.c (lseek_copy, infer_scantype): Report an error if
lseek with SEEK_DATA or SEEK_HOLE returns less than -1,
as this is an lseek bug.
Pádraig Brady [Thu, 21 Oct 2021 12:05:47 +0000 (13:05 +0100)]
doc: say that printf(1) is preferred over echo(1)
* src/echo.c (usage): Say printf(1) is preferred
due to being more standard and robust.
* man/echo.x [SEE ALSO]: Reference printf(1).
* doc/coreutils.texi (echo invocation): Mention in the
summary that echo is not robust when outputting
any string, and that printf is preferred.
Also expand on the examples showing how to
output a single '-n' string.
Addresses https://bugs.gnu.org/51311
* doc/coreutils.texi (timeout invocation): Clarify
that -k is ignored if either its duration or the
main timeout duration is 0.
Addresses https://bugs.gnu.org/51128
Pádraig Brady [Tue, 12 Oct 2021 13:32:57 +0000 (14:32 +0100)]
timeout: ensure --foreground -k exits with status 137
* src/timeout.c (main): Propagate the killed status from the child.
* doc/coreutils.texi (timeout invocation): Remove the
description of the --foreground specific handling of SIGKILL,
now that it's consistent with the default mode of operation.
* tests/misc/timeout.sh: Add a test case.
* NEWS: Mention the change in behavior.
Fixes https://bugs.gnu.org/51135
Pádraig Brady [Mon, 11 Oct 2021 21:04:38 +0000 (22:04 +0100)]
doc: timeout --foreground: add clarification on exit status
* doc/coreutils.texi (timeout invocation): Add detail on
how --foreground allows timeout(1) to use more standard
exit status as the uncatchable SIGKILL is not sent to itself.
Fixes https://bugs.gnu.org/51135
Paul Eggert [Sun, 10 Oct 2021 22:59:56 +0000 (15:59 -0700)]
sort: fix unlikely bug when '\377' < 0
* gl/lib/strintcmp.c (strintcmp): Don’t assume that the input
cannot contain ((char) -1), as this equals '\377' when char is
signed (assuming 8-bit char).
* src/sort.c (decimal_point): Now char, to make it clear
that it’s always in char range now.
(NON_CHAR): New constant.
(traverse_raw_number): Return char not unsigned char;
this is simpler and could be faster. All callers changed.
(main): Do not convert decimal_point and thousands_sep to
unsigned char, as this can mishandle comparisons on
machines where char is signed and the input data contains
((char) -1). Use NON_CHAR, not -1, as an out-of-range value for
thousands_sep.
Paul Eggert [Sun, 3 Oct 2021 01:41:10 +0000 (18:41 -0700)]
maint: switch to C11-style _Noreturn
Use C11-style _Noreturn instead of the old ATTRIBUTE_NORETURN
macro. This pacifies clang on OpenBSD 6.9, which otherwise
complains "'noreturn' function does return" in some places.
* gl/lib/randread.c, src/system.h (ATTRIBUTE_NORETURN):
Remove. All uses either removed as GCC no longer needs them, or
changed to C11-style _Noreturn since Gnulib arranges for _Noreturn
globally nowadays.
* doc/coreutils.texi (ls invocation - general output formatting):
The option ordering was not changed when the option was renamed
from --null to --zero.
tests: cp/sparse-perf: make more robust and add zfs comments
* init.cfg (seek_data_capable_): Add a timeout to ensure failure for
slow lseek(...SEEK_DATA) calls (even if that syscall isn't interrupted).
* tests/cp/sparse-perf.sh: Run the SEEK_DATA check on the
1TiB empty file to exclude both FreeBSD 9.1 which takes 35s,
and ZFS which requires a delay of about 5s between file creation
and use of SEEK_DATA to correctly determine it's empty (return ENXIO).
Also remove the stat size checks as they invalidate the test
due to cp never writing data due to it being always zeros,
and thus converted to holes in the output.
* src/chmod.c: Reorder enum so CH_NOT_APPLIED
can be treated as a non error.
* tests/chmod/ignore-symlink.sh: A new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/50784
* tests/cp/sparse-perf.sh: Avoid the case where
we saw SEEK_DATA take 35s to return a result
against a 1TB sparse file. This happened on
a FreeBSD 9.1 VM at least.
Reported by Nelson H. F. Beebe.
* src/cksum.c (crc_sum_stream): On sparc64 for example,
a crc of 0 was printed due to mismatch in size of
variable copied between generator and output functions.
uint_fast32_t is generally 64 bits on 64 bit systems,
so we copy through an int to ensure we don't use the wrong
end of a 64 bit variable.
Reported by Nelson H. F. Beebe
* bootstrap.conf: We only need poll on Linux and AIX
where poll is not replaced. Also resinstate dependence
on select so we can use it unconditionally.
* src/tail.c (check_output_alive): Reinstate use of select()
by default as poll was seen to be ineffective for this
application on macOS.
Fixes https://bugs.gnu.org/50714
cksum: support more transparent emulation of older utils
* src/digest.c: Allow using the --untagged option with --check,
so that `cksum -a md5 --untagged` used to emulate md5sum for example,
may be augmented with the --check option. Also support the --tag
option with cksum, to allow overriding a previous --untagged setting.
* doc/coreutils.texi: Adjust accordingly.
* tests/misc/cksum-a.sh: Likewise.
* tests/tail-2/F-vs-rename.sh: Keep stdout and stderr separate,
so that interspersion doesn't impact regex checks. Also wait
for each file's data to be printed to avoid multiple writes
to a file to be printed in a single iteration, which would
impact the regex checks. Also we refactor the check function,
rather than repeatedly redefining variations.
tests: fix rare false failure in tail-2/F-vs-rename
This is wrong fix really, as only introducing delay I think.
* tests/tail-2/F-vs-rename.sh: Avoid a rare false failure
due to a race in the test. Now wait until tail has noticed
that b is replaced before writing to a, so that the subsequent
write of "y" to b will be displayed independently from
current contents of b ("x").
* tests/ls/removed-directory.sh: On FreeBSD 9.1 at least,
one gets ENOENT when trying to traverse the current removed dir
with ../, so instead reference the parent dir directly.
Jim Meyering [Thu, 16 Sep 2021 20:23:46 +0000 (13:23 -0700)]
build: avoid new chmod.c warnings from upcoming GCC12
Here are the warnings:
src/chmod.c:175:3: error: 'ch.new_mode' may be used uninitialized in\
this function [-Werror=maybe-uninitialized]
175 | strmode (ch->new_mode, perms);
src/chmod.c:178:3: error: 'ch.old_mode' may be used uninitialized in\
this function [-Werror=maybe-uninitialized]
178 | strmode (ch->old_mode, old_perms);
* src/chmod.c (process_file): Initialize ch. Its new_mode and
old_mode fields could indeed be used uninitialized to form mode
strings, but those are used only when built from initialized members.
* src/digest.c (digest_check): Treat empty lines like comments,
as commented checksum files very often have empty lines.
* tests/misc/md5sum.pl: Adjust accordingly.
cksum: fix --check with non tagged format checksums
* src/digest.c: Always set the digest_length, so that
we check the correct number of hex digits when parsing
non tagged format checksums.
* tests/misc/cksum-a.sh: Add a test case. Also fix
up this test which was ineffective due to fail=1
being set in a subshell and ignored.
Support checksum files with CRLF line endings,
which is a common gotcha for using --check on windows,
or with checksum files generated on windows.
Note we escape \r here to support the original coreutils format
(with file name at EOL), and file names with literal
\r characters as the last character of their name.
* src/digest.c (filename_unescape): Convert \\r -> \r.
(print_filename): Escape \r -> \\r.
(output_file): Detect \r chars in file names.
(digest_check): Ignore literal \r char at EOL.
* tests/misc/md5sum.pl: Add a test case.
* tests/misc/sha1sum.pl: Likewise.
* NEWS: Mention the improvement.
This only practically matters on windows.
But given there are separate text handling options in cygwin,
keep the interface simple, and avoid exposing the
confusing binary/text difference here.
* doc/coreutils.texi (md5sum invocation): Mention that
--binary and --text are not supported by the cksum command.
* src/digest.c: Set flag to use binary mode by default.
(output_file): Don't distinguish text and binary modes with
' ' and '*', and just use ' ' always.
This format is a better default, since it results in simpler usage,
as you don't need to specify --tag on generation or -a on
checking invocations. Also it's a more general format supporting
mixed and length adjusted digests.
* doc/coreutils.texi (cksum invocation): Document a new --untagged
option, to use the older coreutils format.
(md5sum invocation): Mention that cksum doesn't support --tag.
* src/digest.c: Adjust cksum(1) to default to --tag,
and accept the new --untagged option.
* tests/misc/b2sum.sh: Adjust accordingly.
* tests/misc/cksum-a.sh: Likewise.
* tests/misc/cksum-c.sh: Likewise.
* src/cksum.h: Thread DELIM through the output functions.
* src/digest.c: Likewise.
* src/sum.c: Likewise.
* src/sum.h: Likewise.
* src/cksum.c: Likewise. Also adjust check to allow -z
with traditional output modes. Also ajust the global variable
name to avoid shadowing warnings.
* tests/misc/cksum-a.sh: Adjust accordingly.
Support `cksum --check FILE` without having to specify a digest
algorithm, allowing for more generic file check instructions.
This also supports mixed digest checksum files, supporting
more robust multi digest checks.
* src/digest.c (algorithm_from_tag): A new function to
identify the digest algorithm from a tagged format line.
(split3): Set the algorithm depending on tag, and update
the expected digest length accordingly.
* tests/misc/cksum-c.sh: Add a new test.
* tests/local.mk: Reference the new test.
* tests/misc/md5sum.pl: Adjust to more generic error.
* tests/misc/sha1sum.pl: Likewise.
* doc/coreutils.texi (md5sum invocation): Mention the new -c feature.
* NEWS: Mention the new feature.
Add message digest sm3, which uses the OSCCA SM3 secure
hash (OSCCA GM/T 0004-2012 SM3) generic hash transformation.
* bootstrap.conf: Add the sm3 module.
* doc/coreutils.texi: Mention the cksum -a option.
* src/digest.c: Provide support for --algorithm='sm3'.
* tests/misc/sm3sum.pl: Add a new test (from Tianjia Zhang)
* tests/local.mk: Reference the new test.
* NEWS: Mention the new feature.
cksum: add --algorithm option to select digest mode
* src/digest.c: Organize HASH_ALGO_CKSUM to be table driven,
and amalgamate all digest algorithms.
(main): Parse all options if HASH_ALGO_CKSUM, and disallow
--tag, --zero, and --check with the traditional bsd, sysv, and crc
checksums for now.
* src/local.mk: Reorganize to include all digest modules in cksum.
* tests/misc/cksum-a.sh: Add a new test.
* tests/misc/b2sum.sh: Update to default to checking with cksum,
as b2sum's implementation diverges a bit from the others.
* tests/local.mk: Reference the new test.
* doc/coreutils.texi (cksum invocation): Adjust the summary to
identify the new mode, and document the new --algorithm option.
* man/cksum.x: Adjust description to be more general.
* man/*sum.x: Add [See Also] section referencing cksum(1).
* NEWS: Mention the new feature.
* cfg.mk: Adjust cksum.c to not require config.h
and support a main (for crctab) without calling bindtextdomain().
* po/POTFILES.in: Remove cksum_pclmul.c since it no longer
concerns itself with diagnostics.
* src/cksum.c: Refactor to just providing stream digest,
and digest printing functionality.
* src/cksum.h: Adjust to the new interface.
* src/cksum_pclmul.c: Remove diagnostics, and determine errors
internally.
* src/crctab.c: Separate from cksum.h since that's now included
multiple times.
* src/digest.c: Provide cksum(1) functionality if -DHASH_ALGO_CKSUM
* src/local.mk: Adjust to new crctab.c and HASH_ALGO_CKSUM define.
* doc/coreutils.texi (cksum invocation): Add the --debug description.
* src/cksum.c (usage): Likewise.
(main): Also give explicit indication when using generic hardware.
Pádraig Brady [Sun, 29 Aug 2021 18:34:32 +0000 (19:34 +0100)]
digest: refactor sum(1) into digest.c
Since digest will be providing all digest functionality,
refactor sum.c into it.
* po/POTFILES.in: sum.c no longer has translatable strings so remove.
* src/digest.c: Call out to new stream interfaces in sum.c
* src/local.mk: Adjust sources for the sum binary.
* src/sum.c: Provide a stream interface for BSD and SYSV digests.
* src/sum.h: A new file to declare the exported functions in sum.c
* doc/coreutils.texi (whoami invocation): Clarify it prints names,
not numeric IDs.
* man/whoami.x: Likewise.
* man/logname.x: Reference getlogin(3).
* src/logname.c: Clarify that it prints the login name,
rather than the name of the effective user ID.
Search for "direct color" at:
https://invisible-island.net/xterm/terminfo.html
* src/dircolors.hin: Add *direct* to match terminals that
support direct colors (24-bit color / TrueColor).
The trailing * will match entries like xterm-direct2.
* tests/ls/stat-vs-dirent.sh: Skip the test if we can't stat(1),
as the file may have been removed, or have a malformed name
due to '\n' etc. in the file name.
* gnulib: Update to latest. This fixes a gnulib test failure in base64,
among other fixes.
* cfg.mk: Disable sc_indent as auto indent is too invasive for now.