Commit Graph

29106 Commits

Author SHA1 Message Date
Paul Eggert
3aaa42deaa maint: port from matchpathcon to selabel_lookup
Ubuntu 20.10 is using a newer version of libselinux that
complains that matchpathcon is obsolete.  Rewrite the code
that it uses the recommended selabel_lookup instead.
* m4/jm-macros.m4 (coreutils_MACROS): Do not check for
matchpathcon_init_prefix, as it is no longer used.
* src/copy.c (set_file_security_ctx): Omit process_local arg,
as it is equivalent to !x->set_security_context.  All callers changed.
* src/copy.h (struct cp_options): set_security_context is now of
type struct selabel_handle *, not bool.  All uses changed.
* src/cp.c, src/install.c, src/mkdir.c, src/mkfifo.c, src/mknod.c:
* src/mv.c: Include selinux/label.h.
(main): Use selabel_open for set_security context.
* src/install.c (matchpathcon_init_prefix): Remove; now unused.
(get_labeling_handle): New static function.
(setdefaultfilecon, main): Use it.
(setdefaultfilecon): Do something regardless of
ENABLE_MATCHPATHCON, which seems to be a revenant macro.
(setdefaultfilecon): Use selabel_lookup instead of the obsolescent
matchpathcon.  Report an error unless it fails due to ENOENT.
* src/local.mk (src_ginstall_CPPFLAGS): Remove.
* src/selinux.c: Include selinux/label.h
Do not include die.h, error.h, canonicalize.h.
(defaultcon, restorecon_private, restorecon):
New arg HANDLE.  All callers changed.
Use selabel_lookup rather than matchpathcon.
(restorecon_private, restorecon): Don’t lose track of errno.
* src/selinux.c, src/selinux.h:
(restorecon): Don’t call ‘error’; that’s the caller’s job.
Use HAVE_SELINUX_LABEL_H, not HAVE_SELINUX_SELINUX_H,
in case there is some weird system with the former but not the latter.
* src/selinux.h (struct selinux_handle): Add forward decl.
2020-11-21 18:41:25 -08:00
Paul Eggert
5c8e2716b3 build: port to Solaris 10
* src/local.mk (src_ln_LDADD, src_mktemp_LDADD, src_tac_LDADD):
Add $(LIB_CLOCK_GETTIME), since these use tempname which uses
clock_gettime if getrandom fails.  On platforms like Solaris 10,
clock_gettime is not in the standard C library.
2020-11-21 18:41:25 -08:00
Paul Eggert
4c667a86d3 build: update gnulib submodule to latest 2020-11-21 18:41:24 -08:00
Pádraig Brady
c3a5280731 doc: mention that sort -g supports hex numbers
* doc/coreutils.texi (sort invocation): Mention explicitly
that --general-numeric-sort supports arbitrary format hex numbers,
but also mention that consistent case/width hex numbers can
be sorted faster with a standard sort.
2020-11-18 14:00:43 +00:00
Pádraig Brady
2bc66c5ea7 tr: fix crash validating -c with some case char classes
This crash was identified by Cyber Independent Testing Lab:
https://cyber-itl.org/2020/10/28/citl-7000-defects.html
and was introduced with commit v8.5-163-g3f48829c2

* src/tr.c (validate_case_classes): Don't apply these
extra case alignment checks in the --complement case,
which is even more restrictive as to the contents of SET2.
* tests/misc/tr-case-class.sh: Add a test case,
for a large SET1, which caused the length adjustment
in validate_case_classes to underflow and trigger the assert.
* NEWS: Mention the bug fix.
2020-11-14 16:51:49 +00:00
Ben Pfaff
1833f51aaa doc: clarify in texinfo that test == ... is non portable
* doc/coreutils.texi (test invocation): Mention non portability
of the double equals form.
2020-11-12 18:59:31 +00:00
Pádraig Brady
6fc695cb4a ls: fix crash printing SELinux context for unstatable files
This crash was identified by Cyber Independent Testing Lab:
https://cyber-itl.org/2020/10/28/citl-7000-defects.html
and was introduced with commit v6.9.90-11-g4245876e2

* src/ls.c (gobble_file): Ensure scontext is initialized
in the case where files are not statable.
* tests/ls/selinux-segfault.sh: Renamed from proc-selinux-segfault.sh,
and added test case for broken symlinks.
* tests/local.mk: Adjust for the renamed test.
* NEWS: Mention the bug fix.
2020-11-11 17:28:54 +00:00
Pádraig Brady
beafa5c0a3 timeout: support sub-second timeouts on macOS
* m4/jm-macros.m4: Check for setitimer.
* src/timeout.c: Use setitimer if timer_settime is not available.
* NEWS: Mention the improvement.
2020-11-07 21:35:01 +00:00
Pádraig Brady
165a80f6e6 maint: avoid strncat warning on GCC
GCC 10.1.1 without optimization gives:

  error: ‘strncat’ argument 2 declared attribute ‘nonstring’
    [-Werror=stringop-overflow=]
    strncat (comment, UT_ID (utmp_ent), utmpsize);

Note the strncat man page says that:
  "src does not need to be null-terminated
   if it contains n or more bytes."
And the POSIX spec says that the second (source) parameter
is an array not a string.
So I think it's incorrect for strncat to require src be a string type.
This constraint seems to be being added to the gcc builtin strncat,
as specifiying -fno-builtin also avoids the warning.
Note specifying any optimization level also avoids the warning.

* src/who.c (make_id_equals_comment): Avoid the issue by using
stpcpy + stzncpy, instead of strcpy + strncat.
This pattern is used elsewhere in who.c
2020-11-07 21:34:34 +00:00
Pádraig Brady
ff80b6b0a0 stat,tail: sync file system constants from the linux kernel
* src/stat.c: Add magic constants for "devmem", and
"zonefs" file systems.
* NEWS: Mention the improvement.
2020-10-28 14:16:29 +00:00
Pádraig Brady
53324dd611 maint: cleanup operation of fs-magic-compare
* src/local.mk: Ensure we map 2 hex digits to 4,
so that we don't output already handled Z3FOLD file system (0x33).
Also hide the generation command for src/fs.h.
2020-10-28 14:16:12 +00:00
Pádraig Brady
51cfaef655 doc: make blank lines before --help consistent
* src/basenc.c (usage): Remove extraneous blank line,
to be consistent with other utilities that have options.
* src/realpath.c: Likewise.
* src/runcon.c: Likewise.
Addresses https://bugs.gnu.org/44248
2020-10-27 19:23:46 +00:00
Jim Meyering
cc816fb978 maint: avoid new sort.c warning from upcoming GCC11
gcc version 11.0.0 20201025 (experimental) warns that
src/sort.c:1655:1: warning: function might be candidate for attribute \
  'pure' if it is known to return normally [-Wsuggest-attribute=pure]
* src/sort.c (limfield): Mark as pure.
2020-10-26 07:47:36 -07:00
Kamil Dudka
4278e6615f dd: drop old workaround for lseek() bug in Linux kernel
The workaround triggers warnings from newer kernel versions in case
a user does not have sufficient privileges for the MTIOCGET ioctl.

* src/dd.c (skip_via_lseek): Drop wrapper function no longer needed.
(skip): Use lseek() directly.
(advance_input_after_read_error): Likewise.

Reported-by: Nir Soffer at https://bugzilla.redhat.com/1876840
Fixes https://bugs.gnu.org/44235
2020-10-26 13:31:36 +00:00
KOBAYASHI Takashi
2c898597ea nl: support a negative --line-increment
* src/nl.c (main): Allow -i to accept down to INTMAX_MIN.
* tests/misc/nl.sh: Add test cases.
* NEWS: Mention the new feature.
2020-10-26 13:15:46 +00:00
Pádraig Brady
fe41d6c651 nl: only fail if need to output overflowed numbers
Previously we would have failed immediately upon internal overflow,
which didn't output the full line being processed, and assumed
there would be another numbered line.

* src/nl.c (line_no_overflow): A new global to track overflow.
(print_lineno): Only fail if about to output an overflowed number.
(reset_lineno): A new function to refactor resetting of the number,
and which also clears line_no_overflow.
* tests/misc/nl.sh: Add a test case.
2020-10-25 16:57:19 +00:00
Pádraig Brady
175c7c6a60 maint: add lib/parse-datetime-gen.h to .gitignore
* .gitignore: update to ignore new file
generated by the latest gnulib update.
2020-10-25 13:35:40 +00:00
Pádraig Brady
f803c0e92d maint: sync help2man to latest version
* man/help2man: sync to changes from version 1.47.16.
Note this doesn't materially change the generated man pages.
Addresses https://bugs.gnu.org/44105
2020-10-25 13:31:37 +00:00
Paul Eggert
00ea4bacf6 build: update gnulib submodule to latest
* gl/lib/randperm.c, src/cp-hash.c, src/ls.c, src/sort.c, src/tail.c:
Change all instaces of hash_delete to hash_remove to accommodate
change to Gnulib API.
2020-10-19 10:58:53 -07:00
Grigorii Sokolik
d9b33b1535 maint: remove already handled FIXME in tail.c
* src/tail.c: Remove FIXME to follow a file name in a recreated
directory. The comment was added in commit v8.5-191-g61b77891c
while the fix (albeit not using inotify) was added in
commit v8.27-21-gba5fe2d4b
2020-10-17 16:54:17 +01:00
Grigorii Sokolik
db3131adb8 maint: update docs for build prerequisites
* README-prereq: Explicitly pull tags,
and update the xz git repo url.
2020-10-17 16:53:35 +01:00
Benno Schulenberg
ebaffa5094 doc: fix punctuation in stat --help
* src/stat.c (usage): Replace a mistaken semicolon with a colon,
and replace mistaken backticks with single quotes.  Also reorder
some words, for clarity.
Fixes https://bugs.gnu.org/43707
2020-09-29 21:57:30 +01:00
Pádraig Brady
5b8161ee4d doc: clarify timeout --foreground description
* doc/coreutils.texi (timeout invocation): Avoid any implication
that `timeout --foreground` could be used to retroactively
timeout commands not already invoked by timeout(1).
Fixes bug https://bugs.gnu.org/42831
2020-08-12 18:40:17 +01:00
Emanuele Giacomelli
7cf45f4f6a csplit: fix regex suppression with specific match count
* src/csplit.c (process_regexp): Process the line suppression
in all invocations so that the last match is suppressed.
Previously with a non infinite match count,
the last regex pattern was not suppressed.
* NEWS: Mention the bug fix.
* tests/misc/csplit-suppress-matched.pl: Add a test case.
Fixes https://bugs.gnu.org/42764
2020-08-08 21:50:13 +01:00
Bernhard Voelker
c0e5f8c59b tests: skip some parts of 'tests/rmdir/ignore.sh' if run as root
Parts of this test expect that the rmdir syscall returns with EPERM,
but the root user does not see that.

* tests/rmdir/ignore.sh: Add uid_is_privileged_ guards around parts
of the test which expect rmdir() to fail with EPERM.

Reported by Nick Alcock <nix@esperi.org.uk> in
https://bugs.gnu.org/42633
2020-07-31 19:49:35 +02:00
Bernhard Voelker
881c3f20ec doc: show version in title of HTML manual
* doc/coreutils.texi (@include version.texi): Move before ...
(@settitle): ... this.  Add the version after the package name.

Suggested by Jonny Grant <jg@jguk.org> in
https://lists.gnu.org/r/bug-coreutils/2020-07/msg00021.html
2020-07-28 23:30:11 +02:00
Paul Eggert
fd0fdeff94 build: update gnulib submodule to latest
* src/local.mk (src_expr_LDADD, src_factor_LDADD):
Adjust to Gnulib renaming of LIB_GMP to LIBGMP.
2020-07-28 13:45:47 -07:00
Pádraig Brady
97757b5eba doc: fix typo in env --split-string documentation
* doc/coreutils.texi: Fix grammar.
2020-07-27 13:16:42 +01:00
Paul Eggert
fa7a5074d7 date: clarify the Epoch
* src/date.c (usage): Mention the Epoch under %s for clarity,
and capitalize.
2020-07-24 13:33:40 -07:00
Paul Eggert
3f06bde222 doc: modernize date examples
* doc/coreutils.texi: Use more-modern date examples.
Capitalize “Epoch” to be consistent with POSIX.
2020-07-24 13:33:40 -07:00
Paul Eggert
7b3a62e016 build: update gnulib submodule to latest
* bootstrap.conf (gnulib_modules): Add hash-triple.
2020-07-24 13:33:40 -07:00
Bernhard Voelker
49bd08aea5 doc: clarify 'timeout -k' behavior
* doc/coreutils.texi (timeout invocation): Document that the the
duration of --kill-after=DURATION begins when sending the initial
signal.  Also mention that -k does not have any effect if timeout's
duration is 0.

Suggested by Jonny Grant <jg@jguk.org>.
2020-07-20 22:02:02 +02:00
Paul Eggert
9462c1202d factor: port to --without-libgmp
* src/factor.c (mp_factor_using_division): Use mpz_fdiv_q_2exp
instead of its no-longer-documented mpz_div_2exp alias.
(print_factors): Use mpz_out_str instead of gmp_printf.
2020-07-18 18:46:35 -07:00
Paul Eggert
6b6f0f54c0 build: be less aggressive about -fanalyzer
* configure.ac: Don’t enable -fanalyzer unless configured with the
new --enable-gcc-warnings=expensive option.  See thread at:
https://lists.gnu.org/r/coreutils/2020-07/msg00011.html
2020-07-10 17:38:31 -07:00
Paul Eggert
55d985064c factor: explain why non-GMP code (Bug#42269)
* doc/coreutils.texi (factor invocation):
* src/factor.c: Explain why the two-word algorithm is useful.
2020-07-08 18:59:41 -07:00
Paul Eggert
67fc55d636 doc: mention expr and factor bignums
* NEWS:
* doc/coreutils.texi (expr invocation, factor invocation):
Mention bignum support on all platforms.  Modernize timings.
2020-07-08 08:11:57 -07:00
Paul Eggert
95955e6746 factor: treat ' +bignum' like non-bignum
* src/factor.c (strto2uintmax): Instead of here ...
(print_factors): ... skip spaces and '+' here, so that
bignums are treated like non-bignums.
* tests/misc/factor.pl (bug-gmp-plus_2_sup_128_plus_1): New test.
2020-07-08 08:11:57 -07:00
Paul Eggert
af941bc523 tests: simplify since expr now works on bignums
* cfg.mk (sc_prohibit_expr_unsigned): Remove.
* tests/dd/skip-seek-past-dev.sh (DEV_OFLOW):
* tests/id/setgid.sh (gp1):
* tests/misc/cut-huge-range.sh (CUT_MAX):
* tests/misc/expr.pl:
* tests/misc/sort-discrim.sh:
Assume expr works on bignums.
* tests/misc/cut-huge-range.sh (subtract_one):
Remove; no longer needed.
2020-07-08 08:11:57 -07:00
Paul Eggert
712855a77d factor: simplify tests by assuming libgmp
* tests/misc/factor.pl: Test bignums even if !HAVE_GMP.
2020-07-08 08:11:57 -07:00
Paul Eggert
1304644488 maint: use Gnulib libgmp module
This lets use assume multiple-precision arithmetic on all
platforms, simplifying the code.
* bootstrap.conf (gnulib_modules): Add libgmp.
* configure.ac: Don’t call cu_GMP, as this is now done by Gnulib.
* m4/gmp.m4: Remove.
* src/expr.c, src/factor.c: Use gmp.h unconditionally.
* src/factor.c: Use the simpler ‘#ifndef mpz_inits’ to
determine whether there is an mpz_inits macro.
2020-07-07 14:48:21 -07:00
Paul Eggert
4c8495cf11 build: update gnulib submodule to latest 2020-07-07 14:48:21 -07:00
Bernhard Voelker
b1c6ef230c doc: add timeout examples
* doc/coreutils.texi (timeout invocation): Add examples.

Suggested by Jonny Grant <jg@jguk.org> in
https://lists.gnu.org/r/bug-coreutils/2020-06/msg00018.html
2020-07-04 00:19:31 +02:00
Andreas Schwab
6a3d2883fe tests: avoid spurious testsuite failure
* tests/dd/stats.sh: Increase timeout.
Fixes https://bugs.gnu.org/42135
2020-06-30 13:44:34 +01:00
Pádraig Brady
947c553ff9 tests: fix false failure with valgrind and reflink
* tests/cp/fiemap-FMR.sh: Avoid FICLONE ioctl,
which would avoid the point of the test (fiemap testing).
Also it avoids a valgrind bug with this ioctl:
https://bugs.kde.org/show_bug.cgi?id=397605
2020-06-26 19:57:09 +01:00
Paul Eggert
4b04a0c3b7 cp: use copy_file_range if available
* NEWS: Mention this.
* bootstrap.conf (gnulib_modules): Add copy-file-range.
* src/copy.c (sparse_copy): Try copy_file_range if not
looking for holes.
2020-06-25 18:53:43 -07:00
Paul Eggert
a6eaee501f cp: use SEEK_DATA/SEEK_HOLE if available
If it works, prefer lseek with SEEK_DATA and SEEK_HOLE to FIEMAP,
as lseek is simpler and more portable (will be in next POSIX).
Problem reported in 2011 by Jeff Liu (Bug#8061).
* NEWS: Mention this.
* src/copy.c (lseek_copy) [SEEK_HOLE]: New function.
(enum scantype): New constants ERROR_SCANTYPE, LSEEK_SCANTYPE.
(union scan_inference): New type.
(infer_scantype): Last arg is now union scan_inference *,
not struct extent_scan *.  All callers changed.
Prefer SEEK_HOLE to FIEMAP if both work, since
SEEK_HOLE is simpler and more portable.
(copy_reg): Do the fdadvise after initial scan, in case the scan
fails.  Report an error if the initial scan fails.
(copy_reg) [SEEK_HOLE]: Use lseek_copy if scantype says so.
2020-06-25 18:53:43 -07:00
Paul Eggert
2fcd0f3328 cp: avoid copy_reg goto
* src/copy.c (copy_reg): Redo to avoid label and goto.
2020-06-25 18:53:43 -07:00
Paul Eggert
761ba28400 cp: refactor extent_copy
* src/copy.c (extent_copy): New arg SCAN, replacing
REQUIRE_NORMAL_COPY.  All callers changed.
(enum scantype): New type.
(infer_scantype): Rename from is_probably_sparse and return
the new type.  Add args FD and SCAN.  All callers changed.
2020-06-25 18:53:43 -07:00
Paul Eggert
d80820b3b5 maint: typo fix
* NEWS: Fix typo.
2020-06-25 18:53:42 -07:00
Paul Eggert
eac715a412 chmod: man page fixes
* man/chmod.x: Mention -6000 too.  Use .BR to fix trailing period.
2020-06-23 08:41:40 -07:00