Page MenuHomeFreeBSD

Use extended errors for err(3) and warn(3)
ClosedPublic

Authored by kib on Jul 3 2025, 3:08 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Aug 8, 11:02 PM
Unknown Object (File)
Thu, Aug 7, 1:55 AM
Unknown Object (File)
Tue, Aug 5, 5:00 AM
Unknown Object (File)
Sun, Aug 3, 12:25 AM
Unknown Object (File)
Sat, Aug 2, 10:59 PM
Unknown Object (File)
Tue, Jul 29, 1:06 AM
Unknown Object (File)
Tue, Jul 29, 12:25 AM
Unknown Object (File)
Mon, Jul 28, 9:34 PM
Subscribers

Details

Summary
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.


err(3): print extended error if available

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Jul 3 2025, 3:08 AM
lib/libc/gen/err.c
96

Should this be false, since the errno is coming from the caller instead of from the kernel?

lib/libc/gen/err.c
96

I am not sure. There are syscalls returning error instead of setting errno, and errc() is naturally used with them. I definitely mean this.

The question is probably should warnc() and errc() be consistent in this regard.

lib/libc/gen/err.c
199

It looks like the \n went missing.

This function and verrci have a lot in common. Should they be merged?

kib marked an inline comment as done.

Add vexterr() helper.

lib/libc/gen/err.c
96

I'm concerned about a sequence of events like this:

(void) some_syscall(42);  // Fails with EINVAL and ext err "Not a valid number"
...
if (err = some_library_call()) {
    // errc might print "Not a valid number", which wouldn't make sense.
    errc(1, err, "some_library_call");
}
lib/libc/gen/err.c
96

I understand.

In fact it would print right error, and not related extended error. Practically this is not too huge issue, but ok. I reverted the errc() back.

kib marked 2 inline comments as done.

Exclude errc() from extended error printing.

lib/libc/gen/err.c
96

How would it know not to print the stale error? The new error may not even come from the kernel. The library might use errnos for its own errors.

kib marked an inline comment as done.Jul 5 2025, 9:44 AM
kib added inline comments.
lib/libc/gen/err.c
96

This is reverted already.

This revision is now accepted and ready to land.Jul 5 2025, 3:12 PM
This revision was automatically updated to reflect the committed changes.
kib marked an inline comment as done.