Commit graph

3693 commits

Author SHA1 Message Date
Kyle Evans
587dacce01 cp: fix -R recursion detection
The correct logic is a lot simpler than the previous iteration.  We
record the base fts_name to avoid having to worry about whether we
needed the root symlink name or not (as applicable), then we can simply
shift all of that logic to after path translation to make it less
fragile.

If we're copying to DNE, then we'll have swapped out the NULL root_stat
pointer and then attempted to recurse on it.  The previously nonexistent
directory shouldn't exist at all in the new structure, so just back out
from that tree entirely and move on.

The tests have been amended to indicate our expectations better with
subdirectory recursion.  If we copy A to A/B, then we expect to copy
everything from A/B/* into A/B/A/B, with exception to the A that we
create in A/B.

Reviewed by:	bapt
Sponsored by:	Klara, Inc.

(cherry picked from commit f00f8b4fbd)
2022-04-23 22:51:28 -05:00
Kyle Evans
5237a02ba8 cp: fix some cases with infinite recursion
As noted in the PR, cp -R has some surprising behavior.  Typically, when
you `cp -R foo bar` where both foo and bar exist, foo is cleanly copied
to foo/bar.  When you `cp -R foo foo` (where foo clearly exists), cp(1)
goes a little off the rails as it creates foo/foo, then discovers that
and creates foo/foo/foo, so on and so forth, until it eventually fails.

POSIX doesn't seem to disallow this behavior, but it isn't very useful.
GNU cp(1) will detect the recursion and squash it, but emit a message in
the process that it has done so.

This change seemingly follows the GNU behavior, but it currently doesn't
warn about the situation -- the author feels that the final product is
about what one might expect from doing this and thus, doesn't need a
warning.  The author doesn't feel strongly about this.

PR:		235438
Reviewed by:	bapt
Sponsored by:	Klara, Inc.

(cherry picked from commit 848263aad1)
2022-04-23 22:51:13 -05:00
Gordon Bergling
492741b131 pax(1): Remove a few double words in source code comments
- s/an an/an/

(cherry picked from commit ffedb32dd3)
2022-04-14 08:17:16 +02:00
Piotr Pawel Stefaniak
c8f0a1c6d7 sh: fix autocompletion for commands that share name with a directory
(cherry picked from commit 68700941c7)
2022-04-13 21:01:04 +02:00
Cameron Katri
f50cda5511 ls(1): Allow LSCOLORS to specify an underline
Allows capitalizing the background color character to enable an
underline instead of bold, capitalizing the foreground color char will
still do bold.

Differential Revision:	https://reviews.freebsd.org/D30547

(cherry picked from commit 97c31821eb)
2022-03-26 14:18:19 +01:00
Math Ieu
a4bd2216fb ps: fix ps -aa
Passing the -a flag multiple times made ps show no processes.

Differential Revision:	https://reviews.freebsd.org/D27215

(cherry picked from commit bf27a2253f)
2022-03-22 19:46:40 +01:00
Cameron Katri
44eb8cfdc6 cp: Make -P work without -R as per POSIX
According to POSIX, cp should allow the `-P` flag to work whether `-R`
is specified or not.  Currently, the `-P` option only works along with
`-R`.

PR:		199466

(cherry picked from commit 97e1303791)
2022-03-09 15:22:02 -06:00
Kyle Evans
f8e07f2f96 cp: fix -R with links
The traversal was previously not properly honoring -H/-L/-P.  Notably,
we should not have been resolving symlinks encountered during traversal
when either -H or -P are specified.

(cherry picked from commit 33ad990ce9)
2022-03-09 15:21:58 -06:00
Stefan Eßer
c888fc2d97 bin/df: allow -t option to be used together with -l
The df command provides a -l option to exclude all non-local file
systems and a -t option with a (positive or negative) list of file
system types to display.

This commit adds support for a combination of -l and -t. If both are
specified, the parameter list of the -t option is applied on top of
the selection of öocal file systems (independently of the order of
the -l and -t options).

E.g., "df -t noprocfs,sysfs -l" will select all local file systems
except those of type procfs and sysfs.

(cherry picked from commit f0fd4a32c4)
2022-03-04 20:49:21 +01:00
Hans Petter Selasky
7c0170ab9f echo(1): Replace errexit() with err(3)
Differential revision:	https://reviews.freebsd.org/D32501
Submitted by:	christos@
Sponsored by:	NVIDIA Networking

(cherry picked from commit 4c537df51a)
2022-01-07 14:12:12 +01:00
Emmanuel Vadot
26c7445164 pkgbase: Put yellow pages programs to its own package
YP is less and less used, split them to users have the choice to not
install them.

MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33441

(cherry picked from commit 5abb10faa1)
2022-01-05 18:23:51 +01:00
Elyes HAOUAS
d88a3fe466 src/bin/sh: Fix spelling errors
Pull Request: https://github.com/freebsd/freebsd-src/pull/544
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
(cherry picked from commit 48556dff3d)
2021-11-18 21:52:21 -07:00
Elyes HAOUAS
d57d56b8ab src/bin/mkdir: Spell occur correctly.
Pull Request: https://github.com/freebsd/freebsd-src/pull/544
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
(cherry picked from commit 28c3c137f6)
2021-11-18 21:52:21 -07:00
Elyes HAOUAS
fa99313f30 src/bin/pax: Fix spelling error
"whats" -> "what's"

Pull Request: https://github.com/freebsd/freebsd-src/pull/544
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
(cherry picked from commit 8db446034e)
2021-11-18 21:52:21 -07:00
Elyes HAOUAS
2a5fe2c981 src/bin/ps: Fix spelling error
Spell interruptible correctly.

Pull Request: https://github.com/freebsd/freebsd-src/pull/544
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
(cherry picked from commit 3fe686f25a)
2021-11-18 21:52:21 -07:00
Mateusz Piotrowski
014ae00ef6 date: Capitalize seconds string in synopses
This makes it consistent with other date(1) implementations. Also, it
feels more consistent since hours and minutes are already represented as
HH and MM respectively.

MFC after:	3 days

(cherry picked from commit c537bf9d59)
2021-11-07 18:55:22 +01:00
Mateusz Piotrowski
5bee300aef date.1: Fix some style issues and examples
- Use Cm instead of Ar or Sq for command modifiers of the -v flag.
- Remove unnecessary "Ar ..." from the synopsis. It's not clear what it
  was referring to.
- Add missing arguments to the -f and -v flags.
- Stylize the dot before "ss" with Cm in the default format in the -f
  flag description.
- Set LC_ALL=C in the last example so that the output format of
  date(1) always matches the specified format of the -f flag not matter
  the locale.
- List the -f flag as optional in all usage lines in the synopsis.

MFC after:	3 days

(cherry picked from commit 00133d5c5e)
2021-11-07 18:54:59 +01:00
Mateusz Piotrowski
513348e821 date: Clean up synopses
MFC after:	3 days

(cherry picked from commit a12b16f48f)
2021-11-07 18:54:03 +01:00
Ka Ho Ng
446da52f9e sh: Set PATH envvar after setting HOME in dotfile
In single-user mode, all env vars are absent, so exptilde() would not be
able to expand ~ correctly.
Place the lines setting PATH below HOME, so exptilde() would work as
expected.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	jilles, emaste
Differential Revision:	https://reviews.freebsd.org/D27003

(cherry picked from commit fcfa64801a)
2021-10-31 08:46:41 +08:00
Faraz Vahedi
cae3560307 freebsd-version(1): Add -j flag to support jails
Make freebsd-version(1) support jails by adding the -j flag which takes
a jail jid or name as an argument. As with other options, -j
flags stack and display in the order requested.

Reviewed by:	bcr (manpages), kevans
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D25705

(cherry picked from commit f54b18fc4d)
2021-10-08 11:29:07 -05:00
Kyle Evans
6e9b69d219 hostname: avoid strcpy() overlap in -d flag handling
We don't need the strcpy() anyways, just use a pointer to the hostname
buffer and move it forward for `hostname -d`.

Sponsored by:	Klara, Inc.

(cherry picked from commit 33c1e7271a)
2021-10-03 00:14:58 -05:00
Piotr Pawel Stefaniak
ec5849afc8 sh: improve command completion
When there are many matches, find the longest common substring starting
from the beginning of each command and use that to replace input.

As an example: on my system, llv<tab> will be autocompleted to llvm-
and another <tab> will print all matching llvm commands.

(cherry picked from commit c866d0c798)
2021-09-25 10:34:38 +02:00
Piotr Pawel Stefaniak
14fb8056ce sh: reset sh bindings on bind -e, bind -v
Until this change, any bindings set in histedit() were lost on calls to
bindcmd().

Only bind -e and bind -v call libedit's keymacro_reset(). Currently you
cannot fool libedit/map.c:map_bind() by trying something like bind -le
as when p[0] == '-', it does a switch statement on p[1].

(cherry picked from commit 9413dfd331)
2021-09-25 10:34:38 +02:00
Piotr Pawel Stefaniak
b2b7eb9e23 sh: improve command completion
When multiple matches are found, we keep the provided string on the
input line and print unique matches as suggestions.

But the multiple matches might be the same command found in different
directories, so we should deduplicate the matches first and then decide
whether to autocomplete the command or not, based on the number of
unique matches.

(cherry picked from commit b8ff849cbd)
2021-09-25 10:34:38 +02:00
Piotr Pawel Stefaniak
ff5f61e07d ls: prevent no-color build from complaining when COLORTERM is non-empty
(cherry picked from commit ced2dcadcc)
2021-08-28 10:17:55 +02:00
Piotr Pawel Stefaniak
b25642d653 sh: fix NO_HISTORY build
(cherry picked from commit 35b253d9d2)
2021-08-28 10:17:29 +02:00
Kyle Evans
d511b903b9 kenv: allow listing of static kernel environments
The early environment is typically cleared, so these new options
need the PRESERVE_EARLY_KENV kernel config(8) option. These environments
are reported as missing by kenv(1) if the option is not present in the
running kernel.

(cherry picked from commit db0f264393)
2021-08-26 01:35:33 -05:00
Kyle Evans
40ea449c41 kenv: s/dump/list/ to clarify meaning
The contents of the kenv will be dumped to stdout, while dump could have
also meant 'discard'. Call it 'list' instead.

(cherry picked from commit 46438b5366)
2021-08-26 01:35:24 -05:00
Alex Richardson
0869d85591 bin/ps: Avoid function name conflict with libc uname()
This prevents ps from being built with address sanitizer instrumentation.

Reviewed By:	trasz
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D31048

(cherry picked from commit 2423585b1d)
2021-08-05 09:59:59 +01:00
Mateusz Guzik
ede6e97b82 df: remove the unused fstype var
Found with cc --analyze

Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 570b31f610)
2021-07-25 07:00:42 +00:00
Emmanuel Vadot
d130523e84 pkgbase: Put chio in utilities
No need to bloat runtime with this utility.

Differential Revision:	https://reviews.freebsd.org/D30753
Sponsored by:	Diablotin Systems
2021-06-30 09:24:32 +02:00
Piotr Pawel Stefaniak
2556ee3a27 sh: fix debug build
(cherry picked from commit 1a4e959eb3)
2021-05-05 13:04:58 +02:00
Piotr Pawel Stefaniak
bee62aa5a6 sh: silence sanitizer
(cherry picked from commit 5a18515b31)
2021-05-05 13:04:58 +02:00
Piotr Pawel Stefaniak
21b2920724 sh(1): autocomplete commands
(cherry picked from commit b315a7296d)
2021-05-05 13:04:57 +02:00
Baptiste Daroussin
a3b7f91260 cp: fix indentation
No functional changes

(cherry picked from commit 45b252fc91)
2021-05-05 10:35:02 +02:00
Baptiste Daroussin
2abb724cad sh: improve emacs mode
In emacs mode, force ^R to backware search the history
This behaviour is the default in emacs mode for most of the other shells

Note: Note that this can still be overridden via $EDITRC, ~/.editrc or a
bind command after set -o emacs.

Approved by:		jilles
Reviewed by:		jilles, arichardson, pstef
Differential Revision:	https://reviews.freebsd.org/D29494

(cherry picked from commit 660045fb53)
2021-05-05 09:17:09 +02:00
Gordon Bergling
ddb7a5056f ed(1): Add two references in the SEE ALSO section
Obtained from:	OpenBSD

(cherry picked from commit 3ce579325e)
2021-04-16 16:25:25 +02:00
Alex Richardson
a24b7455e8 bin/pkill: Fix {pgrep,pkill}-j_test.sh
The POSIX sh case statement does not allow for pattern matching using the
regex + qualifier so this case statement never matches. Instead just check
for a string starting with a digit followed by any character.

While touching these files also fix various shellcheck warnings.

`kyua -v parallelism=4 test` failed before, succeeds now.

Reviewed By:	imp
Differential Revision: https://reviews.freebsd.org/D28480

(cherry picked from commit 5ff2e55e00)
2021-03-17 09:57:15 +00:00
Alexander V. Chernikov
bbff3a72b2 Fix typo in pwait.c introduced in 5bdce6ff54
Reported by:	kevans
2021-01-21 21:43:27 +00:00
Alexander V. Chernikov
5bdce6ff54 Remove deadlock in rc caused by pwait waiting for itself.
The following situation can trigger the deadlock:
1) Long time ago a_service was started through rc.d
2) We want to restart a_service and issue service a_service restart
3) rc.subr reads current process PID (via file or process),
   sends TERM signal and runs pwait with PID harvested
4) a_service process dies very quickly so it's PID becomes available.
   It is possible that while original process was running,
   PID counter overflowed and pwait got assigned a_service's PID.

This patch ignores pid(s) to wait that are equal to pwait PID.

Reported by:	Dan McGregor, Boris Lytochkin
Submitted by:	Boris Lytochkin <lytboris at gmail.com>
Reviewed By:	0mp
MFC after:	2 weeks
PR:		218598
Differential Revision: https://reviews.freebsd.org/D28240
2021-01-21 21:36:37 +00:00
Mariusz Zaborski
0614d73967 cat: style nits
Pointed out by:	jhb
2021-01-20 18:46:26 +01:00
Mateusz Piotrowski
a0e85d0eb5 Remove the unnecessary space before the colon
MFC after:	3 days
2021-01-20 09:46:15 +01:00
Ed Maste
e83b514a95 cat: depend on Makefile to rebuild when WITH_CASPER changes
We try to ensure building WITHOUT_CLEAN (or -DNO_CLEAN) works on an
ongoing basis.  b7ab6832cd changed cat to build w/o -DWITH_CASPER
by default; add a cat.o dependency on the Makefile so that it gets
rebuilt.
2021-01-17 12:19:00 -05:00
Mariusz Zaborski
b7ab6832cd cat: disable building it with Casper
We want to measure what are the actual cost of sandboxing cat(1).

Requested by:	mjg, cy, Mike Karels
Discussed with:	rwatson, markj
2021-01-17 01:21:46 +01:00
Mariusz Zaborski
de57c3d882 cat: style nits 2021-01-16 12:58:23 +01:00
Mariusz Zaborski
6e8062c855 cat: persistent errno
There is no guarantee that after close(2)/free the errno will remain
persistent. The caller of the udom_open function depends on the errno
for reporting errors.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D28185
2021-01-16 12:55:42 +01:00
Mariusz Zaborski
c664d8dfc3 cat: Fix potential memory leak
This was introduced in aefe30c543.
2021-01-15 21:49:52 +01:00
Mariusz Zaborski
aefe30c543 cat: capsicumize it
Reviewed by:	markj, arichardson
Differential Revision:	https://reviews.freebsd.org/D28083
2021-01-15 21:23:42 +01:00
Alex Richardson
ed8455806e Fix all warnings emitted in make kernel-toolchain
With this change and D27598 make kernel-toolchain no longer emits any
warnings for me.

Reviewed By:	emaste
Differential Revision: https://reviews.freebsd.org/D27599
2021-01-07 09:26:22 +00:00
Jilles Tjoelker
52981a1694 sh/tests: Add a second kind of binary scripts without #!
One of the reasons for git commit
e0f5c1387d was to make "actually portable
executables" work. Add a test that is more like those.

MFC after:	1 week
2021-01-03 23:53:37 +01:00