Commit Graph

3894 Commits

Author SHA1 Message Date
Ganael Laplanche
681fd2bed8 pax: Terminate loop for empty directory names
Pax can sometimes loop forever. For example:

$ mkdir -p /tmp/src/foo/bar
$ rm -rf /tmp/dst ; mkdir -p /tmp/dst
$ cd /tmp/src
$ echo 'foo/bar/' | /bin/pax -r -w -d -pe "/tmp/dst"
<looping infinitely>

Here, pax(1) infinitely deletes and re-creates /tmp/dst/foo/bar/.

The problem is that chk_path() (bin/pax/file_subs.c), called from
node_creat() also creates the leaf directory when a trailing '/' appears
in the directory name to create. When the execution goes back from
chk_path() to node_creat(), the function still cannot create the leaf
directory (it has been created by chk_path()), so it unlinks it and
calls node_creat() again. The function re-creates it, and so on...

In node_creat() detect trailing slashes and not create a leaf directory,
but only intermediate ones.

PR: 277060
Reviewed by: imp
2024-06-21 10:39:09 -06:00
Emmanuel Vadot
dcb65c5a94 csh: Remove hardlink /.cshrc
Remove this historical artifact.
csh will try to use /.csrch if the user has no home directory defined which
is rather unlikely (To be exact if the concatenation of $HOME and "/.cshrc"
fail which is the same thing).

Also, with this change pkg will happily handle 3way merge for /root/.cshrc

Differential Revision:	https://reviews.freebsd.org/D45382
Reviewed by:		emaste, imp
Sponsored by:		Beckhoff Automation GmbH & Co. KG
2024-05-29 09:56:58 +02:00
Pierre Pronchery
3d7c8f0887 cp: avoid a resource leak
In copy_file(), make sure the from_fd file descriptor is closed even
when the operation failed early.

Reported by:	Coverity Scan
CID:		1545036
Sponsored by:	The FreeBSD Foundation

Reviewed by: imp, emaste
Pull Request: https://github.com/freebsd/freebsd-src/pull/1238
2024-05-23 12:04:43 -06:00
Alexander Ziaee
1a720cbec5 man filesystems: fix xrefs after move to section 4
Reviewed by: des, imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1077
2024-05-16 10:25:29 -06:00
Henrich Hartzer
9bcc1b18c1 /bin/rmdir: Exit with status 2 for invalid arguments
PR: 277677

Signed-off-by: Henrich Hartzer <henrichhartzer@tuta.io>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1161
2024-05-11 13:13:28 -06:00
Dag-Erling Smørgrav
ad4f3bdf73 cat: Missed a couple.
MFC after:	3 days
Sponsored by:	Klara, Inc.
2024-05-10 13:05:45 +02:00
Dag-Erling Smørgrav
c6f9df7064 cat: Check for lack of success rather than a specific failure.
MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	oshogbo
Differential Revision:	https://reviews.freebsd.org/D45149
2024-05-10 12:59:30 +02:00
Jamie Landeg-Jones
3f0b80bc15 ps: handle incorrect -D values
I just noticed a slight issue with the '-D' option. Basically,
I accidentally typed something along the lines of:

ps -Dboth-p303

I.E. missing out the "space". Instead of giving an error, it behaved as
if I'd just typed "ps".

Looking at bin/ps/ps.c, where the -D option is parsed, it doesn't
error-out if there is no valid match.

This commit fixes the bug.
2024-05-06 19:13:35 +02:00
Mateusz Piotrowski
c40e0bff72 date.1: Note that nanosecond support is to appear first in 14.1
Sponsored by:	Klara, Inc.
2024-05-02 22:48:08 +02:00
Dag-Erling Smørgrav
dafb424b8d date: Correctly check outcome of mktime().
X-MFC-With:	7b390cb636
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D44982
2024-04-28 19:12:58 +02:00
Fernando Apesteguía
6e74b603fc uuidgen(1): Add EXAMPLES to manual page
Approved by:		manpages@ (gbe@)
Reviewed by:		gbe@, pauamma
Differential Revision:	https://reviews.freebsd.org/D43494
2024-04-27 20:53:59 +02:00
Mateusz Piotrowski
7b390cb636 date: Fix tests by initializing timespec structure
The tests related to nanosecond support were failing on amd64 due to
uninitialized timespec structure.

Fixes:		eeb04a736c date: Add support for nanoseconds
Reviewed by:	markj
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D44975
2024-04-26 17:32:57 +02:00
Mateusz Piotrowski
eeb04a736c date: Add support for nanoseconds
This patch introduces support for a conversion specification for
nanoseconds.

The format of %N is meant to be compatible with that of GNU date.

The nanoseconds conversion specification is implemented directly in
date(1) instead of libc (in strftime(3)) to avoid introducing
non-standard functions to libc at this time and modifying struct tm.

Apart from introducing the nanoseconds conversion specification, this
patch brings the following changes:

- The "ns" format for ISO 8061 dates is now unlocked. E.g., date -Ins
  prints:
      2024-04-22T12:20:28,763742224+02:00
- The -r flag when fed a file is now aware of the nanosecond part of the last
  modification time.
- date(1) is now able to set the time with nanosecond precision. It is
  not possible as of now to do that by specifying nanoseconds directly
  via the command-line arguments. Instead, the -r flag can be used.
- date(1) is now using the clock_gettime(3) family of functions instead
  of ctime(3) family of functions where possible.

Reviewed by:	des, markj
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D44905
2024-04-26 11:26:50 +02:00
Mateusz Piotrowski
177ba18307 sync.8: Document that the "sync dance" is not a thing
People still believe that it is essential to run sync(8) a couple of
times before a reboot/halt. Document that this has not been necessary
for a long time now.

Reviewed by:	imp, bcr, Pau Amma <pauamma@gundo.com>
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D33233
2024-04-25 11:49:50 +02:00
Dag-Erling Smørgrav
f070188c3a cp: Use warnc().
MFC after:	1 week
Sponsored by:	Klara, Inc.
2024-04-17 04:08:38 +02:00
Dag-Erling Smørgrav
9075d4cfad cp: Additional sanity check.
Once we've successfully opened the file we've been asked to copy, check
that it's of the same type as FTS told us it was.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude, markj
Differential Revision:	https://reviews.freebsd.org/D44806
2024-04-17 04:03:28 +02:00
Dag-Erling Smørgrav
64d6925d19 cp: Clarify an obscure comment.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D44805
2024-04-17 04:03:21 +02:00
Ricardo Branco
428f86fd2f mv: Set file flags after setting file times
Some file flags prevent modification of file times, so they should be
set later.  This matches NetBSD's behaviour.

Reviewed by:	markj
MFC after:	1 week
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1138
2024-04-16 09:18:15 -04:00
Collin Funk
606c37c541 nproc: Prefer sys/cdefs.h __unreachable over the builtin
The __builtin_unreachable macro provided by Clang and GCC is a hint to
the compiler used for optimization. The programs work fine even if the
compiler doesn't support it. The sys/cdefs.h has had __unreachable for
9 years (commit 732b31de5d). It expands
to the builtin if it is available. In the rare case that it is
unsupported it expands to a null statement so compilation does not
fail.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Reviewed by: imp, freebsd@igalic.co
Pull Request: https://github.com/freebsd/freebsd-src/pull/1117
2024-04-12 16:39:05 -06:00
Dag-Erling Smørgrav
0729d1e8fd cp: Never follow symbolic links in destination.
Historically, BSD cp has followed symbolic links in the destination
when copying recursively, while GNU cp has not.  POSIX is somewhat
vague on the topic, but both interpretations are within bounds.  In
33ad990ce9, cp was changed to apply the same logic for symbolic
links in the destination as for symbolic links in the source: follow
if not recursing (which is moot, as this situation can only arise
while recursing) or if the `-L` option was given.  There is no support
for this in POSIX.  We can either switch back, or go all the way.

Having carefully weighed the kind of trouble you can run into by
following unexpected symlinks up against the kind of trouble you can
run into by not following symlinks you expected to follow, we choose
to go all the way.

Note that this means we need to stat the destination twice: once,
following links, to check if it is or references the same file as the
source, and a second time, not following links, to set the dne flag
and determine the destination's type.

While here, remove a needless complication in the dne logic.  We don't
need to explicitly reject overwriting a directory with a non-directory,
because it will fail anyway.

Finally, add test cases for copying a directory to a symlink and
overwriting a directory with a non-directory.

MFC after:	never
Relnotes: 	yes
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44578
2024-04-09 00:41:33 +02:00
Fernando Apesteguía
7e68976408 echo(1): Add EXAMPLES
While here add CAVEAT section and promote the use of printf(1)

Reviewed by:		gbe@, imp@
Approved by:		manpages (gbe)
Differential Revision:	https://reviews.freebsd.org/D43493
2024-04-08 18:35:40 +02:00
Dag-Erling Smørgrav
bee7cf9e97 ln: Improve link(1) variant of ln(1).
* Give link(1) its own usage message.
* Use getprogname(3) instead of rolling our own.
* Verify that the target file does not already exist.
* Add tests specific to link(1).

MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D44635
2024-04-04 16:14:50 +02:00
Dag-Erling Smørgrav
dd286b0dc1 cp: Improved conformance when copying directories.
* When copying a directory, if the destination exists and is not a
  directory, we would previously emit an error message and exit.  The
  correct behavior according to POSIX is to emit an error message and
  continue without descending further into the source directory.

* When copying a directory, if the destination does not exist and we
  fail to create it, we would previously emit an error message and
  exit.  The correct behavior according to POSIX is to emit an error
  message and continue.  Whether to descend further into the source
  directory is explicitly left unspecified; GNU cp does not, which
  seems to me to be the safer and less surprising option, so let's not
  either.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44577
2024-04-01 19:29:31 +02:00
Dag-Erling Smørgrav
aaa1806f68 cp: Correct the list of non-portable flags.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44576
2024-04-01 19:29:31 +02:00
Dag-Erling Smørgrav
5aaef5a600 cp: Fix grammar in comment.
This reverts commit 416fdc2d71.
2024-03-28 15:09:45 +01:00
Stephen J. Kiernan
a6d8dcb0d9 csh: Use HOST_CC when compiling hostprog used by csh build
The "gethost" program should be built with the host compiler.

Obtained from:	Juniper Networks, Inc.
Reviewed by:	sjg
Differential Revision:	https://reviews.freebsd.org/D44537
2024-03-27 18:21:50 -04:00
Dag-Erling Smørgrav
2ae8d34666 ln: Add a test case for ln -sfF.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude, asomers
Differential Revision:	https://reviews.freebsd.org/D44513
2024-03-27 11:03:56 +01:00
Dag-Erling Smørgrav
e0afcbc856 ln: Clean up and simplify tests.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D44512
2024-03-27 11:03:52 +01:00
Dag-Erling Smørgrav
437d53daf7 ln: Use stdbool, style nits.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	imp, allanjude
Differential Revision:	https://reviews.freebsd.org/D44511
2024-03-27 11:03:49 +01:00
Dag-Erling Smørgrav
2295cae7e6 sleep: Overhaul.
Program:

* Add a dummy getopt(3) loop to handle `--`.
* Move interval parsing out into a separate function.
* Print a diagnostic for every invalid interval.
* Check for NaN and infinity.
* Improve bounds checks.

Manual page:

* Miscellaneous markup fixes.
* Reword DESCRIPTION section.
* Move text about GNU compatibility to STANDARDS section.
* Convert examples from csh to sh.

Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44471
2024-03-25 16:59:02 +01:00
Collin Funk
8b86415185 cp: Remove useless ssize_t cast
Both wcount and wresid are ssize_t so this cast is not needed. Just
remove it so the code is easier to read.

Signed-off-by:	Collin Funk <collin.funk1@gmail.com>
Reviewed by:	emaste, zlei
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1116
2024-03-21 11:43:04 -03:00
Olivier Cochard
161984ade1 tests: Fixing incomplete atf_skip if missing jail condition
Testing the scripts outside kyua(1) was a bad idea:
It didn't allow me to detect that they were faulty.

Sponsored by:	Netflix
2024-02-23 13:08:09 +01:00
Olivier Cochard
3562b7b1eb hostname(1): skip test if jail binary is missing
Approved by:	lwhsu
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D44005
2024-02-23 10:46:34 +01:00
Gordon Bergling
ffea732c51 ls.1: Mention CLICOLOR environment variable
Mention CLICOLOR environment variable in the manual page.

PR:	276556
Submitted by:	bsdcode at disroot dot org
Reviewed by:	imp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D43970
2024-02-21 11:54:58 +01:00
Warner Losh
ef75877fc2 ls: Fix -v and associated test
The cleanup of d854370fa8 had a cut and paste error (so f_verssort
was set to 1 and then to 0 rather thame f_timesort being set to 0).

Fixes: d854370fa8
Sponsored by: Netflix
2024-02-19 09:50:04 -07:00
Ed Maste
05f530f4d2 cat: fix cap_rights_init usage
Capability rights passed to cap_rights_* are not simple bitmaks and
cannot be ORed together in general (although it will work for certain
subsets of rights).

PR:		277057
Reported by:	asomers, markj
2024-02-14 19:37:54 -05:00
Chia-Jung Chang
90405e1d63
domainname(1): Grammar fix
Event:		Advanced UNIX programming course (Fall'23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1038
2024-02-13 19:13:33 +08:00
Chia-Jung Chang
26cf4a61f6
hostname(1): Grammar fix
Event:		Advanced UNIX programming course (Fall'23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1037
2024-02-13 19:02:17 +08:00
Chia-Jung Chang
8e9fc2d9f6
date(1): Grammar fixes
Event:		Advanced UNIX programming course (Fall'23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1035
2024-02-13 19:00:59 +08:00
Chia-Jung Chang
416fdc2d71
cp(1): Grammar fix in comment
Event:		Advanced UNIX programming course (Fall'23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1033
2024-02-13 18:53:50 +08:00
Chia-Jung Chang
304f52ad1b
df(1): Fix grammar
Event:		Advance UNIX programming course (Fall'23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1027
2024-02-13 18:31:05 +08:00
Chia-Jung Chang
a400e25904
ed(1): Fix grammar in comment
Event:		Advanced UNIX programming course (Fall'23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1025
2024-02-13 17:55:54 +08:00
HUNG-CHI CHANG
711a74e19f
pax(1): Grammar fix in file_subs.c
Event:		Advanced UNIX Programming Course (Fall’23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/999
2024-02-13 15:09:32 +08:00
Fu-Cheng Wang
3cddabf0bd
sh(1): Grammar fix in jobs.c
Event:		Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/992
2024-02-13 14:13:08 +08:00
Wilbert Allen Koeswoyo Suwito
84886bf93a
ed(1): Grammar fixes
- Adding a missing verb "is" on line 723
- Changing is to are on line 835

Event:		Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/986
2024-02-13 12:42:54 +08:00
Wilbert Allen Koeswoyo Suwito
8b6876e136
chio(8): Fix typo in the copyright section
Event:		Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/978
2024-02-13 12:38:27 +08:00
Alexander Ziaee
d854370fa8 ls: versort incompatible w/ timesort and sizesort
ls.1: versort incompatible w/ timesort and sizesort

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/825
2024-02-02 13:19:10 -07:00
Konstantin Belousov
2954af09f1 chflags(1): obey siginfo request on chflagsat(2) failure
Note that the error diagnostic can now be printed both to stderr due to
the absence of the -f flag and to stdout due to SIGINFO simultaneously.

Noted and reviewed by:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-01-30 22:21:55 +02:00
Ricardo Branco
fae467c221 chflags(1): Fix -f option
As stated in the man page, -f must not emit warning on error, and must
not set the utility exit code.

PR:	276723
Github PR:	https://github.com/freebsd/freebsd-src/pull/1088
Reviewed by:	imp, kib
MFC after:	1 week
2024-01-30 19:08:03 +02:00
Lin Lee
73974a78f7
hostname(1): Add test cases
Sponsored by:	The FreeBSD Foundation
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1069
2024-01-30 11:26:57 +08:00