Un-sucking EINVAL (was: ip# on bridge members)
Date: Wed, 21 May 2025 07:22:29 UTC
The ip# on bridge member interfaces is yet another example of why
"EINVAL" is the undisputedly least helpful errno of them all.
The laconic "Invalid argument" leaves both the userland programmer
and the user to guess what might be wrong.
That's ok-ish for read(2) where the possibilities are so few that
the manpage can tell you what you did wrong.
It breaks down totally for ioctl(2), setsockopt(2) and similar
syscalls which can attempt very, complex operations with many
parameters and subparameters.
Ifconfig(8) is ground zero for this and the manpage is not even trying:
DIAGNOSTICS
Messages indicating the specified interface does not exist, the requested
address is unknown, or the user is not privileged and tried to alter an
interface's configuration.
We should give errno a text-partner, so kernel code can:
if (p->n_mazel-vanes < 6 * p->n_dingle_arms) {
error_text("Too few mazel-vanes per dingle-arm (min: 6)");
return (EINVAL)
}
The err(3) family of functions should retrieve the string, and when there
is one, print it as part of the error message:
Invalid argument: Too few mazel-vanes per dingle-arm (min: 6)
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.