* .gitignore: Add new headers from gnulib.
* src/basenc.c: Adjust line length due to replacement
of 'verify' with 'static_assert'.
* src/od.c: Likewise.
Paul Eggert [Wed, 21 Sep 2022 21:05:49 +0000 (14:05 -0700)]
rm: fix diagnostics on I/O error
I ran into this problem when attempting to recursively
remove a directory in a filesystem on flaky hardware.
Although the underlying readdir syscall failed with errno == EIO,
rm issued no diagnostic about the I/O error.
Without this patch I see this behavior:
$ rm -fr baddir
rm: cannot remove 'baddir': Directory not empty
$ rm -ir baddir
rm: descend into directory 'baddir'? y
rm: remove directory 'baddir'? y
rm: cannot remove 'baddir': Directory not empty
With this patch I see the following behavior, which
lets the user know about the I/O error when rm tries
to read baddir's directory entries:
* src/remove.c (Ternary): Remove. All uses removed.
(get_dir_status): New static function.
(prompt): Last arg is now directory status, not ternary.
Return RM_USER_ACCEPTED if user explicitly accepted.
All uses changed.
Report any significant error in directory status right away.
(prompt, rm_fts): Use get_dir_status to get directory status lazily.
(excise): Treat any FTS_DNR errno as being more descriptive, not
just EPERM and EACCESS. For example, EIO is more descriptive.
(rm_fts): Distinguish more clearly between explicit and implied
user OK.
* src/remove.h (RM_USER_ACCEPTED): New constant.
(VALID_STATUS): Treat it as valid.
* src/system.h (is_empty_dir): Remove, replacing with ...
(directory_status): ... this more-general function.
All uses changed. Avoid undefined behavior of looking at
a non-null readdir pointer after corresponding closedir.
* tests/rm/rm-readdir-fail.sh: Adjust test of internals
to match current behavior.
Paul Eggert [Thu, 15 Sep 2022 06:03:10 +0000 (01:03 -0500)]
maint: fix bootstrap module lists for alignof
* bootstrap.conf (gnulib_modules): Remove alignof, which isn’t
needed since coreutils source modules don’t include alignof.h.
Add stdalign, since they depend on alignof working without
stdalign.h.
Paul Eggert [Thu, 15 Sep 2022 05:30:31 +0000 (00:30 -0500)]
maint: don’t include config.h twice
* gl/lib/fadvise.h, gl/lib/smack.h, src/blake2/blake2-impl.h:
Do not include config.h from a .h file. config.h is supposed
to be included once, at the start of compilation and before
any other file.
stty: give explicit error for unsupported asymmetric speeds
* src/stty.c (check_speed): If difference input and output speeds
are specified, then validate the system supports that, before
interacting with the device.
* src/stty.c (eq_mode): A new function to compare
equivalence of two modes.
(main): Use eq_mode() rather than memcmp() to compare
two modes. Also use stack variables rather than implicitly
initialized static variables. Also remove all uses of
the SPEED_WAS_SET hack since we now more robustly compare modes.
* NEWS: Update the [io]speed fix entry.
Reported at https://bugs.debian.org/1019468
Pádraig Brady [Tue, 30 Aug 2022 23:39:59 +0000 (00:39 +0100)]
stty: add an undocumented ---debug option for more info
* src/stty.c (main): Move internal TESTING code that showed
the new and old mode, upon failure to apply the new mode,
to being runtime controlled with the ---debug option.
Also augment the display to show which items were not
set as expected.
Pádraig Brady [Wed, 31 Aug 2022 13:16:14 +0000 (14:16 +0100)]
doc: stty: clarify that [-]drain is treated as an option
* doc/coreutils.texi (stty invocation): Say that "drain"
is treated as an option, rather than a line setting,
and so option processing rules apply to it.
Reported in https://bugs.debian.org/1018803
Pádraig Brady [Tue, 30 Aug 2022 23:17:21 +0000 (00:17 +0100)]
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
Pádraig Brady [Sun, 28 Aug 2022 01:48:11 +0000 (02:48 +0100)]
maint: be defensive in avoiding gnulib's poll module
* src/tail.c (check_output_alive): Add a guard that would
trigger on most platforms, to detect if we're using the
gnulib poll module. That's currently problematic in the
way it emulates poll() using select() and would cause
issues on macOS and AIX at least as poll() is replaced there.
Pádraig Brady [Sat, 27 Aug 2022 17:40:14 +0000 (18:40 +0100)]
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
Pádraig Brady [Sat, 27 Aug 2022 16:50:20 +0000 (17:50 +0100)]
runcon: distinguish runcon specific errors in exit status
* src/runcon.c: Use EXIT_CANCELED (125) instead of EXIT_FAILURE (1),
so that errors specific to runcon can be distinguished,
from those of the invoked program.
* doc/coreutils.texi (runcon invocation): Fix the Exit status
description to say we return 125 (not 127) for internal errors.
* tests/misc/runcon-no-reorder.sh: Add a test case.
Pádraig Brady [Sat, 13 Aug 2022 19:48:12 +0000 (20:48 +0100)]
doc: README: split out ancillary information
The README was becoming too long and contained
quite a bit of info only pertaining to rarely used systems, so...
* README: Split out install specific info to README-install.
Also remove a few stale lines, and reorder a few items.
* README-install: A new file split from README.
* Makefile.am [EXTRA_DIST]: Explicitly reference new README-install
file for distribution, since automake only auto adds README.
* TODO: Reference the HPUX info now in README-install.
Pádraig Brady [Fri, 12 Aug 2022 12:40:00 +0000 (13:40 +0100)]
doc: ls: clarify description of timestamps
* src/ls.c (usage): Don't mention "modification" in the
description of ctime (-c), as it's confusing with mtime.
Mention "metadata" when discussing "change" time to
disambiguate from data change time.
* doc/coreutils.texi (ls invocation): State that --time=creation
falls back to using mtime where not available.
Paul Eggert [Wed, 27 Jul 2022 16:59:38 +0000 (09:59 -0700)]
touch: fix aliasing bug
Problem reported by Tim Lange in:
https://lists.gnu.org/r/coreutils/2022-07/msg00008.html
* src/touch.c (date_relative): Rename from get_reldate,
and use a functional style to fix the aliasing bug.
doc: env: clarify that empty signal args are ignored
It's useful to treat empty and missing arguments differently.
Missing means all signals, while empty means no signals and
so is a no-op. It's useful to treat empty arguments like
this, so that dynamically specified arguments like the following
are supported
env --ignore-signals "$SIGS_TO_IGNORE"
Note `env --ignore-signals=` is treated as an empty argument.
* doc/coreutils.texi (env invocation): Empty args are treated
differently to missing arguments, so call that out explicitly.
* src/env.c (usage): Likewise.
Addresses https://bugs.debian.org/1016049
doc: date: clarify which options are mutually exclusive
* src/date.c (usage): Specify that --date, --file, --reference,
and --resolution are mutually exclusive. This is also useful
documentation to group similar options.
* doc/coreutils.texi (Options for date): Likewise.
Addresses https://bugs.gnu.org/55401
date: --debug: diagnose discarded -d or -s options
* src/date.c: (main): Track and diagnose whether any
-d or -s options are dropped, as users may think
multiple options are supported, given they can be relative.
* tests/misc/date-debug.sh: Add a test case.
* NEWS: Mention the improvement.
runcon: ensure --compute runs the file it inspects
* src/runcon.c (main): With -c avoid searching the path
to ensure the file specified to --compute is executed.
* tests/misc/runcon-compute.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Reported in https://bugs.debian.org/1013924
Paul Eggert [Sat, 23 Jul 2022 19:11:49 +0000 (12:11 -0700)]
rm: don’t assume st_size is nonnegative
* src/remove.c: Include stat-time.h.
(cache_fstatat, cache_stat_init): Use negative st->st_atim.tv_sec to
determine whether the stat is cached, not negative st->st_size.
On non-POSIX platforms that lack st_atim.tv_sec, don’t bother to cache.
Paul Eggert [Wed, 6 Jul 2022 19:29:12 +0000 (14:29 -0500)]
cp: don’t remove nonempty cloned dest
This follows up on comments by Pádraig Brady (bug#56391).
* src/copy.c (copy_reg): When --reflink=always removes a file
due to an FICLONE failure, do not remove a nonempty file.
Paul Eggert [Fri, 24 Jun 2022 15:59:09 +0000 (10:59 -0500)]
shuf: better diagnostic for ‘shuf -i -10-10’
* src/shuf.c: Do not include xdectoint.h.
(main): Improve diagnostic for ‘shuf -i -10-10’. Without this
patch, the diagnostic was “shuf: invalid input range: ‘’” which is
not helpful. Now it is “shuf: invalid input range: ‘-10-10’”.
Paul Eggert [Tue, 21 Jun 2022 03:19:59 +0000 (22:19 -0500)]
maint: prefer POSIX-compatible EREs
* cfg.mk (begword, endword): New macros.
(sc_prohibit_stat_macro_address, sc_prohibit_fail_0)
(sc_prohibit_short_facl_mode_spec, sc_require_stdio_safer)
(sc_prohibit_sleep, sc_prohibit_framework_failure)
(sc_marked_devdiagnostics):
* build-aux/gen-single-binary.sh:
Prefer POSIX-compatible EREs to GNU extensions like \w and \<.
Paul Eggert [Sat, 11 Jun 2022 17:49:18 +0000 (10:49 -0700)]
cp: fix ‘cp -rx / /mnt’
Problem reported by pkoraou@gmail.com (Bug#55910).
* src/copy.c (copy_internal): Treat a relative destination name ""
as if it were "." for the purpose of directory-relative syscalls
like fstatat that might might refer to the destination directory.
Paul Eggert [Wed, 18 May 2022 02:30:09 +0000 (19:30 -0700)]
sort: fix unlikely int overflow with -r
* src/sort.c (keycompare, compare): Don’t overflow if -r is
specified and a comparison function returns INT_MIN, as this
causes the comparison to have undefined behavior (typically the
reverse of correct). glibc memcmp on s390x reportedly returns
INT_MIN in some cases, so this is not a purely academic issue.
Paul Eggert [Wed, 18 May 2022 02:17:12 +0000 (19:17 -0700)]
maint: simplify comparisons
* src/comm.c (compare_files):
* src/join.c (keycmp):
* src/ls.c (off_cmp):
* src/ptx.c (compare_words, compare_occurs):
* src/set-fields.c (compare_ranges):
Prefer ((a > b) - (a < b)) to variants like (a < b ? -1 : a > b)
as it’s typically faster these days.
Paul Eggert [Wed, 18 May 2022 01:55:43 +0000 (18:55 -0700)]
sort: remove some gotos
* src/sort.c (keycompare): Rework to avoid gotos.
This also shrinks the machine code a bit (112 bytes)
with GCC 12 x86-64 -O2. Nowadays compilers are smart
enough to coalesce jumps so we need not do it by hand.
Paul Eggert [Wed, 18 May 2022 01:39:16 +0000 (18:39 -0700)]
sort: pacify GCC 12 false positive
* src/sort.c (keycompare): Rework to pacify a GCC 12
-Wmaybe-uninitialized false positive, by coalescing some minor
duplicate code and eliminating a branch. This should execute an
insn or two less in the usual case.
factor: --exponents: new option for printing in p^e format
When factoring numbers that have a large 2^n factor, it can be hard to
eyeball just how many 2's there are. Add an option to print each prime
power factor in the p^e format (omitting the exponent when it is 1).
* src/factor.c: Add -h, --exponents option for printing in p^e format.
* doc/coreutils.texi (factor invocation): Document the new option.
* tests/misc/factor.pl: Add test case.
* THANKS.in: Add previous suggester
(https://lists.gnu.org/r/coreutils/2017-11/msg00015.html).
Paul Eggert [Mon, 2 May 2022 05:46:21 +0000 (22:46 -0700)]
sort: fix sort -g infloop again
Problem reported by Giulio Genovese (Bug#55212).
* src/sort.c (nan_compare): To compare NaNs, simply printf+strcmp.
This avoids the problem of padding bits and unspecified behavior.
Args are now long double instead of char *; caller changed.
Paul Eggert [Tue, 19 Apr 2022 23:13:55 +0000 (16:13 -0700)]
pr: don’t use uninitialized var
Found with -flto and --enable-gcc-warnings.
* src/pr.c (getoptarg): Fix misuse of xstrtol, which does not
necessarily set tmp_long on errror, and does not set errno in any
reliable way. The previous code might access uninitialized
storage; on typical platforms this merely causes it to possibly
print the wrong diagnostic.
Paul Eggert [Tue, 19 Apr 2022 20:38:17 +0000 (13:38 -0700)]
doc: fix ' and ` in PDF output of code
* doc/coreutils.texi: Set txicodequoteundirected and
txicodequotebacktick so that ' and ` in code examples appear
as-is, rather than being transliterated to ’ and ‘. E.g., prefer
“... this is equivalent to ‘tr '\303\266' '\305\201'’ and ...” to
“... this is equivalent to ‘tr ’\303\266’ ’\305\201’’ and ...”
in PDF output.
Paul Eggert [Tue, 19 Apr 2022 20:24:42 +0000 (13:24 -0700)]
doc: prefer ö to $'\u7530'
* doc/coreutils.texi (Character arrays): Avoid using shell
notation like $'\u7530' since this isn’t in POSIX yet. Instead,
use ö and Ł which should work in all texinfo output formats.
This option has changed from ignoring only ENOTEMPTY|EEXIST
(i.e. ignore errors _solely_ due to dir not empty),
to ignoring some other errors from more protected dirs
that are not empty. That adjustment was made to better
support use with --parents, to essentially remove as much of
a hierarchy as possible, without erroring as we hit more
protected non empty parent dirs.
That functionality adjustment was originally discussed at:
https://lists.gnu.org/r/bug-coreutils/2008-01/msg00283.html
* src/rmdir.c (usage): Adjust to be more accurate to current behavior.
Also adjust --parents option to be easier to read.
* doc/coreutils.texi (rmdir invocation): Likewise.
Reported at https://github.com/coreutils/coreutils/issues/40
Avoid "Unicode character U+#1 not supported, sorry" error
when converting from texi to dvi or pdf.
* doc/coreutils.texi (tr invocation): Avoid the @U{XXXX}
texi representation, as even though info and html can represent
these characters directly, there are conversion errors
for pdf and dvi. Instead use the more abstract shell
$'\uXXXX' representation.
* src/tail.c (check_output_alive): Use poll() on Solaris.
Also handle POLLHUP, which Solaris returns in this case.
* tests/tail-2/pipe-f.sh: Use `head -n2` rather than `sed 2q`
as Solaris sed does not exit in this case.
* NEWS: Mention the improvement.
Reported by Bruno Haible.
Paul Eggert [Wed, 13 Apr 2022 06:56:41 +0000 (23:56 -0700)]
cp,mv,install: improve EACCES targetdir messages
This improves on the fix for --target-directory diagnostics bugs on
Solaris 11. Problem reported by Bruno Haible and Pádraig Brady; see:
https://lists.gnu.org/r/coreutils/2022-04/msg00044.html
Also, omit some unnecessary stat calls.
* gl/lib/targetdir.c (target_directory_operand): If !O_DIRECTORY,
do not bother calling open if stat failed with errno != EOVERFLOW.
Rename is_a_dir to try_to_open since that’s closer to what it means.
If the open failed with EACCES and we used O_SEARCH, look at stat
results to see whether errno should be ENOTDIR for better diagnostics.
Treat EOVERFLOW as an “I don’t know whether it’s a directory and
there’s no easy way to find out” rather than as an error.
Paul Eggert [Wed, 13 Apr 2022 06:56:41 +0000 (23:56 -0700)]
cp,mv,install: avoid excess stat calls on non-GNU
* gl/lib/targetdir.c (target_directory_operand): New arg ST.
All callers changed.
* src/cp.c (do_copy):
* src/mv.c (main):
Avoid unnecessary stat call if target_directory_operand already
got the status.
Paul Eggert [Wed, 13 Apr 2022 06:56:41 +0000 (23:56 -0700)]
cp,mv,install: modularize targetdir
Move target directory code out of system.h to a new targetdir module.
This doesn’t change functionality.
* bootstrap.conf (gnulib_modules): Add targetdir.
* src/cp.c, src/install.c, src/mv.c: Include targetdir.h.
* src/system.h (must_be_working_directory, target_directory_operand)
(targetdir_dirfd_valid): Move from here ...
* gl/lib/targetdir.c, gl/lib/targetdir.h, gl/modules/targetdir:
... to these new files.
cp,mv,install: avoid EACCES with non directory destination
* src/system.h (target_directory_operand): Also check with stat()
on systems with O_SEARCH, to avoid open("file", O_SEARCH|O_DIRECTORY)
returning EACCES rather than ENOTDIR, which was seen on Solaris 11.4
when operating on non dirs without execute bit set.
* NEWS: Remove related bug entry, as that issue was only introduced
after coreutils v9.0 was released.
Reported by Bruno Haible.
* tests/misc/env.sh: Verify with another command that
execvp() doesn not return ENOENT, before testing the
exit code from the command in question.
* tests/misc/nice-fail.sh: Likewise.
* tests/misc/stdbuf.sh: Likewise.
* tests/misc/timeout-parameters.sh: Likewise.
* tests/misc/md5sum-newline.pl: Avoid binary '*' tags when
comparing checksums.
* tests/misc/md5sum-bsd.sh: Avoid binary '*' tags so that we correctly
trigger the ambiguity test.
Reported by Bruno Haible
tests: dircolors.pl: avoid false failure with TERM=dumb
* tests/Coreutils.pm: Ensure an unset $TERM env var,
which is required on perl 5.22.2 on Solaris 11 OpenIndiana at least,
where TERM was being reset to 'dumb'.
Reported By Bruno Haible.
cp,mv,install: avoid opening non directory destination
commit v9.0-66-ge2daa8f79 introduced an issue, for example
where cp could hang when overwriting a destination fifo,
when it would try to open() the fifo on systems
like Solaris 10 that didn't support the O_DIRECTORY flag.
This is still racy on such systems, but only in the
case where a directory is replaced by a fifo in
the small window between stat() and open().
* src/system.h (target_directory_operand): On systems without
O_DIRECTORY, ensure the file is a directory before attempting to open().
* tests/cp/special-f.sh: Protect cp with timeout(1),
as cp was seen to hang when trying to overwrite an existing fifo.
* NEWS: Mention the bug fix.
* doc/coreutils.texi (install invocation): For the --compare option,
clarify that the ownership or permissions of the source files don't
matter. Also don't imply --owner or --group need to be specified
for --compare to be effective.
* src/install.c (usage): Add more detail on what's being compared.
Fixes https://bugs.gnu.org/50889