HomeFreeBSD

libcasper: Fix inconsistent error codes of cap_get{addr,name}info()

Description

libcasper: Fix inconsistent error codes of cap_get{addr,name}info()

The get{addr,name}info(3) API is designed to return an API-specific error
code that is independent of errno. The cap_get{addr,name}info() functions
returned either an errno or API-specific error code inconsistently.
This change fixes this mismatch.

When the API returns an errno, the return value itself is set to
EAI_SYSTEM and errno is set depending on the actual error. So, usually
this API is called in the following form:

error = getnameinfo(...);
if (error == EAI_SYSTEM)
    perror("getnameinfo");
else if (error)
    errx(1, "getnameinfo: %s", gai_strerror(error);

If the above getnameinfo() call is replaced with cap_getnameinfo(),
it breaks the error handling. For example, the cap_get{addr,name}info()
functions can return ENOTCAPABLE.

This change simply adds "errno", in addition to "error", to the nvlout and
cap_get{addr,name}info() restores the errno if the error code is EAI_SYSTEM.

Reviewed by: oshogbo
Differential Revision: https://reviews.freebsd.org/D45859

Details

Provenance
hrsAuthored on Jun 12 2025, 6:16 PM
Reviewer
oshogbo
Differential Revision
D45859: libcasper: Fix inconsistent error codes of cap_get{addr,name}info()
Parents
rG6501b68ffba7: libcasper: Use __VA_ARGS__ for function-like macros
Branches
Unknown
Tags
Unknown