Commit Graph

3894 Commits

Author SHA1 Message Date
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Enji Cooper
e835ee68e1 Link /usr/bin/cpuset to a relative path
This creates an appropriate symlink instead of a potentially incorrect
path pointing to the absolute path for cpuset(8) on the host.

MFC after:	2 weeks
MFC with:	f05948d4e9
Requested by:	imp
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D41419
2023-08-11 04:20:16 -07:00
Enji Cooper
f05948d4e9 cpuset(8): move to /bin/
Summary:
This change moves /usr/bin/cpuset to /bin/cpuset so it is more readily
available on hosts where the /usr partition might not be mounted at the
time / has been mounted.

Remove some complexity from rc.subr(8) since /bin is assumed to always
be present if/when / is mounted.

MFC after:	2 weeks
MFC with:	0661f93892, 271d552379af

Test Plan:
- Test out rc.subr change.
- Confirm that the installation logic does what's needed.

Relnotes:	yes (moving cpuset may impact strict file permissions/mode checking)
Reviewers:	kevans
Subscribers:	imp
Differential Revision: https://reviews.freebsd.org/D40057
2023-08-11 00:49:02 -07:00
Minsoo Choo
3bfbb521fe ls: Improve POSIX compatibility for -g and -n.
- Change -g (ignored for BSD 4.3 compatibility since BSD 4.4)
  to use POSIX semantics of implying -l but omitting the owner's
  name.

- Change -n to imply -l.

The -o option remains unchanged (POSIX defines -o as a complement to
-g that implies -l but omits group names whereas BSD defines -o to add
file flags to -l).  This compromise is the same used by both NetBSD
and OpenBSD.

PR:		70813
Reviewed by:	jhb, Pau Amma <pauamma@gundo.com>
Co-authored-by:	John Baldwin <jhb@FreeBSD.org>
Differential Revision:	https://reviews.freebsd.org/D34747
2023-07-18 10:03:09 -07:00
Martin Matuska
055f920ebe cat: fallback on EBADF with copy_file_range(2)
When stdout is opened with O_APPEND, copy_file_range(2) fails with EBADF.
2023-07-09 01:08:46 +02:00
Martin Matuska
8113cc8276 cat: use copy_file_range(2) with fallback to previous behavior
This allows to use special filesystem features like server-side
copying on NFS 4.2 or block cloning on OpenZFS 2.2.

Reviewed by:	imp, rmacklem
Differential revision:	https://reviews.freebsd.org/D40882
2023-07-08 21:51:15 +02:00
Alfonso Gregory
38f57faa06 cat: ensure serrno is always set
Set serrno to errno before the loop begins for the edge case that res0
is immediately NULL.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/724
2023-07-07 15:56:35 -06:00
Alfonso Gregory
e97468063d Mark usage function as __dead2 in programs where it does not return
In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735
2023-07-07 10:45:17 -06:00
Pedro F. Giffuni
4ef3964b5f bin/date: Upgrade calculations (take 2)
Use uint64_t instead of long, as this type is not correct for platforms like i386 or armv7.

Pointed out by:	imp
2023-07-03 23:39:00 -05:00
Pedro F. Giffuni
4456846a1a bin/date: Upgrade calculations
Use long instead of int for numerous calculations, fixing a number of
date calculation overflow issues.

Obtained from:	DragonflyBSD
Git log:	4238ce6f0c6df33ce677ae298b245c62cd60fb43 (only partial)
2023-07-03 22:08:01 -05:00
Simon J. Gerraty
fcc8d72702 Separate dependencies on tools built for host.
When generated files depend on tools that need to be built for host,
we need to carefully separate them for the DIRDEPS_BUILD so we
only build them once.

Reviewed by:	stevek
Sponsored by:	Juniper Networks, Inc.
2023-06-29 23:52:03 -07:00
Tom Hukins
70bc3f4331 timeout(1): link to related manual pages
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/783
2023-06-26 16:36:25 -06:00
Kyle Evans
781624ca2d getfacl: free acl in print_acl error path
Sponsored by:	Klara, Inc.
2023-06-21 23:58:33 -05:00
Piotr Pawel Stefaniak
14dd001235 sh: also auto-complete built-ins
Reported in a comment in PR 261728.

Reported by:	Oleg
Reviewed by:	jilles (previous version), bapt
Differential Revision:	https://reviews.freebsd.org/D39839
2023-06-19 19:27:20 +02:00
Daniel Kolesa
2178e8c27a sh: make smark a static variable instead of a local in main()
We are modifying it after setjmp and then accessing it after the jump,
so it cannot be a local.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D40415
2023-06-08 23:01:43 +02:00
Daniel Kolesa
fa6fa98ac7 sh(1): initialize smark to zero in main()
As popstackmark may be called on this without pushstackmark having
been called, we need to initialize it so that we don't get a bogus
comparison inside popstackmark, which would have resulted in a
NULL pointer dereference.

MFC After:	3 days
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D40413
2023-06-03 23:09:31 +02:00
Konstantin Belousov
8dad5ece49 dd(1): neutralize SIGINT while non-async-signal safe code is executing
making the SIGINT handler (the terminate() function) safe to execute at
any interruption moment.  This fixes a race in
5807f35c54 where SIGINT delivered right
after the check_terminate() but before a blocking syscall would not
cause abort.

Do it by setting the in_io flag around potentially blocking io syscalls.
If handler sees the flag, it terminates the program.  Otherwise,
termination is delegated to the before_io/after_io fences.

Reviewed by:	Andrew Gierth <andrew@tao146.riddles.org.uk>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D40281
2023-06-03 01:06:27 +03:00
Mateusz Piotrowski
1e078fb602 nproc.1: Fix "first appeared in" details
nproc(1) has been MFC'ed into 13-STABLE and made it into 13.2-RELEASE.

MFC after:	3 days
2023-06-02 18:53:55 +02:00
Mike Karels
1082307434 pwd.1: replace /home with /sys in example
The default location for home directories is moving from /usr/home
to /home, and the /home symlink will no longer exist.  Switch to
another example that is in base, /sys.

Reviewed by:	fernape
Differential Revision:	<https://reviews.freebsd.org/D40204
2023-05-23 07:21:50 -05:00
Baptiste Daroussin
31edf56b15 date: add -z output_zone option
Inpired by OpenBSD date(1), this option allows to do timezone conversion
via the date(1) command.

For example, to determine when the BSDCan livestream begins for me:

$ env -i TZ=EST5EDT date -z Europe/Paris -j 0900

MFC After:		1 week
Reviewed by:		kib, bcr (manpage)
Differential Revision:	https://reviews.freebsd.org/D40159
2023-05-19 21:09:40 +02:00
Piotr Pawel Stefaniak
43489c142e sh: improve style 2023-05-13 21:57:27 +02:00
Warner Losh
b61a573019 spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD
The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:04 -06:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Dag-Erling Smørgrav
5807f35c54 dd: Fix SIGINT handling.
Currently, we handle SIGINT by calling summary() and _exit() directly from the signal handler, which we install after setup().  There are several issues with this:

* summary() is not signal safe;
* the parent is not informed about the signal;
* setup() can block on open(), and catching SIGINT at that stage will produce the correct exit status but will not print anything to stderr as POSIX demands.

Fix this by making SIGINT non-restartable, changing our signal handler to only set a flag, installing it before setup(), and checking the termination flag before and after every blocking operation, i.e. open(), read(), write().

Also add two test cases, one for catching SIGINT while opening the input and one for catching it while reading.  I couldn't think of an easy way to test catching SIGINT while writing (it's certainly feasible, but perhaps not from a shell script).

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	cracauer, ngie, imp
Differential Revision:	https://reviews.freebsd.org/D39641
2023-05-05 12:42:32 +00:00
Dag-Erling Smørgrav
dabef9818f dd: Tidy up the tests.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	ngie
Differential Revision:	https://reviews.freebsd.org/D39711
2023-05-05 12:42:32 +00:00
Ceri Davies
fef74e99fc setfacl.1: correct reference to a trailing comma, should read "colon"
PR:		271063
Reported by:	rdd@rdd.nu
2023-04-29 12:22:52 +01:00
Mateusz Piotrowski
820ac12679 ps: Add libxo to usage message
MFC after:	1 week
Sponsored by:	Klara Inc.
2023-04-25 17:23:07 +02:00
Mateusz Piotrowski
3f46bf40a1 ps: Fix synopsis
In the -L mode, the -L flag is not optional.

MFC after:	3 days
Sponsored by:	Klara Inc.
2023-04-25 17:23:07 +02:00
Mateusz Guzik
c5b5f2d808 cp: Revert "If copy_file_range(2) fails with EXDEV, use fall-back."
This reverts commit 6433365490.

The error is not valid per api contract, it showed up as a regression
after 15f0b8c309

15f0b8c309 ("zfs: merge openzfs/zfs@9cd71c860 (master)") and was
subsequently in d012836fb6 ("zfs: fix up EXDEV handling for
clone_range").

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-04-24 16:04:53 +00:00
Simon J. Gerraty
8fe4f8f7a7 Fix building host tools for host
Several makefile depend on tools built for host.
At least when using DIRDEPS_BUILD we can build these for the
pseudo machine "host" to facilitate building on older host versions.

Ideally we would build these tools in their own directories to avoid
building more than needed.

For now, setting an appropriate default for BTOOLSPATH will suffice

Reviewed by:	stevek
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D39708
2023-04-20 10:05:43 -07:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
John Baldwin
525438ea71 sendmail: Silence -Wdeprecated-non-prototype warnings.
These will hopefully be fixed upstream eventually, but silence the
warnings until then.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D39518
2023-04-18 11:19:48 -07:00
Mateusz Piotrowski
8688532f07 date.1: Make sure that the example works in any locale 2023-04-13 13:02:20 +02:00
Poul-Henning Kamp
6433365490 If copy_file_range(2) fails with EXDEV, use fall-back. 2023-04-04 07:39:59 +00:00
Stefan Eßer
c33db74b53 fs/msdosfs: add tracking of free root directory entries
This update implements tallying of free directory entries during
create, delete,	or rename operations on FAT12 and FAT16 file systems.

Prior to this change, the total number of root directory entries
was reported as number of inodes, but 0 as the number of free
inodes, causing system health monitoring software to warn about
a suspected disk full issue.

The FAT12 and FAT16 file systems provide a limited number of
root directory entries, e.g. 512 on typical hard disk formats.
The valid range of values is 1 to 65535, but the msdosfs code
will effectively round up "odd" values to the next multiple of 16
(e.g. 513 would allow for 528 root directory entries).

This update implements tracking of directory entries during create,
delete, or rename operations, with initial values determined by
scanning the directory when the file system is mounted.

Total and free directory entries are reported in the f_files and
f_ffree elements of struct statfs, despite differences in semantics
of these values:

- There is no limit on the number of files and directories that can
  be created on a FAT file system. Only the root directory of FAT12
  and FAT16 file systems is limited, any number of files can still be
  created in sub-directories, even when 0 free "inodes" are reported.

- A single file can require 1 to 21 directory entries, depending on
  the character set, structure, and length of the name. The DOS 8.3
  style file name takes up 1 entry, and if the name does not comply
  with the syntax of a DOS 8.3 file name, 1 additional entry is used
  for each 13 characters of the file name. Since all these entries
  have to be contiguous, it is possible that a file or directory with
  a long name can not be created, despite a sufficient total number of
  free directory entries.

- Renaming a file can require more directory entries than currently
  allocated to store its long name, which may prevent an in-place
  update of the name if more entries are needed. This may cause a
  rename operation to fail if no contiguous range of free entries for
  the new name can be found.

- The volume label is stored in a directory entry. An empty FAT file
  system with a volume label will therefore show 1 used "inode" in
  df.

- The perceentage of free inodes shown in df or monitoring tools does
  only represent the state of the root directory of a FAT12 or FAT16
  file system. Neither does a reported value of 0% free inodes does
  prevent files from being created in sub-directories, nor does a
  value of 50% free inodes guarantee that even a single file with
  a "long" name can be created in the root directory (if every other
  directory entry is occupied and there are no 2 contiguous entries).

The statfs(2) and df(1) man pages have been updated with a notice
regarding the possibly different semantics of values reported as
total and free inodes for non-Unix file systems.

PR:		270053
Reported by:	Ben Woods <woodsb02@freebsd.org>
Approved by:	mckusick
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D38987
2023-03-29 08:46:01 +02:00
Kyle Evans
822057bfbb pkill: tests: do a pass for case-sensitive conflicts
As in 76b6a59f9d, encode upper-case flag tests with a leading
underbar to avoid collisions (thus, erroneously dirty git repos) on
case-sensitive filesystems.

Sponsored by:	Klara, Inc.
2023-03-20 14:54:54 -05:00
Kyle Evans
3610bffd28 pkill: use an ARG_MAX size buffer for argument matching
Right now pkill/pgrep cut off at _POSIX2_LINE_MAX (2048), but argument
strings can be much larger (ARG_MAX is 256K/512K).  Stop arbitrarily
cutting the search off at 2K, rather than documenting the limit.

Reviewed by:	allanjude (earlier version), des
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D38663
2023-03-20 14:19:36 -05:00
Daniel Kolesa
3ce64010f8 sh(1): fix history file write checking
We cannot just compare histsizeval() against 0, since that returns
a string pointer, which is always non-zero (non-null). The logic
in sethistsize() initializes the history size to 100 with values
that are non-number, and an empty string counts as that. Therefore,
the only time we want to not write into history with HISTSIZE val
set is when it's explicitly 0.

MFC after:	2 weeks
2023-03-20 17:56:56 +01:00
Baptiste Daroussin
4cd30c640d uuidgen(1): fix another typo 2023-03-06 09:03:52 +01:00
Baptiste Daroussin
0ba66872be uuidgen(1): back to the past and fix typo
Reported by:	ceri
2023-03-02 09:37:03 +01:00
Baptiste Daroussin
b2b294f27c uuidgen: add -c for compact uuid
It generates the uuid string but without the hyphen

MFC After:		3 days
Reviews by:		tcberner
Differential Revision:	https://reviews.freebsd.org/D38820
2023-03-01 19:16:25 +01:00
Mateusz Piotrowski
de7a6b6fd0 date.1: Examples: Use syntax that is also compatible with csh
MFC after:	1 month
Sponsored by:	Klara Inc.
2023-02-27 17:37:28 +01:00
Mateusz Guzik
059320b8c8 nproc: denote an incompatiblity with Linux
On Linux _NPROCESSORS_CONF reports CPU threads disabled by the kernel,
while it does not on FreeBSD.

Flip _NPROCESSORS_ONLN to _NPROCESSORS_CONF. While it keeps reporting
the same value, it will automagically unbreak should someone change the
above.
2023-02-15 20:43:46 +00:00
Konstantin Belousov
6957cd86d9 man: some typesetting and style fixes for recent additions
Mostly start each sentence from a new line.  Also add more pretty
typesetting to cdce(4).

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D38501
2023-02-11 19:23:54 +02:00
Mateusz Guzik
48bfd35976 Add nproc(1)
This program prints the number of CPU threads it can run on, while
respecting cpusets (or not, depending on switches).

It aims to be compatible with nproc as found in GNU coreutils.

Reviewed by:	des
Reviewed by:	pstef
Differential Revision:	https://reviews.freebsd.org/D38386
2023-02-08 19:47:33 +00:00
Dag-Erling Smørgrav
8b418c83d1 cp: Adjust the sparse file tests.
* The sparsity check was ineffective: it compared the apparent size in bytes to the actual size in blocks.  Instead, write a tool that reliably detects sparseness.
* Some of the seq commands were missing an argument.
* Based on empirical evidence, 1 MB holes are not necessarily large enough to be preserved by the underlying filesystem.  Increase the hole size to 16 MB.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	cracauer
Differential Revision:	https://reviews.freebsd.org/D38414
2023-02-08 16:49:50 +00:00
Dag-Erling Smørgrav
cb96a0ef00 cp: Minor code cleanup.
* Fix includes in utils.c, cf. style(9).
* Fix type mismatch: readlink(2) returns ssize_t, not int.
* It is not necessary to set errno to 0 as fts_read(3) already does it.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D38369
2023-02-03 16:37:37 +01:00
Mateusz Piotrowski
e7ab133648 timeout: Move from /usr/bin to /bin
timeout(1) is used by /etc/rc.d/zfskeys. Unfortunately, having
timeout(1) installed in /usr/bin causes problems when /usr is an
encrypted ZFS partition.

Implementing timeout(1) in sh(1) is not trivial. A more elegant solution
is to move timeout(1) to /bin so that it is available to early services
in the boot process.

PR:		265221
Reviewed by:	allanjude, des, imp
Approved by:	allanjude, des, imp
Reported by:	Ivan <r4@sovserv.ru>
Fixes:	33ff39796f Add zfskeys rc.d script for auto-loading encryption keys
MFC after:	1 week
Relnotes:	yes
Sponsored by:	Modirum MDPay
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D38344
2023-02-02 18:34:35 +01:00
Dag-Erling Smørgrav
6c85042afc cp: Simplify the common case.
* The allocated buffer is only used in the fallback case, so move it
  there.  The argument for passing it in from the caller was that if
  malloc(3) were to fail, we'd want it to fail before we started
  copying anything, but firstly, it was already not in the right place
  to ensure that, and secondly, malloc(3) never fails (except in very
  contrived circumstances, such as an unreasonable RLIMIT_AS or
  RLIMIT_DATA).

* Remove the mmap(2) option.  It is almost never beneficial,
  especially when the alternative is copy_file_range(2), and it adds
  needless complexity and indentation.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	rmacklem, mav
Differential Revision:	https://reviews.freebsd.org/D38291
2023-02-02 15:46:04 +01:00
Dag-Erling Smørgrav
822fa7ae1e cp: Add tests involving sparse files.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38290
2023-02-02 15:45:55 +01:00
Dag-Erling Smørgrav
c968598479 df: Return non-zero status on write failure.
While here, complete the libxo conversion and switch return value to standard constants.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Differential revision: https://reviews.freebsd.org/D38097
2023-01-17 16:25:28 +01:00
Juraj Lutter
3cf65f8a7f sh(1): Allow non-printing characters in prompt strings
Introduce new prompt format characters:

- '\[' starts the sequence of non-printing chatacters
- '\]' ends the sequence of non-printing characters

Within these sequences, the following characters are now supported:

- '\a' emits ASCII BEL (0x07, 007) character
- '\e' emits ASCII ESC (0x1b, 033) character
- '\r' emits ASCII CR (0x0d, 015) character
- '\n' emits ASCII CRLF sequence

These can be used to embed ANSI sequences into prompt strings.

Example in .shrc:

PS1="\[\e[7m\]\u@\h\[\e[0m\]:\w \\$ "

This tries to maintain some degree of compatibility with GNU bash,
that uses GNU readline library (which behaves slightly different from
BSD editline): It has two "non-printing boundary" characters:

- RL_PROMPT_START_IGNORE (\001)
- RL_PROMPT_END_IGNORE (\002)

while BSD editline only has one (when using EL_PROMPT_ESC setting), so
for this purpose, ASCII \001 was chosen and both \[ and \] emits
this character.

And while here, enlarge PROMPTLEN from 128 to 192 characters.

Reviewed by:		jilles
Approved by:		jilles
Differential Revision:	https://reviews.freebsd.org/D37701
2022-12-22 19:10:48 +01:00
Tobias C. Berner
f176fe8e7f bin/uuidgen: add support for v4 uuids
The version 4 UUID is meant for generating UUIDs from truly-random or
pseudo-random numbers. [1]

bin/uuidgen gained the new flag '-r' to create version 4 UUID.

[1] RFC 4122, https://www.rfc-editor.org/rfc/rfc4122#section-4.4

Reviewed by:		pstef
Approved by:		bapt
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D37695
2022-12-17 10:03:38 +01:00
Ed Maste
67d2aaf078 csh: install hard link with same mode as target
Previously when using NO_ROOT we recorded METALOG entries for the /.cshrc
hard link with a different file mode than the link target, which is not
permitted.

We cannot just set LINKMODE here as it would also apply to the hard link
for the tcsh binary.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37499
2022-11-29 16:04:05 -05:00
Ed Maste
1dbb9994d4 sh: install hard link with same mode as target
Previously when using NO_ROOT we recorded a METALOG entry for the
/.profile hard link with a different mode than the link target, which is
not permitted.

Reviewed by:	bapt
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37476
2022-11-23 15:10:02 -05:00
Aymeric Wibo
e2662256cd ls(1): add a -v flag to sort naturally
Add a -v flag for ls which sorts entries following a natural ordering
using strverscmp(3) (e.g. "bloem1 bloem9 bloem10" as opposed to
"bloem1 bloem10 bloem9").

Update the manual page and add a test case.

Reviewed by:	pauamma, bcr
Tested by:	pstef
Differential Revision:	https://reviews.freebsd.org/D36407
2022-10-31 00:00:42 +01:00
Warner Losh
3b899d5a8f chio: Mark some arguments as unused.
Sponsored by:		Netflix
2022-10-25 10:57:29 -06:00
Dag-Erling Smørgrav
8d7221ca2d sh: when loading profile, read only .sh files.
Reviewers: jilles, eugen_grosbein.net, cy

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D37034
2022-10-22 19:05:31 +02:00
Dag-Erling Smørgrav
d05e43bc0d pax: update date parsing code (from OpenBSD)
Sponsored by:	Klara, Inc.
MFC after:	1 week
2022-10-19 17:02:45 +00:00
Dag-Erling Smørgrav
d3890a547d sh: when loading profile, skip obvious scratch files.
Differential Revision: https://reviews.freebsd.org/D36856
2022-10-03 14:35:51 +00:00
Konstantin Belousov
a7eac01843 stty(1): provide details about interaction with job control
Describe a shell trick to do non-blocking modification of the terminal
settings, by ignoring job control signals with trap built-in.

PR:	266627
With input from:	jilles
Reviewed by:	pauamma
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D36745
2022-10-02 20:29:53 +03:00
Dag-Erling Smørgrav
497cdf9673 sh: read more profile files.
Differential Revision: https://reviews.freebsd.org/D36505
MFC after:	1 month
2022-10-01 21:30:56 +00:00
John Baldwin
10297a9ed4 sh: Fix mismatch in array bounds for vforkexecshell().
Reviewed by:	imp, jilles, emaste
Reported by:	GCC -Warray-parameter
Differential Revision:	https://reviews.freebsd.org/D36760
2022-09-28 14:05:07 -07:00
Dag-Erling Smørgrav
a8e8a91445 pax: name all supported formats.
Sponsored by:	Klara, Inc.
2022-09-13 18:13:19 +02:00
Dag-Erling Smørgrav
0266a5d610 pax: comment typo fixes from NetBSD / OpenBSD.
Sponsored by:	Klara, Inc.
2022-09-13 17:58:59 +02:00
Dag-Erling Smørgrav
30c30e220a pax: remove 4.4BSD compatibility
Sponsored by:	Klara, Inc.
2022-09-13 17:36:37 +02:00
Kirk McKusick
927f8d8bbb Handle NULL return from localtime(3) in ls(1) and find(1)
The ls(1) (with -l option) and find(1) (with -ls option) utilties
segment fault when operating on files with very large modification
times. A recent disk corruption set a spurious bit in the mtime
field of one of my files to 0x8000000630b0167 (576460753965089127)
which is in year 18,266,940,962. I discovered the problem when
running fsck_ffs(8) which uses ctime(3) to convert it to a readable
format. Ctime cannot fit the year into its four character field, so
returns ??? ??? ?? ??:??:?? ???? (typically Thu Nov 24 18:22:48 2021).

With the filesystem mounted, I used `ls -l' to see how it would
report the modification time and it segment faulted. The find(1)
program also segment faulted (see script below). Both these utilities
call the localtime(3) function to decode the modification time.
Localtime(3) returns a pointer to a struct tm (which breaks things
out into its component pieces: year, month, day, hour, minute,
second). The ls(1) and find(1) utilities then print out the date
based on the appropriate fields in the returned tm structure.

Although not documented in the localtime(3) manual page, localtime(3)
returns a NULL pointer if the passed in time translates to a year
that will not fit in an "int" (which if "int" is 32-bits cannot
hold the year 18,266,940,962). Since ls(1) and find(1) do not check
for a NULL struct tm * return from localtime(3), they segment fault
when they try to dereference it.

When localtime(3) returns NULL, the attached patches produce a date
string of "bad date val". This string is chosen because it has the
same number of characters (12) and white spaces (2) as the usual
date string, for example "Sep 3 22:06" or "May 15 2017".

The most recent ANSI standard for localtime(3) does say that localtime(3)
can return NULL (see https://pubs.opengroup.org/onlinepubs/9699919799/
and enter localtime in the search box). Our localtime(3) man page should
be updated to indicate that NULL is a possible return. More importantly,
there are over 100 uses of localtime(3) in the FreeBSD source tree (see
Differential Revision D36474 for the list). Most do not check for a NULL
return from localtime(3).

Reported by:  Peter Holm
Reviewed by:  kib, Chuck Silvers, Warner Losh
MFC after:    2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36474
2022-09-09 14:30:42 -07:00
Alexander Motin
35b7759c05 cp: Fix build without VM_AND_BUFFER_CACHE_SYNCHRONIZED.
It allows to not use mmap() for small files, which is not helpful
in case of ZFS.  Should be no functional change.

MFC after:	1 week
2022-08-30 10:51:21 -04:00
Piotr Pawel Stefaniak
a142345641 sh: nullify ENV in tests
This is to avoid loading .shrc which may contain commands that would
result in output different than expected.

Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D35876
2022-08-20 13:27:42 +02:00
Piotr Pawel Stefaniak
755a1be6d0 sh: accept fc options grouped behind one '-'
As per Utility Syntax Guidelines, accept both forms: -l -n and -ln.

To do that, anticipate the source string for the next option that will
be parsed by nextopt(). It's not always *argptr, sometimes it is
nextopt_optptr.

To simplify the check for not_fcnumber, slightly modify nextopt() to
always nullify nextopt_optptr in cases where it would have been set
to point to a NUL character.

Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D35836
2022-08-20 13:26:05 +02:00
Jens Schweikhardt
825225e52f For man page references found in ports, indicate the respective port. 2022-08-14 15:02:06 +02:00
Gordon Bergling
b131efe3e5 sh.1: Fix a mandoc warning
- new sentence, new line

MFC after:	3 days
2022-07-31 16:23:27 +02:00
Kyle Evans
4148dffadd date: remove some ambiguity in tzdata references
The use of 'package' in this could be understood to mean a FreeBSD
package provided by pkg, rather than the fact that we use data provided
by IANA.  Re-word it to clearly identify `tzdata` as the IANA Time Zone
Database on first use, then drop subsequent uses of the word 'package'.

Reviewed by:	0mp, pauamma, philip
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D35966
2022-07-28 10:14:18 -05:00
Kyle Evans
9fcac31db4 date: attempt to more accurately describe year limitations with -v
The previous description was both incorrect and incomplete in its
description -- the 2038 limit doesn't apply on !i386 platforms, and
it didn't note that values above 100 are accepted and interpreted
differently.  Further, it didn't note that absolute years are accepted.

Reviewed by:	pauamma_gundo.com (manpages)
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D35360
2022-06-27 22:54:13 -05:00
Mateusz Piotrowski
d46d907a26 sleep.1: Fix mdoc style
Fixes:	be038c3afc bin/sleep: add support for multiple delay values
MFC after:	1 week
2022-05-25 10:11:33 +02:00
Warner Losh
f5dcfbe36e stty: Remove stray '-'.
There's a stray '-' that causes Fl to double the dash, but that's not
how the command works.

MFC After:		2 days
Sponsored by:		Netflix
2022-05-24 14:31:28 -06:00
Stefan Eßer
81cea61f3b bin/sleep: document more non-standard features
Add support of other time units than seconds to the IMPLEMENTATION
NOTES section of the man page.

MFC after:	1 week
2022-05-24 11:31:21 +02:00
Stefan Eßer
be038c3afc bin/sleep: add support for multiple delay values
The sleep time is calculated as the sum of all arguments passed.

This makes the FreeBSD version of sleep functionally compatible with
the version in GNU coreutils.

MFC after:	1 week
2022-05-24 10:47:40 +02:00
A. Mallory
34978f7edd bin/sleep: add support for units other than seconds
The coreutils version of this command accepts a unit designation of s,
m, h, or d (for seconds, minutes, hours, days) immediately following
the number of (fractional) units to delay.

The submitted patch has been modified in one detail: the test meant to
detect the presence of the unit modified was not specific (!= 1) and
would have accepted a non-numeric initial element or extra characters
following the union. The committed version accepts only the number
immediately followed by one of the defined unit designators and no
further characters.

PR:		264162
MFC after:	1 week
2022-05-24 09:43:38 +02:00
Gordon Bergling
ffedb32dd3 pax(1): Remove a few double words in source code comments
- s/an an/an/

MFC after:	3 days
2022-04-09 14:27:39 +02:00
Kyle Evans
f00f8b4fbd 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.
Differential Revision:	https://reviews.freebsd.org/D34655
2022-04-05 20:41:00 -05:00
Greg Lehey
8deef88628 Correct source markup. No change to output.
Reported by:	0mp@
2022-03-30 14:55:28 +11:00
Greg Lehey
8e4b069f45 Remove reference to kernel clock time zone.
Add references.

Reported by:	philip@
2022-03-30 14:42:14 +11:00
Piotr Pawel Stefaniak
68700941c7 sh: fix autocompletion for commands that share name with a directory
Provide libedit a special function making it always add a space after
the autocompleted command. The default one adds a slash if the word is
also a name of a directory in the current working directory, but this is
wrong for commands.

Reviewed by:	bapt, jilles
Differential Revision: https://reviews.freebsd.org/D34544
2022-03-28 08:45:03 +02:00
Greg Lehey
3c9f304b38 Describe modern time zone handling.
Reviewed by:	peterj@
MFC after:	2 weeks
2022-03-28 14:57:37 +11:00
Alfonso
3322d1c0e2 ps(1): Use calloc instead of malloc and memset.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/546
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-03-11 10:36:00 +01:00
Baptiste Daroussin
2eee44bd5e df: do not report a 100% full inode usage on fs without inodes
Before:
devfs    2        2         0   100%       0          0  100%   /dev

After:
devfs    2        2         0   100%       0          0     -   /dev

The previous behaviour was confusing for end users and many monitoring tools

Note the linux df tools is also using the same syntax '-' for such filesystem

MFC After:		2 weeks
Reviewed by:		manu, emaste, imp
Differential Revision:	https://reviews.freebsd.org/D34515
2022-03-11 08:49:44 +01:00
Cameron Katri
97e1303791 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
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D30012
2022-02-23 12:55:13 -06:00
Kyle Evans
33ad990ce9 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.

Sponsored by:	Klara, Inc.
Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D34063
2022-02-22 16:06:02 -06:00
Stefan Eßer
f0fd4a32c4 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.

PR:		260921
Approved by:	imp
Relnotes:	yes
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D33748
2022-02-10 21:09:34 +01:00
Kyle Evans
848263aad1 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.
Differential Revision:	https://reviews.freebsd.org/D33944
2022-01-27 12:02:17 -06:00
Jilles Tjoelker
5a1a07f2a0 sh: Don't add something to a null pointer
Pointer arithmetic on a null pointer is undefined behavior.

The bug can be reproduced by running bin/sh/tests/builtins/wait6.0 with
UBSAN.

Reported by:	Mark Millard
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D34011
2022-01-26 23:13:20 +01:00
Emmanuel Vadot
4991269369 pkgbase: Create a FreeBSD-csh package
Now that root uses /bin/sh as the default shell no need to have csh part
of runtime.
Put it in its own package.

MFC after:	never
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33471
2021-12-21 10:17:50 +01:00
Emmanuel Vadot
5abb10faa1 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
2021-12-21 10:17:22 +01:00
Bryan Drewery
971677d5fd sh: Avoid some headers when NO_HISTORY is set.
This is more simpler compatibility with using this source on older
systems before libedit was made to install filecomplete.h in
commit b315a7296d.
2021-11-24 17:53:39 -08:00
Hans Petter Selasky
4c537df51a echo(1): Replace errexit() with err(3)
Differential revision:	https://reviews.freebsd.org/D32501
Submitted by:	christos@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2021-11-09 22:12:19 +01:00
Mateusz Piotrowski
c537bf9d59 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
2021-11-03 14:09:36 +01:00
Mateusz Piotrowski
a12b16f48f date: Clean up synopses
MFC after:	3 days
2021-11-03 14:09:36 +01:00
Mateusz Piotrowski
00133d5c5e 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
2021-11-03 14:09:18 +01:00
Jilles Tjoelker
72f750dc7c sh: Fix heredoc at certain places in case and for
After an unescaped newline, there may be a here-document. Some places in
case and for did not check for one.

Reviewed by:	bdrewery
Differential Revision:	https://reviews.freebsd.org/D32628
2021-10-27 21:05:19 +02:00
Ka Ho Ng
fcfa64801a 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
MFC after:	3 days
Reviewed by:	jilles, emaste
Differential Revision:	https://reviews.freebsd.org/D27003
2021-10-26 22:50:09 +08:00
Baptiste Daroussin
f3aad18d5e sh(1): fix home/del key on mobaxterm env
For $reason mobaxterm default on sending unusual sequence from home/del
key, which makes libedit unabel to catch them and bind them correctly.

mobaxterm seems popular on the windows environment, so add proper
keybinding to default shrc configuration so it works out of box.

Reported by:	lme
2021-10-20 14:00:20 +02:00
Baptiste Daroussin
ef0d94a3d3 sh(1): interactive mode improvement
In the default configuration add 2 bindings which has been requested by
many during the HEADSUP discussion:
* csh like arrow history navigation
* ctrl-arrow to jump from word to words

Add an alias to make the history command exist as an alias to fc -l.
2021-10-20 09:33:04 +02:00
Elyes HAOUAS
3fe686f25a 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>
2021-10-02 10:39:37 -06:00
Elyes HAOUAS
8db446034e 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>
2021-10-02 10:39:34 -06:00
Elyes HAOUAS
28c3c137f6 src/bin/mkdir: Spell occur correctly.
Pull Request: https://github.com/freebsd/freebsd-src/pull/544
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2021-10-02 10:39:31 -06:00
Elyes HAOUAS
48556dff3d src/bin/sh: Fix spelling errors
Pull Request: https://github.com/freebsd/freebsd-src/pull/544
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2021-10-02 10:39:24 -06:00
Faraz Vahedi
f54b18fc4d 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
2021-10-01 13:50:56 -05:00
Kyle Evans
33c1e7271a 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.
2021-09-25 00:03:50 -05:00
Math Ieu
bf27a2253f ps: fix ps -aa
Passing the -a flag multiple times made ps show no processes.

Differential Revision:	https://reviews.freebsd.org/D27215
2021-09-24 21:19:52 +02:00
Bryan Drewery
e31fb97148 read builtin: Empty variables on timeout
This matches how a non-timeout error is handled.

Reviewed by:	jilles
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D31876
2021-09-24 11:34:54 -07:00
Stephane Rochoy
d2c233176f sh: Add -o verify to use O_VERIFY when sourcing scripts
Add -o verify to sh to make it use O_VERIFY when
sourcing scripts and reading profiles.

Useful in conjunction with mac_veriexec to help protect at
least some parts of the boot sequence, e.g., /etc/rc*.

Differential revision:	https://reviews.freebsd.org/D30464
Reviewed by:		jilles, sjg
Obtained from:		Stormshield
2021-09-23 10:43:09 +02:00
Piotr Pawel Stefaniak
1f82fb3834 sh: try to avoid overwriting HISTFILE produced by other shells
If an attempt to load history from an existing history file was
unsuccessful, do not try to save command history to that file on exit.
2021-09-22 22:23:32 +02:00
Piotr Pawel Stefaniak
c866d0c798 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.
2021-09-22 22:23:32 +02:00
Piotr Pawel Stefaniak
9413dfd331 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].
2021-09-22 10:54:51 +02:00
Baptiste Daroussin
908b8e32f9 sh: remove emacs improvements that are now defaults in libedit 2021-09-22 10:27:10 +02:00
Cameron Katri
97c31821eb 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
2021-09-19 13:52:12 +02:00
Piotr Pawel Stefaniak
b8ff849cbd 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.
2021-09-19 13:51:45 +02:00
Baptiste Daroussin
3ae61b972b sh: improve emacs mode
in emacs mode ^W should delete the previous word by default
Note that upstreaming this change directly into libedit is in process.

Reported by:	manu
Reviewed by:	jills, pstef, manu
Differential Revision:	https://reviews.freebsd.org/D29493
2021-08-28 16:11:57 +02:00
Gleb Popov
fcef0684f1 Fix build of bin/getfacl after libc changes.
Reviewed by: kib, debdrup, gbe
Approved by: kib
Differential Revision: https://reviews.freebsd.org/D28255
2021-08-27 11:52:18 +03:00
Piotr Pawel Stefaniak
ced2dcadcc ls: prevent no-color build from complaining when COLORTERM is non-empty
As 257886 reports, if ls(1) is built with WITHOUT_LS_COLORS="YES", it
issues a warning whenever COLORTERM is non-empty. The warning is not
useful, so I thought to remove it, but as Ed pointed out, we may want
to have a way to determine whether a particular copy of ls has been
compiled with color support or not.

Therefore move the warnx() call to the getopt loop in
a WITHOUT_LS_COLORS build to fire when the user asks for colored output.

PR:		257886
Reported by:	Marko Turk
Reviewed by:	kevans
2021-08-19 21:22:16 +02:00
Piotr Pawel Stefaniak
35b253d9d2 sh: fix NO_HISTORY build
Move code added in b315a7296d ("autocomplete commands") to
conditionally compiled part under #ifndef NO_HISTORY.

Reported by:	bdrewery
Fixes:		b315a7296d
2021-08-19 06:57:06 +02:00
Mateusz Guzik
570b31f610 df: remove the unused fstype var
Found with cc --analyze

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-07-20 19:00:50 +02:00
Alex Richardson
2423585b1d 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
2021-07-19 15:04:09 +01:00
Kyle Evans
db0f264393 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.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D30835
2021-07-18 23:06:19 -05:00
Kyle Evans
46438b5366 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.

Suggested by:	imp
Reviewed by:	imp, jhb
Differential Revision:	https://reviews.freebsd.org/D30836
2021-07-18 23:05:30 -05:00
Emmanuel Vadot
2c733106ae 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-19 17:49:44 +02:00
Ceri Davies
3e4946f0aa date.1: Remove mention of -d and -f flags
These flags were removed in 2019.

PR:		256631
Submitted by:	David Fiander <david@fiander.info>
MFC After:	3 days
2021-06-16 09:18:56 +00:00
Baptiste Daroussin
988b1bb0c5 sh: implement persistent history storage
Implement persistent history storage:
the strategy is simple at start: loads the existing .sh_history file
at exit dump it.

The implementation respects the HISTFILE variable and its POSIX
definition: ~/.sh_history is used if HISTFILE is not set.

to avoid sh to create the history file, set HISTSIZE to 0 or HISTFILE to
en empty value

Co-authored-by:	pstef
Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D29493
2021-05-10 18:57:13 +02:00
Piotr Pawel Stefaniak
1a4e959eb3 sh: fix debug build
Approved by:	jilles
2021-04-11 09:23:14 +02:00
Gordon Bergling
3ce579325e ed(1): Add two references in the SEE ALSO section
Obtained from:	OpenBSD
MFC after:	1 week
2021-04-09 09:43:49 +02:00
Piotr Pawel Stefaniak
5a18515b31 sh: silence sanitizer
Don't add 0 to a null pointer.
Reviewed by:	jilles
2021-04-01 07:31:03 +02:00
Baptiste Daroussin
660045fb53 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.

MFC after:		1 week
Approved by:		jilles
Reviewed by:		jilles, arichardson, pstef
Differential Revision:	https://reviews.freebsd.org/D29494
2021-03-30 23:49:03 +02:00
Piotr Pawel Stefaniak
b315a7296d sh(1): autocomplete commands
Without this patch, sh can autocomplete file names but not commands from
$PATH. Use libedit's facility to execute custom function for autocomplete,
but yield to the library's standard autocomplete function when cursor is
not at position 0.

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D29361
2021-03-29 11:14:27 +02:00
Alex Richardson
5ff2e55e00 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
2021-02-13 13:53:51 +00:00
Baptiste Daroussin
45b252fc91 cp: fix indentation
No functional changes
2021-01-27 12:18:45 +01: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