Commit graph

10264 commits

Author SHA1 Message Date
Kenny Levinsen
da9e73e5d4 wordexp(3): Handle ECHILD from waitpid
If the calling process has used SIG_IGN as handler or set the
SA_NOCLDWAIT flag for SIGCHLD, processes will be automatically reaped on
exit and calls to waitpid(3) will therefore fail with ECHILD.

We waitpid primarily to reap our child so that the caller does not have
to worry about it. ECHILD indicates that there is no child to reap, so
we can just treat that as a success and move on.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
Tested by: Jan Beich
Pull Request: https://github.com/freebsd/freebsd-src/pull/1675
2025-07-08 23:27:33 +02:00
Dag-Erling Smørgrav
c08e019c6c opendir, fdopendir: Add tests, clean up.
* Add test cases for opendir() and fdopendir().
* Drop O_NONBLOCK from opendir(); it was added a long time ago to avoid
  blocking if given a closed named pipe, but now we use O_DIRECTORY,
  which ensures that we get ENOTDIR in that case.
* While here, remove unused #includes left over from the split.

Sponsored by:	Klara, Inc.
Reviewed by:	kevans, markj
Differential Revision:	https://reviews.freebsd.org/D51126
2025-07-08 21:41:21 +02:00
Konstantin Belousov
72c848089f libc: only append exterr herald and text if exterr was recorded
__uexterr_format: return empty string on no error, instead of "No error"
err(): check for the first symbol of the exterr to decide if there is
anything to print.

Requested and reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D51204
2025-07-08 18:55:54 +03:00
Ricardo Branco
9911028f53 libc: mkostemp(3) should support O_CLOFORK
Reviewed by:	kib, markj
MFC after:	1 month
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1758
2025-07-08 15:43:39 +00:00
Konstantin Belousov
01a679715f err(3): print extended error if available
Reviewed by:	asomers, brooks
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D51141
2025-07-07 21:44:22 +03:00
Konstantin Belousov
283c1bd8ce uexterr_format(): simplify output when ext error string is available
If the extended error string is provided by kernel, return only the
string, which is supposedly enough to identify exact cause of the error.
If the string is not provided, print the technically looking gibberish
which still allows to identify location with kernel sources.

Reviewed by:	asomers, brooks
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D51141
2025-07-07 21:44:14 +03:00
Ricardo Branco
efadb5c2a9 Add manpages for O_CLOFORK flag and others
Reviewed by:	kib
MFC after:	1 month
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1698
2025-07-06 23:08:41 +00:00
Ricardo Branco
971f738679 kern: Make dup3() support O_CLOFORK
Reviewed by:	kib
MFC after:	1 month
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1698
2025-07-06 23:08:37 +00:00
Mark Johnston
245ff4c4b2 libc: Add inotify support
inotify_init() and inotify_init1() are implemented using __specialfd(2).
inotify_add_watch() is implemented in terms of inotify_add_watch_at(2).

Reviewed by:	kib
MFC after:	3 months
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D50315
2025-07-04 14:42:33 +00:00
Dag-Erling Smørgrav
5e96f4006d opendir: Simplify is_unionstack().
Sponsored by:	Klara, Inc.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D51118
2025-07-02 12:22:29 +02:00
Dag-Erling Smørgrav
8d02b7190d fts: Add test cases for unreadable directories.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D51098
2025-07-02 12:22:29 +02:00
Dag-Erling Smørgrav
bc624c9735 fts: Clarify what FTS_DNR is used for.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D51097
2025-07-02 12:22:29 +02:00
Dag-Erling Smørgrav
8ebc076866 scandir: Code cleanup.
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D51050
2025-06-26 09:37:06 +02:00
Dag-Erling Smørgrav
62e0f12f51 scandir: Propagate errors from readdir().
Currently, if `readdir()` fails, `scandir()` simply returns a partial
result (or a null result if it fails before any entries were selected).
There is no way within the current API design to return both a partial
result and an error indicator, so err on the side of caution: if an
error occurs, discard any partial result and return the error instead.

MFC after:	1 week
Reported by:	Maxim Suhanov <dfirblog@gmail.com>
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D51046
2025-06-26 09:37:00 +02:00
Konstantin Belousov
6458400813 csu: C standard requires errno on main() entry
Reported by:	Greg Becker <greg.becker@klarasystems.com>
Reviewed by:	emaste, kevans, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Also see:	https://reviews.freebsd.org/D50998
Differential revision:	https://reviews.freebsd.org/D50997
2025-06-24 04:11:17 +03:00
Dag-Erling Smørgrav
0a5b763d98 libc: Rename fscandir{,_b}() to fdscandir{,_b}().
This seems to fit the pattern better (e.g. fdopendir()).

I've added weak references to ease the transition, but since it's only
been a few days, we can remove them (and the ObsoleteFiles entries for
the manual pages) before we branch stable/15.

Fixes:		deeebfdeca
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D50980
2025-06-23 15:03:10 +02:00
Bojan Novković
b2ac169802 glob: Delete trailing whitespace in 'struct glob_limit' definition
Sponsored by: Klara, Inc.
2025-06-23 11:58:41 +02:00
Bojan Novković
66d780ab1d glob.3: Fix punctuation mistakes
Fixes: 1e0743f54d
Sponsored by: Klara, Inc.
2025-06-23 11:34:45 +02:00
Dag-Erling Smørgrav
7fe39bec80 glob: Improve callback tests.
Most importantly, they need to run without privileges, since root is
allowed to read a directory regardless of its permission bits.

PR:		287694
Fixes:		4d7c31bca2
Sponsored by:	Klara, Inc.
Reviewed by:	bnovkov
Differential Revision:	https://reviews.freebsd.org/D50965
2025-06-23 10:44:31 +02:00
Gleb Smirnoff
220cdd1b39 libc/rpc/svc_nl: plg a memory leak
CID:	1591126
2025-06-20 15:37:47 -07:00
Dag-Erling Smørgrav
c187b673bb scandir: Fix behavior when no entries match.
In the previous commit, I removed the initial initialization of the
`names` array, not realizing that `scandir()` is expected to return
a non-null (but empty) array of entries if no entries matched.
Restore the historical behavior, document it, and add a test.

Fixes:		deeebfdeca
Sponsored by:	Klara, Inc.
Reviewed by:	kevans, allanjude, markj
Differential Revision:	https://reviews.freebsd.org/D50949
2025-06-20 18:13:48 +02:00
Dag-Erling Smørgrav
deeebfdeca libc: Add fscandir(), fscandir_b(), scandirat_b().
While here, clean up scandir() a bit and improve the documentation.

MFC after:	never
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D50935
2025-06-20 13:10:23 +02:00
Sergey A. Osokin
22c7815118 exec(3): add missing execvpe(3) to MLINKS
Reviewed by:	glebius
2025-06-18 17:40:22 -04:00
Alexander Ziaee
1b6936e125
manuals: Align our tree with upstream C23 macro
Switch all instances of the -isoC-2024 macro to -isoC-2023 selected by
upstream. Keep -isoC-2024 defined, but deprecated, for backwards compat.

MFC after:      3 days (I will resolve merge conflicts with cdefs)
2025-06-12 17:24:10 -04:00
Ricardo Branco
b0334450aa include: ssp: fortify <signal.h>
sig2str(3)

Reviewed by: imp, kib, des, jilles
Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
Closes: https://github.com/freebsd/freebsd-src/pull/1696
2025-06-11 17:16:22 -06:00
Ricardo Branco
d580567dfb Add tests for sig2str() / str2sig()
Reviewed by: imp, kib, des, jilles
Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
2025-06-11 17:16:22 -06:00
Ricardo Branco
3d12567133 Add the POSIX sig2str(3) & str2sig(3) calls
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed by: imp, kib, des, jilles
Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
2025-06-11 17:16:22 -06:00
Ricardo Branco
86f06e612b Add POSIX NSIG_MAX & _SC_NSIG
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1710
Closes: https://github.com/freebsd/freebsd-src/pull/1710
2025-06-11 17:16:20 -06:00
Brooks Davis
9623040eee closefrom: always use close_range(2)
close_range(2) was added prior to 13.0.  There is no need to support
a new userspace on such an old kernel.

Reviewed by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D50730
2025-06-06 22:58:29 +01:00
Brooks Davis
a5b0b2a7d4 C runtime: add kernel version guards on exterrctl
This allows userspace to run on a (somewhat) out of date kernel.

Avoid a __FreeBSD_version bump and use the bump from a02180cf60 which
has occured since exterrctl was added.

Reviewed by:	kevans
Fixes:		b9c8a07d4d ("C runtime: enable extended error reporting from kernel")
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D50687
2025-06-04 19:09:19 +01:00
Jessica Clarke
786ced56a4 libc: Fix glob.c build with GCC
We don't expose the dummy struct pointer in the header file, so
gl_errblk is just a void * when lacking compiler support for blocks and
we need to cast to the former for CALL_BLOCK to work. If blocks support
is present this should be a redundant cast to the type that gl_errblk
already is.

Fixes:	1e0743f54d ("glob: Add blocks support")
2025-06-03 15:19:04 +01:00
Jessica Clarke
680f1a39ee libc: Allow more complex expressions for CALL_BLOCK first argument
For the case where the compiler supports blocks we only allow the first
expression to have an operator if it has as high precedence as a
function call, which for blocks effectively means member access and
subscripting only, not even a dereference nor a cast. Parenthesise this,
as is the case for the missing compiler support case, so that it's more
general.
2025-06-03 15:19:04 +01:00
Bojan Novković
4d7c31bca2 glob2_test: Add tests for error callback functions and blocks
This change adds tests that check basic callback functionality for
blocks and function pointers. The tests also make sure that GLOB_ERR
overrides the callback's return value.

Sponsored by:   Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D50486
2025-06-02 11:32:55 +02:00
Bojan Novković
1e0743f54d glob: Add blocks support
This change introduces the `glob_b` function which takes a block instead
of a function pointer.

Relnotes:	yes
Sponsored by:   Klara, Inc.
Inspired by:  https://github.com/apple-oss-distributions/Libc
Differential Revision:	https://reviews.freebsd.org/D50485
2025-06-02 11:32:50 +02:00
Konstantin Belousov
a56fe703c2 Provide user interface to retrieve reported extended errors
Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D50483
2025-05-31 22:52:42 +03:00
Konstantin Belousov
98af94cae7 sysconf(3): add _SC_UEXTERR_LEN, the max length of the extended error string
Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D50483
2025-05-31 22:52:42 +03:00
Konstantin Belousov
b9c8a07d4d C runtime: enable extended error reporting from kernel
Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D50483
2025-05-31 22:52:42 +03:00
Jessica Clarke
250b2eda0a libc, libthr: Ditch MD __pthread_distribute_static_tls helpers
_libc_get_static_tls_base() is just _tcb_get() followed by adding (for
Variant I) or subtracting (for Variant II) the offset, so just inline
that as the implementation (like we do in rtld-elf) rather than having
another copy (or equivalent) of _tcb_get()'s assembly.

_get_static_tls_base() doesn't even have any MD assembly as it's
reading thr->tcb, the only difference is whether to add or subtract, so
again just inline that.

Whilst here add some missing blank lines to comply with style(9) for
elf_utils.c's includes, and use a pointer type rather than uintptr_t to
reduce the need to cast, as is done in rtld-elf.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D50592
2025-05-29 17:06:54 +01:00
Enji Cooper
19fb56b192 Revert "Mark several getaddrinfo tests as XFAIL"
This change was unreviewed and should not have been committed to :main.

This reverts commit 9b37d84c87.
2025-05-28 15:18:51 -07:00
Enji Cooper
9b37d84c87 Mark several getaddrinfo tests as XFAIL
These tests were recently enabled on main and have failed consistently
since they were enabled.

- lib.libc.net.getaddrinfo.getaddrinfo.basic
- lib.libc.net.getaddrinfo.getaddrinfo.nofamily
- lib.libc.net.getaddrinfo.getaddrinfo_test.basic
- lib.libc.net.getaddrinfo.getaddrinfo_test.empty_servname
- lib.libc.net.getaddrinfo.getaddrinfo_test.sock_raw

Mark them as expected failures so they no longer count as failures in
Jenkins CI.

PR:		285826
MFC with:	5313457780, 0b773a94ab
2025-05-28 15:15:08 -07:00
Jessica Clarke
0e3dbc64d9 libc/riscv: Fix initial exec TLS mode for dynamically loaded shared objects
The offset here is relative to the TCB, not whatever the thread pointer
points to, so as with powerpc and powerpc64 we need to account for that.
However, rather than using hard-coded offsets as they did, due to
predating machine/tls.h, we can just re-use _tcb_get().

Note that if libthr is used, and its initialiser has been called, it
will take a different path that uses _get_static_tls_base, which works
just fine on riscv (adding the offset to thr->tcb). This only affects
programs that aren't linked against libthr (or that are but manage to
dlopen before the initialiser is called, if that's even possible).

In future this code should be made MI by just reusing _tcb_get() and
checking the TLS variant (since the offset here is positive even for
variant II, where it should be subtracted), but this is a targeted fix
that makes it clear what's changing.

Reviewed by:	kib
Fixes:		5d00c5a657 ("Fix initial exec TLS mode for dynamically loaded shared objects.")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D50564
2025-05-28 21:23:10 +01:00
Konstantin Belousov
eba4039236 libc: set close-on-exec for temp socket used to detect IPv6 support
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D50509
2025-05-24 16:17:09 +03:00
Lexi Winter
9a79f1b8c3 Remove vestiges of keyserv(8)
This daemon has been removed; also remove things which reference it.

Reviewed by:	manu, des, emaste
Approved by:	des (mentor)
Differential Revision:	https://reviews.freebsd.org/D50441
2025-05-23 22:59:33 +01:00
Alexander Ziaee
7098712bbf
SPDX: Tag BSD-4.3TAHOE
TIL traceroute.8 has one of the oldest liceses, predating BSD-4-Clause!
The SPDX tag was not even on Wikipedia. These are all the files I could
find in the tree with git grep that look like the license reported on
the SPDX website, including one that was misfiled.

Ref:			https://spdx.org/licenses/BSD-4.3TAHOE.html
MFC after:		3 days
Reported by:		brooks
Reviewed by:		brooks, carlavilla, imp, ivy
Approved by:		carlavilla (mentor)
Differential Revision:	https://reviews.freebsd.org/D50362
2025-05-21 12:37:10 -04:00
Mark Johnston
19419d36cf libc: Give __thr_jtable protected visibility
This function pointer table is overwritten by libthr when it's loaded.
libc's pthread stubs are implemented by looking up an entry in this
table and invoking the function pointer contained in the entry.

pthread calls are fairly expensive even when libthr is not loaded: each
call involves indirection through the PLT, then through the GOT to look
up __thr_jtable, then the function pointer itself.  We can however
eliminate one level of indirection by disallowing preemption of the
__thr_jtable symbol, and since the existence table is an internal
implementation detail, disabling preemption is unlikely to break
anything.  This gives a modest improvement in some microbenchmarks which
call libc's pthread stubs.

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D50354
2025-05-19 14:29:12 +00:00
Dag-Erling Smørgrav
1518203b89 libc: Improve scanfloat test. 2025-05-16 17:44:10 +02:00
Lexi Winter
a121509041 link_addr: be more strict about address formats
instead of accepting any character as a delimiter, only accept ':', '.'
and '-', and only permit a single delimiter in an address.

this prevents accepting bizarre addresses like:

	ifconfig epair2a link 10.1.2.200/28

... which is particularly problematic on an INET6-only system, in which
case ifconfig defaults to the 'link' family, meaning that:

	ifconfig epair2a 10.1.2.200/28

... changes the Ethernet address of the interface.

bump __FreeBSD_version so link_addr() consumers can detect the change.

Reviewed by:	kp, des
Approved by:	des (mentor)
Differential Revision:	https://reviews.freebsd.org/D49936
2025-05-15 01:02:52 +01:00
Dag-Erling Smørgrav
08f613e1d1 fts: Fix misindented line.
Fixes:		da2025a0e8
Sponsored by:	Klara, Inc.
2025-05-08 20:01:55 +02:00
Dag-Erling Smørgrav
d30a84ab44 fts: Rename fts_options to fts_options_test
Sponsored by:	Klara, Inc.
2025-05-08 17:05:12 +02:00
Dag-Erling Smørgrav
782a611a0b fts: Give the blocks test a description.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D50235
2025-05-08 16:29:16 +02:00