Pádraig Brady [Sat, 31 Dec 2022 17:03:39 +0000 (17:03 +0000)]
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
Pádraig Brady [Fri, 30 Dec 2022 19:34:27 +0000 (19:34 +0000)]
copy: attempt copy offload with sparse files by default
This was seen to vastly improve performance
on NFS 4.2 systems by allowing server side copies,
with partially sparse files (avidemux generated mp4 files).
* src/copy.c (lseek_copy): Also set hole_size to 0,
i.e. enable copy_file_range(), with --sparse=auto (the default),
to enable copy offload in this case, as we've strong signal
from SEEK_DATA that we're operating on actual data and not holes here.
* NEWS: Mention the improvement.
Fixes https://bugs.gnu.org/60416
Pádraig Brady [Wed, 28 Dec 2022 14:04:19 +0000 (14:04 +0000)]
wc: fix regression determining file size
* src/wc.c (wc): Use off_t rather than size_t
when calculating where to seek to, so that
we don't seek to a too low offset on systems
where size_t < off_t, which would result in
many read() calls to determine the file size.
* tests/misc/wc-proc.sh: Add a test case
sufficient for 32 bit systems at least.
* NEWS: Mention the bug fix.
Reported at https://bugs.debian.org/1027101
Paul Eggert [Mon, 26 Dec 2022 17:01:37 +0000 (09:01 -0800)]
tests: accommodate bogomips capitalizations
* tests/cp/proc-short-read.sh: Kernel on ARMv7 Processor rev 3 (v7l)
spells it "BogoMIPS", so allow any capitalization. Patch from
Zach van Rijn in <https://bugs.gnu.org/60339>.
Paul Eggert [Tue, 15 Nov 2022 18:55:23 +0000 (10:55 -0800)]
doc: more dash fixes
* doc/coreutils.texi, doc/sort-version.texi: Prefer on "x -- y" to
"x---y" in prose, as the result is more readable in Emacs.
Fix some instances of unescaped ‘-’ that should be minus, not
hyphen. Fix some other instances that should be en dash. No
spaces around en dash when it’s a range.
Pádraig Brady [Tue, 15 Nov 2022 11:54:58 +0000 (11:54 +0000)]
maint: avoid misquoting of some --long-options in texi
* cfg.mk (sc_texi_long_option_escaped): A new check to
avoid future instances of this.
* doc/coreutils.texi (Common options): Rearrange this menu
to be less repetitive in each description, and avoid long lines.
Addresses https://bugs.gnu.org/59262
Paul Eggert [Tue, 15 Nov 2022 03:08:19 +0000 (19:08 -0800)]
doc: fix markup
Problem reported by Antonio Diaz Diaz (bug#59262).
* doc/coreutils.texi: Use markup in menus to prevent
‘--’ from turning into an em dash, and to be more
consistent.
Pádraig Brady [Fri, 28 Oct 2022 13:40:28 +0000 (14:40 +0100)]
doc: printf: make "java" encoding example more standard
Note using iconv(1) rather than recode(1) is not appropriate
for this example, as the required functionality is only
available on libiconv's iconv implementation, which is
not installed on most systems.
* doc/coreutils.texi (printf invocation): Use env rather than
/usr/local/bin for the printf command. Escape '%' so more robust.
Also use a locale that exists on modern systems.
Pádraig Brady [Thu, 27 Oct 2022 14:17:07 +0000 (15:17 +0100)]
printf: with \U, support all valid unicode points
Previously this was restricted to the C99 universal character subset,
which restricted most values <= 0x9F, as that simplifies the C lexer.
However printf(1) doesn't need this restriction.
Note also the bash builtin printf already supports all values <= 0x9F.
* src/printf.c (main): Relax the restriction on points <= 0x9F.
* doc/coreutils.texi (printf invocation): Adjust description.
* tests/misc/printf-cov.pl: Adjust accordingly. Add new cases.
* NEWS: Mention the change in behavior.
Reported at https://bugs.debian.org/1022857
doc: sort: mention --version useful for IPv4 addresses
* doc/coreutils.texi (sort invocation): Mention in the
multi invocation sort example that the -V GNU extension
could be used to sort IPv4 addresses, and thus simplify
to a single invocation.
doc: be more consistent when documenting exit status
* src/system.h (emit_exec_status): A new function to
output standard "Exit status:" info for commands that exec others.
* doc/coreutils.texi (Exit status): Add "ls" and "runcon"
to the list of commands with non standard exit status.
* src/numfmt.c (main): Call initialize_exit_failure() explicitly
to better indicate this utility may exit with something other than
EXIT_FAILURE.
* src/timeout.c (usage): Use more consistent capitalization.
* src/chroot.c: Call emit_exec_status().
* src/env.c: Likewise.
* src/nice.c: Likewise.
* src/nohup.c: Likewise.
* src/runcon.c: Likewise.
* src/stdbuf.c: Likewise.
runcon: fix inconsistent exit status upon write error
* src/runcon.c (main): Call initialize_exit_failure(),
so we use an appropriate exit status upon failure to close stdout.
This should have been part of recent commit ea3ee6df.
* tests/misc/help-version.sh: Adjust test case accordingly.
* src/getlimits.c: Don't call initialize_exit_failure()
as it's not needed for standard EXIT_FAILURE returns.
Also use the function variant that diagnoses invalid options.
Pádraig Brady [Sat, 25 Jun 2022 23:27:06 +0000 (00:27 +0100)]
wc: add --total={auto,never,always,only} option
without this option, control of when the total is output
is quite awkward. Consider trying to suppress the total line,
which could be achieved with something like:
wc-no-total() { wc "$@" /dev/null | head -n-2; }
As well as being non obvious, it's also non general.
It would give a non failure, but zero count if passed a file on stdin.
Also it doesn't work in conjunction with the --files0-from option,
which would need to be handled differently with something like:
Also getting just the total can be awkward as file names
are only suppressed when processing stdin, and
also a total line is only printed if processing more than one file.
For completness this might be achieved currently with:
* src/wc.c: Add new --total option.
* tests/misc/wc-total.sh: New test suite for the new option.
* tests/local.mk: Reference the new test.
* doc/coreutils.texi (wc invocation): Document the new option.
* THANKS.in: Add suggestor.
* NEWS: Mention the new feature.
* .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).