Commit Graph

3739 Commits

Author SHA1 Message Date
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