Commit Graph
9314 Commits
Author SHA1 Message Date
Collin Funk b1ba0f3843 maint: groups: reduce variable scope
* src/groups.c (main): Declare variables where they are used instead of
at the start of the function. Convert a comment to GNU style.
2025-12-10 18:50:53 -08:00
Collin Funk ae1dcbdbc6 maint: printenv: reduce variable scope
* src/printenv.c (main): Declare variables where they are used instead
of at the start of the function. Constify some strings we do not modify.
2025-12-10 18:50:53 -08:00
Collin Funk bdb276a0c5 maint: rmdir: reduce variable scope
* src/rmdir.c (remove_parents, main): Declare variables where they are
used instead of at the start of a block.
2025-12-10 18:50:53 -08:00
Collin Funk 553c33ba6a maint: date: reduce variable scope
* src/date.c (batch_convert, main): Declare variables where they are
used instead of at the start of the function.
2025-12-10 18:50:53 -08:00
Collin Funk 684ec5b8ad maint: install: reduce variable scope
* src/install.c (change_timestamps): Initialize variables where they are
declared.
(need_copy, setdefaultfilecon, get_ids, mkancesdirs_safe_wd, main):
Declare variables where they are used instead of at the start of the
block.
2025-12-10 18:50:53 -08:00
Collin Funk 55aa5afbaf maint: cp: reduce variable scope
* src/cp.c (re_protect): Initialize variables where they are declared.
(make_dir_parents_private, do_copy, main): Declare variables where they
are used instead of at the start of the block.
2025-12-10 18:50:53 -08:00
Collin Funk 71250b2772 maint: mv: reduce variable scope
* src/mv.c (do_move, main): Declare variables where they are used
instead of at the start of a block.
2025-12-10 18:50:53 -08:00
Collin Funk cc3cb220c3 maint: env: reduce variable scope
* src/env.c (extract_varname, parse_signal_action_params)
(parse_block_signal_params, set_signal_proc_mask)
(list_signal_handling, main): Declare variables where they are used
instead of at the start of the function.
2025-12-07 15:48:15 -08:00
Collin Funk 5af9ffed32 maint: nohup: reduce variable scope
* src/nohup.c (main): Declare variables where they are used instead of
at the start of the function.
2025-12-07 15:47:24 -08:00
Collin Funk d213c625ac maint: sync: reduce variable scope
* src/sync.c (sync_arg, main): Declare variables where they are used
instead of at the start of the function.
2025-12-07 15:35:48 -08:00
Collin Funk 881ac237be maint: pwd: reduce variable scope
* src/pwd.c (find_dir_entry, robust_getcwd): Declare variables where
they are used.
(logical_getcwd, main): Likewise. Constify the result of getenv, since
the result cannot be modified.
2025-12-07 15:35:16 -08:00
Collin Funk 8af2d813b9 maint: dirname: reduce variable scope
* src/dirname.c (main): Declare variables where they are used instead of
at the start of the function. Prefer idx_t to size_t.
2025-12-07 15:17:21 -08:00
Collin Funk 2880332ada maint: hostid: reduce variable scope
* src/hostid.c (main): Declare variables where they are used instead of
at the start of the function.
2025-12-07 15:11:55 -08:00
Collin Funk dd2a113f5f maint: nproc: reduce variable scope
* src/nproc.c (main): Declare variables where they are used instead of
at the start of the function.
2025-12-07 15:06:24 -08:00
Collin Funk b8abde0fe4 maint: whoami: reduce variable scope
* src/whoami.c (main): Declare variables where they are used instead of
at the start of the function.
2025-12-07 15:03:00 -08:00
Collin Funk efd9a48ca5 maint: logname: reduce variable scope
* src/logname.c (main): Declare variables where they are used instead of
at the start of the function.
2025-12-07 14:59:19 -08:00
Collin Funk 597dfa0d31 maint: basename: initialize values while declaring
* src/basename.c (remove_suffix): Initialize values on the same line as
their declarations.
2025-12-07 14:56:23 -08:00
Collin Funk c3eb8b4579 shred: use gethrxtime instead of time
The gethrxtime function uses a monotonic clock if available on the
system. The effect should be unnoticeable since we print --verbose
information every 5 seconds, but is more correct and we already do the
same in 'dd'.

* src/local.mk (src_shred_LDADD): Add $(GETHRXTIME_LIB).
* src/shred.c (dopass): Use xtime_t instead of time_t. Use gethrxtime
instead of time.
2025-12-07 11:37:17 -08:00
Collin Funk 3c405ae0b6 pinky: promptly diagnose write errors
In some cases 'pinky' could run forever until interrupted:

    $ ln -s /dev/zero ~/.plan
    $ ln -s /dev/zero ~/.project
    $ timeout -v 5 pinky -l collin > /dev/full
    timeout: sending signal TERM to command ‘pinky’

After this change it will exit upon failing to write to standard output:

    $ timeout -v 5 ./src/pinky -l collin > /dev/full
    pinky: write error: No space left on device

* src/pinky.c: Include fadvise.h, filenamecat.h, full-write.h, and
ioblksize.h.
(cat_file): New function.
(print_entry): Check if standard output has it's error flag set after
printing a user entry.
(print_long_entry): Likewise. Use the new cat_file function.
* NEWS: Mention the improvement.
2025-12-05 15:42:16 -08:00
Paul Eggert 2a21ecb16f build: update gnulib submodule to latest
Gnulib issymlinkat change reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2025-12/msg00044.html
* bootstrap: Update from Gnulib.
* src/copy.c: Include issymlinkat.h, not issymlink.h.
2025-12-04 12:45:02 -08:00
Collin Funk f23509b4f1 maint: don't use == on bools
* src/df.c (filter_mount_list): Adjust comment.
* src/sync.c (sync_arg): Don't use == on bools.
* src/pr.c (init_parameters): Likewise.
2025-12-02 20:24:16 -08:00
Collin Funk c00a094188 timeout: print the signal number 0 instead of EXIT
POSIX.1-2024 added sig2str but leaves the behavior when called with
signal 0 unspecified. FreeBSD 15.0 does not return the signal name EXIT
like Gnulib's version causing a test failure. This fixes that and
changes the behavior to print 0 instead of EXIT, to avoid confusion when
the program does not exit.

* NEWS: Mention the change.
* src/timeout.c (cleanup): Use snprintf instead of sig2str if the signal
is 0.
* tests/timeout/timeout.sh: Updated the expected output.
2025-12-02 19:16:23 -08:00
Pádraig Brady 86061ddbbd timeout: prioritize "timed out" exit status
* src/timeout.c (cleanup): Reset the default exit status
to EXIT_TIMEDOUT, if we have in fact received an ALARM.
Otherwise we would exit with status EXIT_CANCELED if
there was an issue writing --verbose output for example.
This also ensures a consistent exit status with ASAN enabled,
as with ASAN stderr is not explicitly closed by gnulib's
close_stdout handler.
2025-12-02 17:20:19 +00:00
Pádraig Brady fc5c7b2e47 timeout: ensure we terminate command upon abnormal exit
* src/timeout.c (main): Use PR_SET_PDEATHSIG to ensure the
child is terminated even if the parent terminates abnormally.
* tests/timeout/timeout-group.sh: Add a case to ensure sending
SIGKILL results in the termination of the monitored command.
* NEWS: Mention the improvement.
2025-11-29 12:17:27 +00:00
Collin Funk 90856dd867 du: add the short option -A corresponding to --apparent-size
The --apparent-size option to 'du' was added in
coreutils-4.5.8 (2003). FreeBSD 8.0 (2009) added the same functionality
under the short option -A. This long option previously had no short
option, so this patch adds -A to be compatible with FreeBSD.

* NEWS: Mention the new short option.
* doc/coreutils.texi: Document the short option.
* src/du.c (usage): Likewise.
(APPARENT_SIZE_OPTION): Remove definition.
(EXCLUDE_OPTION): Define to CHAR_MAX + 1.
(long_options): Use the -A short option for --apparent-size.
(main): Likewise.
* tests/du/apparent.sh: Test that '-b', '-A -B 1', and
'--apparent-size --block-size 1' function the same.
2025-11-28 14:08:31 -08:00
Collin Funk 8083efff09 maint: prefer mcel_eq to mcel_cmp
* gnulib: Update submodule to latest.
* bootstrap: Run ./bootstrap --bootstrap-sync
* src/expr.c (mbs_logical_cspn): Use mcel_eq instead of mcel_cmp.
* src/join.c (eq_tab, main): Likewise.
2025-11-27 12:16:59 -08:00
Collin Funk 194176cddb doc: date: mention --file=- reads from standard input
* src/date.c (usage): Mention that standard input will be read if
DATEFILE is "-".
Reported at https://bugs.debian.org/1100395
2025-11-26 19:31:11 -08:00
Collin Funk 5763d56e69 doc: du, sort, wc: adjust description of --files0-from
* src/du.c (usage): Remove an unnecessary "then".
* src/wc.c (usage): Likewise. Add a comma after "-".
* src/sort.c (usage): Likewise. Adjust the indentation to match du and
wc.
2025-11-26 19:30:41 -08:00
Pádraig Brady dc0f069ddd doc: fold: clarify operation of -s in --help
* src/fold.c (usage): The description of -s was unclear:
- State that we can also break within words.
- State that we split on blanks not spaces.
- State that we split after the blank, not before.
2025-11-26 09:32:27 +00:00
Paul Eggert 2199c9003e du,ls: don’t modify getenv strings
Fix du and ls to conform to the POSIX getenv spec,
which says you can’t modify strings returned by getenv
unless you put the string there directly, or used putenv.
This portability bug was found by strict C23 checking
using qualifier-generic functions.
* bootstrap.conf (gnulib_modules): Add xmemdup0.  Sort.
* src/du.c (main):
* src/ls.c (decode_switches):
Don’t modify the string that getenv returns.
Instead, use xmemdup0 if needed, and include xmemdup0.h.
2025-11-23 12:00:09 -08:00
Paul Eggert eade022f24 numfmt: port to C23 qualifier-generic fns
* src/numfmt.c (mbsmbchr): Cast results of qualifier-generic functions
to char *, to port to strict C23.
2025-11-23 12:00:09 -08:00
Paul Eggert 772f240b6b cat: refactor struct stat usage
* src/cat.c (main): Simplify by keeping input and output
struct stat in separate local vars.
2025-11-23 12:00:09 -08:00
Pádraig Brady 6c323dce5b doc: cat -E: mention ^M$ output possibility
* src/cat.c (usage): Document the ^M$ combination
which is output for \r\n line endings.
Fixes https://github.com/coreutils/coreutils/issues/130
2025-11-23 12:16:32 +00:00
Pádraig Brady cf973e7f80 dd,ls,sort: prefer sigaction over signal
sigaction() is generally available and if not
provided by the sigaction gnulib module.

* src/dd.c [SA_NOCLDSTOP]: Delete workarounds.
* src/ls.c: Likewise.
* src/sort.c: Likewise.
Suggested by Collin Funk.
2025-11-22 14:08:20 +00:00
Pádraig Brady e63131b326 csplit,ls,sort: handle a more complete set of signals
* src/term-sig.h: A new file defining a TERM_SIG array signals.
* src/local.mk: Reference the new file.
* src/csplit.c: Likewise.
* src/sort.c: Likewise.
* src/timeout.c: Likewise.
* src/ls.c: Likewise.  Also handle SIGTSTP separately.
* NEWS: Mention the improvement.
2025-11-22 12:43:28 +00:00
Pádraig Brady 8c24619334 timeout: honor ignored signal dispositions
This behavior was depended on in our trap_sigpipe_or_skip_ helper,
and now that we're handling all terminating signals, we should
consistently honor their ignored signal dispositions.

* NEWS: Mention the change in behavior, especially in regard
to shell background jobs.
* src/timeout.c (sig_needs_handling): A new helper that return TRUE,
for --signal, SIG_ALRM, or non ignored signals.
(cleanup_install): Filter handled signals with the helper.
(block_cleanup_and_chld): Likewise.
* tests/timeout/timeout-group.sh: Adjust to use the now required
`env --default-signal=...` wrapper to reset (auto) ignored signals.
Also change the termination signal from SIGINT to SIGUSR1
to generalize the test signals not specially handled by the shell,
and newly handled by timeout(1).
* tests/timeout/timeout.sh: Add a test case for SIGPIPE
to ensure the ignored signal disposition is honored.
2025-11-22 08:49:20 +00:00
Pádraig Brady d0a51c614d timeout: handle all terminating signals
* src/timeout.c (term_sig): A new global list of all signals
whose default disposition is to terminate the process.
(install_cleanup): Iterate over the TERM_SIG list, rather than
installing the handler for a specific subset.
(block_cleanup_and_chld): Likewise.
* tests/timeout/timeout.sh: Add a test case for SIGPIPE.
* NEWS: Mention the bug fix.
2025-11-21 12:12:28 +00:00
Pádraig Brady 1d58e4ddab build: remove explicit link to CoreFoundation libs on macOS
* src/local.mk: No longer explicitly depend on @INTL_MACOS_LIBS@
as they're no longer implicitly referenced (in LIBINTL) without gettext.
The old dependency was through localename-unsafe, specifically
date, du through show-date() (fprintftime), and
ls, pr, stat, uptime through strftime().
gnulib commit v1.0-2439-gff4b084a68 removed the localename-unsafe
dependency on macOS.
2025-11-20 10:43:06 +00:00
Collin Funk c22d1a4861 maint: add coreutils_hardlinks to src/.gitignore
* src/.gitignore (coreutils_hardlinks): Ignore this file. It is an empty
file created when --enable-single-binary=hardlinks is used to ensure
hardlinks are created after the multicall binary.
2025-11-19 19:23:36 -08:00
Collin Funk 55a32194a9 maint: prefer MAYBE_UNUSED to void casts
* src/copy.c (clone_file, set_author): Use MAYBE_UNUSED in the prototype
instead of void casting the arguments.
2025-11-19 18:47:28 -08:00
Pádraig Brady 59d9f05ef7 build: support --enable-single-binary=hardlinks
* Makefile.am: Use ln rather than $(LN_S) for hardlinks.
* configure.ac: Accept --enable-single-binary=hardlinks.
* man/local.mk: In hardlink mode, explicitly add the
hardlink creation rule to mandeps.  Given the automake
generated dependency chain, this ensures that the hardlinks
are created _after_ the multicall binary, with `make all`
or `make check` etc.
* src/local.mk: Define the new src/coreutils_hardlinks rule,
and only depend on src/coreutils_{symlinks,shebangs} if
in those modes, so that hardlinks are created _after_
the multicall binary, and other link types before.
* NEWS: Mention the new feature.
Addresses https://github.com/coreutils/coreutils/issues/129
2025-11-19 14:38:27 +00:00
Collin Funk be22a57793 maint: use C99 initialization syntax for single-variable 'for' loops
* src/chroot.c (parse_additional_groups): Declare variable in the 'for'
clause.
* src/comm.c (compare_files): Likewise.
* src/cp.c (re_protect): Likewise.
* src/csplit.c (save_buffer, find_line, write_to_file)
(split_file, main): Likewise.
* src/dd.c (apply_translations, translate_buffer)
(copy_with_block, main): Likewise.
* src/df.c (selected_fstype, excluded_fstype, filter_mount_list)
(last_device_for_mount, get_device, get_point, get_all_entries)
(main): Likewise.
* src/fmt.c (copy_rest, get_prefix, fmt_paragraph, put_paragraph)
(put_word): Likewise.
* src/fold.c (main): Likewise.
* src/head.c (elide_tail_bytes_pipe, main): Likewise.
* src/install.c (main): Likewise.
* src/join.c (prfields, join, main): Likewise.
* src/kill.c (list_signals): Likewise.
* src/ls.c (main, decode_switches, parse_ls_color, patterns_match):
Likewise.
* src/operand2sig.c (operand2sig): Likewise.
* src/pathchk.c (no_leading_hyphen, validate_file_name): Likewise.
* src/pr.c (char_to_clump): Likewise.
* src/printenv.c (main): Likewise.
* src/ptx.c (initialize_regex, digest_break_file)
(find_occurs_in_text, print_field): Likewise.
* src/remove.c (mark_ancestor_dirs): Likewise.
* src/seq.c (print_numbers): Likewise.
* src/shred.c (do_wipefd, main): Likewise.
* src/sort.c (cleanup, inittables, key_warnings, mergefps)
(check_ordering_compatibility, main): Likewise.
* src/split.c (closeout): Likewise.
* src/stat.c (find_bind_mount, print_it, format_to_mask): Likewise.
* src/stdbuf.c (set_program_path): Likewise.
* src/stty.c (apply_settings, display_changed, display_all)
(recover_mode, sane_mode): Likewise.
* src/system.h (stzncpy): Likewise.
* src/tail.c (pipe_lines): Likewise.
* src/tee.c (tee_files): Likewise.
* src/tr.c (look_up_char_class, get_spec_stats): Likewise.
* src/users.c (list_entries_users): Likewise.
2025-11-17 19:10:40 -08:00
Pádraig Brady 386cc5e4a7 build: fix make dist failure
* src/local.mk: s/crc.h/cksum_crc.h/.
Reported by Bruno Haible.
2025-11-17 20:02:55 +00:00
Pádraig Brady d611bcbfff tail: add --debug to report the --follow implementation
* doc/coreutils.texi (tail invocation): Describe --debug.
* src/tail.c (tail_forever, tail_forever_inotify): Output
which --follow implementation is being used.
* tests/tail/debug.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the new feature.
2025-11-17 13:55:12 +00:00
Collin Funk 6cbb7f0dbb maint: convert remove a K&R declaration
This function is hidden unless EVAL_TRACE is defined for debugging.

* src/expr.c (trace): Convert to a prototype instead of K&R definition
to avoid -Werror=strict-prototypes. Make the argument const to avoid
-Werror=discarded-qualifiers.
2025-11-16 16:59:43 -08:00
Bernhard Voelker 9a970586c7 du: document the TIME_STYLE env variable in usage
The impact of the TIME_STYLE environment variable on du(1) was only
documented in the Texinfo manual.  To avoid surprises for users,
also mention TIME_STYLE in the usage text, i.e., for --help and man.
Organize similar as in ls(1), but as du(1) has slightly different
behavior it would be hard to share the translation.

* src/du.c (usage): Shorten the description of --time-style, and refer
to an additional --time-style / TIME_STYLE description below.
2025-11-16 18:31:20 +01:00
Pádraig Brady e05b875be8 maint: tag supported options not documented in --help 2025-11-16 17:18:03 +00:00
Pádraig Brady b545f6e6f3 maint: rearrange cksum modules so main is in cksum.c
* src/cksum.c: -> src/cksum_crc.c
* src/cksum.h: -> src/cksum_crc.h
* src/digest.c: -> src/cksum.c
* src/local.mk: Adjust accordingly.
* cfg.mk: Likewise.
* po/POTFILES.in: Likewise.
* src/cksum_avx2.c: Likewise.
* src/cksum_avx512.c: Likewise.
* src/cksum_pclmul.c: Likewise.
* src/cksum_vmull.c: Likewise.
2025-11-16 17:18:03 +00:00
Pádraig Brady f8137811d9 wc: fix missing documentation for the --debug option
* doc/coreutils.texi (wc invocation): Desscribe --debug.
* src/wc.c (usage): Likewise.
* NEWS: Mention the bug fix.
2025-11-16 17:18:03 +00:00
Pádraig Brady faf8d8998c doc: shred: clarify what --verbose outputs
* doc/coreutils.texi (shred invocation): Give more details on what
--verbose outputs, to give some indication of its utility.
* src/shred.c (usage): Likewise.  Also since we're changing the string,
split out translations to give translators more granular translations.
2025-11-14 13:23:09 +00:00