Paul Eggert [Wed, 30 Aug 2023 14:15:09 +0000 (07:15 -0700)]
maint: use modern Gnulib LIB_ macros
* src/local.mk (src_timeout_LDADD, src_dd_LDADD)
(src_shred_LDADD, src_sync_LDADD): Use TIMER_TIME_LIB
and FDATASYNC_LIB instead of LIB_TIMER_TIME and
LIB_FDATASYNC.
Paul Eggert [Wed, 30 Aug 2023 13:51:18 +0000 (06:51 -0700)]
kill: rely on Gnulib strsignal
Omit checks no longer needed now that we use strsignal.
* configure.ac: Do not check for strsignal-related decls.
* src/kill.c (sys_siglist, strsignal): Remove.
Paul Eggert [Wed, 30 Aug 2023 06:52:07 +0000 (23:52 -0700)]
maint: remove need for mbsalign
This simplifies memory allocation a bit, and removes an arbitrary
limitation from numfmt, which formerly limited cell output to 127
bytes.
* bootstrap.conf (gnulib_modules): Remove mbsalign, strncat.
Add strnlen (the code already used strnlen directly, and we were
saved only because Gnulib used the module indirectly)
* gl/lib/mbsalign.c, gl/lib/mbsalign.h, gl/modules/mbsalign:
* gl/modules/mbsalign-tests, gl/tests/test-mbsalign.c: Remove.
* src/df.c, src/ls.c: Do not include mbsalign.h.
(MBSWIDTH_FLAGS): New constant, now used for all
mbswidth calls. All callers changed to check for -1 return.
* src/df.c (struct field_data_t): ‘width’ is now int not size_t,
since mbswidth can’t do widths greater than INT_MAX anyway.
Replace ‘align’ with ‘align_right’. All uses changed.
(print_table): Redo to avoid the need for ambsalign.
(get_header, get_dev): mbswidth returns int, not size_t.
* src/ls.c (MAX_MON_WIDTH): Remove; no longer used.
(abmon_init): Use strnlen to cheaply discard too-long month names.
Align by hand instead of using mbsalign.
* src/numfmt.c: Include stdckdint.h, mbswidth.h.
Do not include mbsalign.h.
(padding_buffer_size): Now idx_t. All uses changed.
(padding_width): Now intmax_t, since it’s no longer an object
size. Its sign now records alignment. All uses changed.
(zero_padding_width): Now int, since it’s given to sprintf.
All uses changed.
(padding_alignment): Remove; it’s now taken from padding_width’s sign.
(double_to_human): Return string length. BUF_SIZE arg is now idx_t.
Include suffix in output. All callers changed. Simplify by not
calling strncat or stpcpy. Calculate fmt size bound more carefully.
(setup_padding_buffer): Remove. All uses removed.
(parse_format_string): Use intmax_t, not long, for pad.
On overflow, set widths to large values that cause later code
to do the right thing, rather than separately checking for
overflow here.
(prepare_padded_number): Return bool, not int 0/1. New arg
PADDING. All uses changed. Do not limit padded output to 127
bytes; instead, use xpalloc to expand the output buffer.
(print_padded_number): New arg PADDING. All uses changed.
(process_suffixed_number): Simplify.
(main): Take extremum if xstrtoimax overflows, as this does
the right thing.
* tests/misc/numfmt.pl: New test suf-20 to test for truncation bug.
Remove tests pad-3.2, fmt-err-7, as they’re no longer invalid but
are quite expensive.
Paul Eggert [Mon, 28 Aug 2023 19:42:23 +0000 (12:42 -0700)]
maint: spelling fixes, including author names
Most of this just affects commentary and documentations. The only
significant behavior change is translating author names via
proper_name_lite rather than proper_name_utf8, or not translating
them at all. proper_name_lite is good enough for coreutils and
avoids the bloat that had coreutils not using Gnulib proper_name.
* bootstrap.conf (gnulib_modules): Use propername-lite instead
of propername.
(XGETTEXT_OPTIONS): Look for proper_name_lite instead of for
proper_name_utf8.
* cfg.mk (local-checks-to-skip): Remove
sc_proper_name_utf8_requires_ICONV, since we no longer use
proper_name_utf8.
(old_NEWS_hash): Update.
(sc_check-I18N-AUTHORS): Remove; no longer needed.
Paul Eggert [Mon, 28 Aug 2023 02:13:42 +0000 (19:13 -0700)]
sort: port sort-continue test back to Solaris 10
* tests/sort/sort-continue.sh: Use ulimit -n 7 not -n 6. On
Solaris 10 'sort' uses Gnulib mkostemp, which calls Gnulib
getrandom, which opens /dev/urandom to calculate the temp file's
name, which means 'sort' needs one more file descriptor to work.
Pádraig Brady [Sun, 27 Aug 2023 19:22:32 +0000 (20:22 +0100)]
tests: avoid false failure on cygwin
* tests/cksum/md5sum-bsd.sh: Avoid part of test dealing with backslashes
in file names, on systems where backslash is a directory separator.
Issue reported by Bruno Haible on cygwin.
Pádraig Brady [Sun, 27 Aug 2023 18:52:13 +0000 (19:52 +0100)]
cksum: adjust tests and docs to binary mode handling
Following commit v9.3-80-g5e1e0993b which makes cksum
match the output of the standalone utilities...
* doc/coreutils.texi (cksum output modes): Remove the mention
that cksum never outputs a binary indicator, as that's no longer the
case.
* tests/cksum/b2sum.sh: Avoid outputting a binary indicator.
* tests/cksum/sm3sum.pl: Likewise.
Pádraig Brady [Sun, 27 Aug 2023 15:01:27 +0000 (16:01 +0100)]
all: avoid duplicated write errors on FreeBSD
* src/system.h (write_error): Also call fpurge(), which was seen to
be needed on FreeBSD 13.1 to avoid duplicated write errors.
* src/head.c (xwrite_stdout): Likewise.
* bootstrap.conf: Depend on fpurge.
Reported by Bruno Haible.
Pádraig Brady [Mon, 21 Aug 2023 13:51:49 +0000 (14:51 +0100)]
doc: reorg texinfo for the checksumming utilities
* doc/coreutils.texi: Reorg so that 'cksum invocation' is the
main node listing all options and output formats, which is then
referenced by the descriptions of the standalone utilities.
Use macros in the description of the standalone utilities
rather than referencing 'md5sum invocation' to be more direct.
Pádraig Brady [Mon, 21 Aug 2023 12:39:14 +0000 (13:39 +0100)]
cp: with --sparse=never, avoid COW and copy offload
* src/cp.c (main): Set default reflink mode appropriately
with --sparse=never.
* src/copy.c (infer_scantype): Add a comment to related code.
* tests/cp/sparse-2.sh: Add a test case.
* NEWS: Mention the bug.
Pádraig Brady [Tue, 15 Aug 2023 15:44:26 +0000 (16:44 +0100)]
tests: fix false failure due to locale on alpine
* tests/sort/sort-debug-keys.sh: Decimal point was seen to be '.'
on fr_FR.UTF-8 on Alpine Linux 3.18, so add an extra guard
to ensure we've a ',' as the decimal point on this locale.
Fixes https://bugs.gnu.org/65310
Paul Eggert [Tue, 15 Aug 2023 21:00:54 +0000 (14:00 -0700)]
uptime: be more generous about read_utmp failure
* src/uptime.c (print_uptime): Check for overflow
when computing uptime. Use C99-style decl after statements.
Do not let an idx_t value go negative.
(print_uptime, uptime): Be more generous about read_utmp failures,
or when read_utmp does not report the boot time. Instead of
failing, warn but keep going, printing the information that we did
get, and then exit with nonzero status.
(print_uptime): Return the desired exit status. Caller changed.
Bruno Haible [Tue, 15 Aug 2023 19:01:13 +0000 (12:01 -0700)]
uptime: Include VM sleep time in the "up" duration
* src/uptime.c: Don't include c-strtod.h.
(print_uptime): Don't read /proc/uptime, because the value it provides
does not change when a date adjustment occurs.
* bootstrap.conf (gnulib_modules): Remove 'uptime'.
Pádraig Brady [Sat, 12 Aug 2023 10:21:50 +0000 (11:21 +0100)]
maint: allow use of printf C99 integer size specifiers
Older systems that had issues with these like HP-UX and Solaris 8
are now obsolete, and can easily apply patches to provide support.
Also we've used %td since coreutils 9.1, with no reported issues.
* cfg.mk (sc_prohibit-c99-printf-format): Remove to allow use of
%[jtz] size specifiers, which allows for cleaner code
by avoiding the need to cast to PRI?MAX etc.
Pádraig Brady [Fri, 11 Aug 2023 13:27:59 +0000 (14:27 +0100)]
doc: separate out description of 2038 time stamp change
* NEWS: Separate out the description of the _existing_ issues
with outputting timestamps on 32 bit systems, from _future_ issues
outputting timestamps on all systems. Also move this to the
"improvement" section, since it's not really a coreutils
specific issue, and also is a build time configurable option.
Paul Eggert [Fri, 4 Aug 2023 01:35:29 +0000 (18:35 -0700)]
maint: Update after gnulib module 'readutmp' changed
(This patch is coauthored with Bruno Haible,
with original version at <https://bugs.gnu.org/64937#>.)
This updates the gnulib submodule to latest.
For year-2038 safety on Linux/{x86,arm},
this adds an --enable-systemd option to ‘configure’.
The idea is that this sort of thing will become the default
after it has been tested more.
* configure.ac: Don't test whether struct utmp and struct utmpx
have the ut_host field; this is now done in gnulib's readutmp module.
* src/local.mk: Link the programs 'pinky', 'uptime', 'users',
'who' with $(READUTMP_LIB).
* src/pinky.c, src/who.c:
Test HAVE_STRUCT_XTMP_UT_HOST instead of HAVE_UT_HOST.
* src/pinky.c (print_entry):
* src/who.c (print_user, print_deadprocs, print_login)
(print_initspawn, scan_entries):
Support the situation where ut_line is a 'char *' rather than a
'char[]' of fixed size. Likewise for ut_user and ut_host.
(make_id_equals_comment): Likewise for ut_id.
* src/pinky.c (print_entry):
* src/who.c (print_user):
Open /dev to simplify looking up its entries.
Don’t use printf if the output might in theory be longer than INT_MAX.
* src/pinky.c (scan_entries, short_pinky):
* src/uptime.c (print_uptime, uptime):
* src/users.c (list_entries_users, users):
* src/who.c (who):
Use idx_t where new read_utmp needs it.
* src/system.h (STREQ_LEN): Add comment that last arg can be -1.
Paul Eggert [Wed, 2 Aug 2023 13:51:55 +0000 (06:51 -0700)]
uptime: fix Y5881633 bug
* src/uptime.c (print_uptime): Prefer signed types.
Fix unlikely bug on platforms with 32-bit long and 64-bit time_t
if the idle time exceeds 2**31 days (about 6 million years...).
Dragan Simic [Tue, 1 Aug 2023 09:07:41 +0000 (11:07 +0200)]
cut: promptly diagnose write errors, continued
* src/cut.c: Complete the error-handling improvements started in
commit e0a4a60af5, by adding a couple of remaining checks for putchar().
While there, sprinkle a few rather useful comments, and perform a few
small code cleanups, to make the code and the comments more uniform
and more conformant to the official coding style. Also make the help
message slightly more uniform.
Pádraig Brady [Tue, 1 Aug 2023 12:30:02 +0000 (13:30 +0100)]
od: fix issues with recent format string changes
* src/ioblksize.h: Avoid syntax check with redundant idx.h inclusion.
* src/od.c (FMT_BYTES_ALLOCATED): Increase by two to avoid:
error: '%s' directive writing between 1 and 2 bytes into a region
of size between 1 and 4 [-Werror=format-overflow=]
(maint): Use %td to print idx_t rather than invalid %jt format.
Paul Eggert [Tue, 1 Aug 2023 00:51:03 +0000 (17:51 -0700)]
pinky: prefer signed types
* src/pinky.c (idle_string): Prefer intmax_t to unsigned long int;
this avoids an overflow on platforms where unsigned long is 32
bits and time_t is 64 bits (the bug could occur on such a system
that was idle for more than 6 million years, so it’s a bit
hard to supply a test case...).
Paul Eggert [Tue, 1 Aug 2023 00:46:15 +0000 (17:46 -0700)]
numfmt: prefer signed types
* src/numfmt.c (suffix_power_char, powerld, expld)
(simple_strtod_int, double_to_human, prepare_padded_number)
(process_suffixed_number): Prefer signed types.
(process_suffixed_number): Fix an unlikely bug if an
arg has exactly 2**32 spaces at the start.
Paul Eggert [Mon, 31 Jul 2023 23:38:02 +0000 (16:38 -0700)]
kill: prefer signed types
* src/kill.c (list_signals):
Prefer signed types. This avoids undefined behavior on
theoretical platforms where unsigned and signed int have
different representations.
Paul Eggert [Mon, 31 Jul 2023 23:33:38 +0000 (16:33 -0700)]
od: prefer signed types
* src/od.c: Include stdckdint.h.
(bytes_to_oct_digits, bytes_to_signed_dec_digits)
(bytes_to_unsigned_dec_digits, bytes_to_hex_digits):
Use ‘char’ for these small constants.
(simple_strtoi): Rename from simple_strtoul. Convert to int
instead of unsigned long; that’s good enough. All uses changed.
Simplify by using ckd_mul and ckd_add to check for overflow.
(main): Prefer signed types to unsigned.
Paul Eggert [Mon, 31 Jul 2023 23:30:24 +0000 (16:30 -0700)]
cksum,df,digest: prefer signed types
* src/cksum.c (main):
* src/df.c (decode_output_arg):
* src/digest.c (valid_digits):
Prefer idx_t to unsigned types when the value is an index
into an array.
Paul Eggert [Mon, 31 Jul 2023 20:43:19 +0000 (13:43 -0700)]
factor: prefer signed types
When it’s easy, prefer signed types to unsigned, as
they are less confusing and allow overflow checking.
* src/factor.c (struct mp_factors, udiv_qrnnd)
(count_leading_zeros, count_trailing_zeros)
(factor_insert_multiplicity, mp_factor_clear, mp_factor_insert)
(factor_insert_refind, factor_using_division)
(mp_factor_using_division, powm2, millerrabin, millerrabin2)
(mp_millerrabin, prime_p, prime2_p, mp_prime_p, isqrt, isqrt2)
(invtab, q_freq, factor_using_squfof, strto2uintmax)
(print_factors_single, main):
Prefer signed integers to unsigned.
Paul Eggert [Mon, 31 Jul 2023 18:21:25 +0000 (11:21 -0700)]
who: fix only-theoretical overflow
Change stzncpy’s implementation to match its comment, in the case
where SRC + LEN would overflow. This case never happens in coreutils.
* src/system.h (stzncpy): Work even if SRC + LEN would overflow.
Paul Eggert [Sat, 22 Jul 2023 20:39:17 +0000 (13:39 -0700)]
mv: better diagnostic for 'mv dir x' failure
Problem reported by Nir Oren <https://bugs.gnu.org/64785>.
* src/copy.c (copy_internal): Use a more-specific diagnostic when
a rename fails due to a problem that must be due to the
destination, avoiding user confusion in cases like 'mv dir x'
where x is a nonempty directory.
* tests/mv/dir2dir.sh: Adjust to match.
tail -n/-c +NUM, is different from tail -n/-c NUM,
and head -n/-c NUM, and head -n/c -NUM, in that it
specifies a 1 based index rather than a count to skip/include.
So clarify this in tail --help and tail info manual.
Note we also mention this gotcha at:
https://www.pixelbeat.org/docs/coreutils-gotchas.html#tail
* doc/coreutils.texi (tail invocation): Give examples for -c/-n +NUM,
to make it clear one has to specify a number 1 larger than
might be expected.
* src/tail.c (usage): State the skip at start edge case more clearly
in the -n description. -c is not often used with tail so we leave
full explanation of that to the info manual. Also split the string
to simplify translation.
* tests/split/l-chunk.sh: Move the "expensive" portion to ...
* tests/split/l-chunk-root.sh: .. A new test split from l-chunk.sh
which uses an isolated TMPDIR, rather than exhausting /tmp,
as that gives false positive failures with some other coreutils tests
like tac-2-nonseekable.sh and shuf-reservoir.sh at least.
* tests/local.mk: Reference the new test.
* bootstrap.conf: Depend on tmpdir rather than tmpfile,
as the standard tmpfile() doesn't honor $TMPDIR.
* src/split.c (copy_to_tmpfile): Adjust to call temp_stream() rather
than tmpfile();
* NEWS: Mention the improvement.
This also refactors temp_stream() to its own module,
in preparation for use by split.
* src/tac.c: Refactor temp_stream() out to ...
* src/temp-stream.c: ... A new module mostly refactored from tac,
but uses tmpdir to more robustly support $TMPDIR,
while falling back to /tmp if not available.
* src/temp-stream.h: The new module interface.
* src/local.mk: Reference the new module from tac.
* tests/tac/tac.pl: Adjust to non failing missing $TMPDIR.
* po/POTFILES.in: Reference the new module with translatable strings.
* NEWS: Mention the user visible improvements to tac TMPDIR handling.
* src/join.c (prjoin): Check for write errors after each line.
* tests/misc/write-errors.sh: enable the test for join.
* NEWS: Mention the improvement.
* src/comm.c (writeline): Simplify by removing the unneeded STREAM
parameter. Call write_error() upon ferror().
(compare_files): Adjust to simplified writeline().
* tests/misc/write-errors.sh: Enable comm test.
* NEWS: Mention the improvement.
* src/cut.c (cut_bytes): Diagnose errors from fwrite() and putchar().
(cut_fields): Likewise.
* tests/misc/write-errors.sh: Enable the test for cut,
and augment to cover both cut_bytes() and cut_fields().
* NEWS: Mention the improvement.
* src/uniq.c (write_line): Check the output from fwrite() immediately.
(check_file): Likewise.
* tests/misc/write-errors.sh: Enable the test case.
* NEWS: Mention the improvement.
* src/od.c (dump): Check for write errors after each block written,
to exit early even with large / unbounded inputs.
* tests/misc/write-errors.sh: enable od check.
* NEWS: Mention the improvement.
Fixes https://bugs.gnu.org/64540
* cfg.mk (sc_some_programs_must_avoid_exit_failure): Adjust to
avoid false positive.
(sc_prohibit_exit_write_error): A new syntax check to prohibit
open coding error(..., "write error"); instead directing to use...
* src/system.h (write_error): ... a new function to clear stdout errors
before we explicitly diagnose a write error and exit.
* src/basenc.c: Use write_error() to ensure no repeated diagnostics.
* src/cat.c: Likewise.
* src/expand.c: Likewise.
* src/factor.c: Likewise.
* src/paste.c: Likewise.
* src/seq.c: Likewise.
* src/shuf.c: Likewise.
* src/split.c: Likewise.
* src/tail.c: Likewise.
* src/tr.c: Likewise.
* src/unexpand.c: Likewise.
* tests/misc/write-errors.sh: Remove TODOs for the fixed utilities:
expand, factor, paste, shuf, tr, unexpand.
* src/digest.c (problematic_chars): This recently introduced
function does not modify state so is pure, even though GCC 13.1 at least
did not warn about that attribute being appropriate.
cksum: escape filenames with a leading '\' in --check status
* src/digest.c (digest_check): Also escape in the case that the
file name contains '\'.
* tests/cksum/md5sum-bsd.sh: Add a test case.
* doc/coreutils.texi (md5um invocation): Clarify escaping operation.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/64392
cksum: support transparent emulation of older utils
Support -b, --binary, and -t, --text
to allow full emulation of older utilities with:
exec cksum -a $algo --untagged "$@"
Note this would diverge from OpenBSD's support of cksum -b.
* src/digest.c: Change -b to mean --binary, not --base64 in all cases.
Accept -b and -t in all cases. Keep --binary and --text undocumented
for cksum.
* tests/cksum/cksum-base64.pl: s/-b/--base64/.
* tests/cksum/cksum-a.sh: Ensure cksum supports -b and -t appropriately.
* NEWS: Mention the change in behavior.
Paul Eggert [Sat, 1 Jul 2023 18:31:41 +0000 (11:31 -0700)]
maint: prefer ckd_add to INT_ADD_WRAPV etc
* bootstrap.conf (gnulib_modules): Add stdckdint.
Also, in C source code, prefer C23 macros like ckd_add
to their Gnulib near-equivalents like INT_ADD_WRAPV.
Include <stdckdint.h> as needed.
Paul Eggert [Sat, 1 Jul 2023 18:31:41 +0000 (11:31 -0700)]
who: don’t crash if clock gyrates
* src/who.c (idle_string): Avoid signed integer overflow
if the superuser messes with the clock in bizarre ways.
Remove an ‘assume’ that wasn’t correct under this scenario.
Paul Eggert [Sat, 1 Jul 2023 18:31:40 +0000 (11:31 -0700)]
maint: pacify GCC bug#109613 better
* src/cut.c (cut_file):
* src/nl.c (nl_file): Pacify GCC Bug#109613 in a better way, by
narrowing the coverage of the ‘assume’ so that bugs in the
no-longer-covered part are not masked.