4119 Commits
Author SHA1 Message Date
Wolfram Schneider 14680d205c ps.1: Fix unusual Xr order 2026-10-25 11:36:15 +00:00
Wolfram Schneider 51a531151a df.1: Fix unusual Xr order 2026-10-25 11:32:12 +00:00
Olivier Certner 72bb9eb7b6 pwd(1): De-obfuscate, style(9)
In getcwd_logical(), test for a '.' or '..' component in one of the most
straightforward and intelligible ways possible.

In particular, this removes a superfluous re-test of the the component's
first character being '.' when the first one did not pass and, more
importantly, prevents the second test from relying on a side-effect in
the first.

While here, for better clarity, replace the loop that searches for '/'
with a simple call to strchrnul().

Add high-level comments about what is going on.

While here, test explicitly that pointed 'char' values are not 0 ('\0')
(style(9)).

While here, separate the successive steps of getcwd_logical() with blank
lines.

No functional change (intended).

Discussed with: emaste
Fixes:          2df923c5d2 ("pwd: Clean up and adopt POSIX semantics")
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D59709
2026-09-23 13:37:45 +02:00
Faraz Vahedi cc61cc7b63 ls(1): Preserve const qualifier on strstr(3) result
Reviewed by:	fuz
Approved by:	fuz (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59774
2026-09-19 13:45:10 +03:30
Faraz Vahedi 066fad8aef ed(1): Preserve const qualifier on strchr(3) result
Reviewed by:	fuz
Approved by:	fuz (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59773
2026-09-19 13:44:30 +03:30
Faraz Vahedi 225612c76d dd(1): Preserve const qualifier on bsearch(3) results
Reviewed by:	fuz, dteske
Approved by:	fuz (mentor), dteske (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59754
2026-09-19 13:43:20 +03:30
Faraz Vahedi d10e39d489 ps(1): Preserve const qualifier on strchr(3) result
Reviewed by:	fuz, dteske
Approved by:	fuz (mentor), dteske (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59666
2026-09-15 19:42:14 +03:30
Alexander Ziaee 49b4137da6 chflags: Alias nocache to noucache for consistency
Event:			EuroBSDcon 2026
Requested by:		fuz
Reviewed by:		fuz, rmacklem
Differential Revision:	https://reviews.freebsd.org/D59588
2026-09-13 07:42:52 -04:00
Alexander Ziaee 35973eceff sh.1: Renew description of case
Update case synopsis, split description into paragraphs, improve markup,
light wordsmithing, and import exit status line from NetBSD.

While here, remove the '-' from the beginning of this document.

PR:	298329
Event:	EuroBSDcon 2026
Fixes:	c9afaa6389 ("Add case statement fallthrough")
Fixes:	f7a9b7fe3a ("Allow a left parenthesis before patterns in case blocks")
Fixes:	e00e16ad7f ("Allow empty case/esac statements")
MFC after:	3 days
Reviewed by:	bcr, jilles, Artem Bunichev <[email protected]>
Differential Revision:	https://reviews.freebsd.org/D59518
2026-09-12 10:44:39 -04:00
Baptiste Daroussin d2cfdf4c12 cat: add -A, -E and -T flags
Support cat -A, -E and -T, which are commonly used by Linux shell
scripts.  -E prints a "$" at the end of each line, -T renders tabs
as ^I, and -A is equivalent to -vET.

MFC After:	1 week
Discussed with:	jrtc27
Reviewed by:	jrtc27, ziaee
Differential Revision:	https://reviews.freebsd.org/D59250
2026-08-31 14:35:21 +02:00
Christian Weisgerber da8b3e70ab stty(1): list DISCARD control character 2026-08-28 16:15:25 +00:00
Rick Macklem c54fbc9e83 chflags.1: Change dontcache to nocache
Commit 290e563166 changed the flag's name from dontcache
to nocache. This patch fixes the man page.

This is a content change.

Reviewed by:	kib (earlier version)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D58181
Fixes:	4830670a3f ("chflags.1: Document the new UF_DONTCACHE flag")
2026-08-26 15:19:26 -07:00
Jitendra Bhati 22df19c09a chflags: use Capsicum capability mode
Run the file-hierarchy traversal inside Capsicum capability mode
using the fts_openat(3) API.  This confines chflags to the directory
hierarchies named on the command line, so a malicious or buggy tree
cannot redirect it at files elsewhere via a crafted symbolic link.

Because AT_FDCWD is rejected in capability mode, a directory descriptor
for the parent directory of every argument with an absolute path or a
path containing ".." is opened once before cap_enter().  Once every
descriptor is open, cap_enter() is called and the traversal acts through
fd-relative operations: chflagsat(fts_parent->fts_dirfd, fts_name).

With -L chflags follows symbolic links, which may point outside the
named hierarchy; chflag now rejects such accesses.  The new
--dereference-links-unsafely option disables the sandbox to restore the
historical behavior for the rare callers that rely on it.  But if the
symbolic was link was named directly on the command line, chflags will
still follow it (unless -h was given).

Add functional tests covering relative, absolute, "..", recursive
and mixed path arguments, and the symlink handling in both the
default and --dereference-links-unsafely modes; they skip on
filesystems that do not support the uchg flag.

Sponsored by:   Google LLC (GSoC 2026)
Reviewed by:	asomers
Relnotes:	yes (for the -L behavior change)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2375
2026-08-23 13:02:00 -06:00
Jitendra Bhati 4a07ed9bcd chflags: fix indentation style bugs
Several lines in the flags-parsing block used spaces instead of
tabs for indentation.  Convert them to tabs to match style(9).
No functional change.

Sponsored by:   Google LLC (GSoC 2026)
2026-08-23 13:01:59 -06:00
Sean Eric Fagan 24983c4e9f sleep: Fix man page about IGINFO output
Reviewed by:	des
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D58483
2026-07-28 10:56:17 +01:00
Dag-Erling Smørgrav 51c0cdb049 pwait: Fix pwait_normal test case
Reported by:	markj
Fixes:		e115066370 ("pwait: Test the new -r option")
2026-07-27 20:54:11 +02:00
Dag-Erling Smørgrav 9d852922f6 Bump dates
Fixes:		c8f5e6819d ("pwait: Optionally wait until process is reaped")
Fixes:		eddd8aa99c ("pwait: Add a SIGINFO handler")
Fixes:		356d0b79cf ("rc.subr: Fix premature return from wait_for_pids")
2026-07-27 12:26:41 +02:00
Dag-Erling Smørgrav e115066370 pwait: Test the new -r option
Test that pwait without -r reports a process as soon as it terminates,
while pwait with -r does not report it until it has been reaped.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D58385
2026-07-27 12:15:41 +02:00
Dag-Erling Smørgrav eddd8aa99c pwait: Add a SIGINFO handler
On SIGINFO, print a space-separated list or remaining processes to
standard error.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D58386
2026-07-27 12:15:36 +02:00
Dag-Erling Smørgrav c8f5e6819d pwait: Optionally wait until process is reaped
If the new -r option is specified, wait until the target process not
only terminates but is reaped.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D58314
2026-07-27 12:15:31 +02:00
Dag-Erling Smørgrav 5922e9d7e7 pwait: Don't use init as a target
The time_unit test case uses PID 1 as a target for pwait.  This doesn't
work in a jail.  Since all we need is a process that we know won't die
while the test is running, we may as well use ourselves.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	ngie
Differential Revision:	https://reviews.freebsd.org/D58418
2026-07-25 14:44:35 +02:00
Dag-Erling Smørgrav 5dc400ff45 cp: Correct description of SIGINFO
The manual page claimed that SIGINFO caused information to be printed to
stdout, when in fact it is printed to stderr, as one would expect.  This
has been true ever since the feature was first added in 2003.

MFC after:	1 week
Fixes:		00d321a2b3 ("Add a SIGINFO handler.")
Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D58392
2026-07-23 08:21:08 +02:00
Jane Smith 9724f3f897 cat: Fix a NULL pointer dereference
Check the `fdopen` return value before calling `cook_cat`.

Reviewed by:	markj, bnovkov
Differential Revision:	https://reviews.freebsd.org/D57741
MFC after:	1 week
2026-07-21 21:50:11 +02:00
Artem Bunichev 6ee5895f88 sh.1: Document which features are non-POSIX
Point out which features are non-POSIX and thus can not be
safely assumed to be portable and exist in other implementations.

Relnotes:		YES!
Reviewed by:		ziaee, jilles
Differential Revision:	https://reviews.freebsd.org/D55333
2026-07-20 17:53:53 -04:00
Rick Macklem 4830670a3f chflags.1: Document the new UF_DONTCACHE flag
Commit 74654ba3b1 added and new chflags(1) flag called
"udontcache" or "dontcache".  This patch documents this flag.

This is a content change.

Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D58181
2026-07-12 15:56:52 -07:00
Artem Bunichev 759ce9a2b3 ps.1: Fix broken comment line
While here, remove the long-unused dash in the first line.

Reviewed by:    ziaee, olce
Fixes:          ddf144a04b ("ps.1: Revamp: Explain general principles, update to match reality")
MFC after:      1 day
Differential Revision:  https://reviews.freebsd.org/D58038
2026-07-05 22:03:34 +02:00
Gordon Bergling dd2127b54f ps(1): Fix a few typos in the manual page
- s/occurence/occurrence/
- s/occurences/occurrences/
- s/ouput/output/

MFC after:	3 days
2026-06-27 12:48:11 +02:00
Kyle Evans 4fd518fcb2 kern: add a security knob to disable unprivileged access to kenv
We sometimes store sensitive things in the kenv that get zapped, but we
really shouldn't rely on that zapping to actually happen.  Most
unprivileged processes don't really need to read from the kernel
environment in the first place, so add a knob that allows it to be
disabled.

Note that we consider jailed root to be unprivileged from this
perspective; they have their own meta/env concepts and we should
encourage users to take advantage of those for passing information to
jails.

"Hey we should do something about that":	dch
Reviewed by:	imp, ziaee, zlei (all slightly previous version)
Differential Revision:	https://reviews.freebsd.org/D57697
2026-06-22 15:22:25 -05:00
Dag-Erling Smørgrav 09bb0b0d13 sh: Belatedly bump manual page date
Fixes:		556e793d80 ("sh: Improve function documentation")
2026-06-20 21:01:24 +02:00
Artem Bunichev b3dfd5d59c rmdir.1: Document non-POSIX -v option
MFC after:		3 days
Reviewed by:		ziaee
Differential Revision:	https://reviews.freebsd.org/D57675
2026-06-19 16:09:39 -04:00
Dag-Erling Smørgrav 556e793d80 sh: Improve function documentation
* Mention that the function body can be in parentheses.  It is already
  implied since the function body can be any valid statement, but it may
  not be obvious to a reader who has only ever seen functions that used
  curly brackets and assumes that they are part of the function syntax.

* Remove the incorrect claim that a local statement may only occur at
  the top of a function.

* Show that a value may be assigned to a variable in a local statement.

* While here, replace unpaired double quotes with \(dq to avoid
  confusing syntax highlighters.

PR:		296050
MFC after:	1 week
Reviewed by:	ziaee, jilles
Differential Revision:	https://reviews.freebsd.org/D57596
2026-06-16 22:23:18 +02:00
Alexander Ziaee e821152cc7 symlink.7: Clean up markup and tag SPDX
Also unwind some parentheticals.

MFC after:	3 days
2026-06-15 18:49:29 -04:00
Gordon Bergling 586a5bc035 pwd.1: Fix a typo in the .dD
- s/Februrary/February/

MFC after:	1 week
2026-06-15 15:40:05 +02:00
Kit Dallege 2c5fd7d9a7 cp(1): fix -P documentation to reflect it works without -R
Since commit 97e1303791, the -P flag works without -R as
required by POSIX. Update the man page to state that only -H
and -L are ignored without -R, while -P can be used independently.

PR: 289959
Signed-off-by: Kit Dallege <[email protected]>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/2102
2026-06-10 06:35:03 -06:00
Jilles Tjoelker 73e0d6b440 tests: Avoid sleep when causing a write error
Cause a write error using a fifo and wait, rather than needing a sleep
to wait for something to terminate. This is faster and avoids a
potential test failure on a heavily loaded system.

Using /dev/full would be simpler, but it is not portable enough (it
tends not to be available in jails, even). Starting programs with stdout
not open or only open for read/execute/search may have unexpected side
effects.

Reviewed by:	ngie, des
Differential Revision:	https://reviews.freebsd.org/D57213
2026-06-04 00:10:08 +02:00
Dag-Erling Smørgrav dfd2273d27 sh: Fix pipebuf limit
Since the factor is not 1, we need to provide a unit.

MFC after:	1 week
Fixes:		5d92f20c7d ("bin/sh: support RLIMIT_PIPEBUF")
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D57352
2026-06-01 10:51:41 +02:00
Jilles Tjoelker be9f353964 Revert "sh/tests: Cut down builtins/read12.0 by 2 seconds"
Dag-Erling Smørgrav does not like this, but I do not understand why.

This reverts commit 1df431576f.
2026-05-25 21:16:52 +02:00
Jilles Tjoelker cc145f5d84 sh/tests: Add a test for long line in history 2026-05-24 19:06:08 +02:00
Kristofer Peterson 95e4fce8f0 bin/sh: Fix history long line truncation/corruption
When reading from standard input with editline history enabled, increase
buffer size to accomodate long lines so that history is recorded
correctly. Cleanup el_gets() handling avoiding potentially dangerous
retention of pointers to editline buffers across calls.  Ensure struct
parsefile objects are properly zero initialised when created. Remove
push argument from setinputstring() and simplify logic as it was always
called with a value of one and as was written was potentially dangerous
if ever called with a value of zero.

This commit does not fix long lines when history is enabled but editing
is not (e.g. if there is no terminal).

MFC after:	3 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2028
Signed-off-by: Kristofer Peterson <[email protected]>
2026-05-24 19:06:07 +02:00
Jilles Tjoelker 1df431576f sh/tests: Cut down builtins/read12.0 by 2 seconds
Since the test assumes a 250 ms response time, there is no need to delay
for 3 seconds. Instead, delay for the minimum possible 1 second.

Also, fix some assertions in builtins/read11.0 and builtins/read12.0. If
`set -e` is in effect, `foo` in `foo && bar` is considered tested and
therefore a failure does not cause the shell to exit.

Reviewed by:	bdrewery
Differential Revision:	https://reviews.freebsd.org/D55191
2026-05-23 21:47:15 +02:00
Dag-Erling Smørgrav 363ea40c76 limits: Further RLIMIT_VMM cleanup
Teach limits(1), sh(1), and setclassresources(3) about RLIMIT_VMM.

Fixes:		1092ec8b33 ("kern: Introduce RLIMIT_VMM")
Reviewed by:	bnovkov
Differential Revision:	https://reviews.freebsd.org/D57031
2026-05-17 18:23:50 +02:00
Konstantin Belousov d7338bb491 bin/sh: make it possible to use as interactive init
If the /sbin/init binary is broken somehow, the way out is to set the
loader environment variable init_path to something else.  The most
natural choice would be either /bin/sh or /rescue/sh.  Unfortunately,
this does not work because the init process starts withoud stdin/out
descriptors.

Make it nicer to users by teaching /bin/sh startup code to open standard
descriptors on /dev/console if the shell is run as init.

Reviewed by:	imp, jilles, zlei
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D56536
2026-04-27 04:45:12 +03:00
Jilles Tjoelker 7262e60119 sh: Allow vfork on redirected simple commands
Things like `{ some_program; } >/dev/null` use vfork, so use vfork
similarly for things like `some_program >/dev/null`.

This cannot be done for command substitutions, because of two problems:

* Redirections might cause the error message for later redirections or
  for an unknown command to be sent to the pipe (to be substituted), and
  this might cause a deadlock if the message is too long.

* The assignment of the pipe needs to come before instead of after the
  redirections.

Reviewed by:	bdrewery
Differential Revision:	https://reviews.freebsd.org/D55190
2026-04-25 15:04:10 +02:00
Nami Arjmandi f3bd86ba18 freebsd-version(1): Disable pathname expansion in -j option
Set the -f flag to sh(1) to disable pathname expansion.
Also, quote the jail variable to ensure correct behavior when passed
to jexec(8).

Signed-off-by:	Nami Arjmandi <[email protected]>
Reviewed by:	pouria
Pull-Request:	https://github.com/freebsd/freebsd-src/pull/2158
2026-04-22 23:25:19 +03:30
Kristofer Peterson 81b2055c49 sh: Increase default history size to POSIX mandated minimum of 128
The default history size in bin/sh is currently 100 however POSIX.1-2024
mandates that a default greater than or equal to 128 shall be used,
therefore this increases the default history size in /bin/sh to 128.

POSIX standards reference:
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/sh.html#tag_20_110_08

MFC after:	3 days
Reviewed by:	emaste, jilles, jlduran, ziaee
Signed-off-by:	Kristofer Peterson <[email protected]>
Closes:		https://github.com/freebsd/freebsd-src/pull/2093
2026-04-13 19:06:41 -04:00
Artem Bunichev b1bc748430 timeout.1: Document non-POSIX options
MFC after:		3 days
Reviewed by:		Aaron Li <[email protected]>, ziaee
Differential Revision:	https://reviews.freebsd.org/D56090
2026-04-13 15:52:21 -04:00
NVSRahul 3570b19d74 uuidgen: generate UUIDs in bounded batches to respect kernel limit
The uuidgen(2) system call enforces a hard upper limit of 2048 UUIDs per
invocation. uuidgen(1) previously attempted to generate arbitrary counts
in a single call and allocated memory accordingly, leading to EINVAL
errors, unnecessary memory usage, and potential overflow risks.

Generate UUIDs in fixed-size batches, streaming output incrementally
while preserving existing semantics. Mirror the kernel limit explicitly
since it is not exposed via a public interface.

Signed-off-by: NVSRahul <[email protected]>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1965
2026-03-07 00:51:16 -07:00
Jamie Landeg-Jones 9006a731bc /bin/ps: Fix display of negative nice values on ARMv7/aarch64
On Arm-based systems (and maybe others), 'char' defaults to unsigned,
causing negative nice values to be displayed incorrectly (e.g., 246
instead of -10). Explicitly using 'signed char' ensures consistent
behaviour across architectures.

[ tested on RPI2 and generic aarch64 qemu install ]

Before:
  # /usr/bin/nice --10 ps -l | awk '(NR == 1 || $(NF-1) == "ps")'
  UID   PID  PPID C PRI  NI  VSZ  RSS MWCHAN  STAT TT     TIME COMMAND
    0 23606 22800 2 -32 246 5400 2544 -       R<+   0  0:00.06 ps -l

After:
  # /usr/bin/nice --10 ps -l | awk '(NR == 1 || $(NF-1) == "ps")'
  UID   PID  PPID C PRI  NI  VSZ  RSS MWCHAN  STAT TT     TIME COMMAND
    0 23614 22800 3 -32 -10 5400 2544 -       R<+   0  0:00.05 ps -l

Signed-off-by: Jamie Landeg-Jones <[email protected]>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/2064
2026-03-07 00:51:14 -07:00
Baptiste Daroussin 5df6aca109 ed: add unicode support for the l (list) command
Use mbrtowc()/iswprint()/wcwidth() in put_tty_line() so that
the l command displays valid multibyte characters as-is instead
of escaping each byte as octal.

Column wrapping now correctly accounts for character display
width (including double-width CJK characters).

Invalid or incomplete UTF-8 sequences and non-printable
characters are still escaped as octal.

Differential Revision:	https://reviews.freebsd.org/D55365
2026-03-01 12:28:29 +01:00
Baptiste Daroussin 7c2c2c2a22 ed: add unicode test cases to ATF test suite
Including examples in Cyrillic suggested by kib@

Differential Revusion:	https://reviews.freebsd.org/D55364
2026-03-01 12:25:16 +01:00