Page MenuHomeFreeBSD

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

Authored by hrs on Jul 3 2024, 5:28 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Feb 15, 3:13 AM
Unknown Object (File)
Sun, Feb 9, 9:30 AM
Unknown Object (File)
Sun, Feb 9, 4:17 AM
Unknown Object (File)
Thu, Feb 6, 4:14 PM
Unknown Object (File)
Fri, Jan 31, 3:36 PM
Unknown Object (File)
Tue, Jan 28, 4:02 PM
Unknown Object (File)
Sun, Jan 26, 2:58 AM
Unknown Object (File)
Thu, Jan 23, 8:41 PM
Subscribers

Details

Reviewers
oshogbo
Summary

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.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 58488
Build 55376: arc lint + arc unit

Event Timeline

hrs requested review of this revision.Jul 3 2024, 5:28 PM
lib/libcasper/services/cap_net/cap_net.c
368

Using dnvlist should be a little bit faster, because we don't have to travel nvlist twice (for exists and get).

serrno = dnvlist_get_number(nvl, "errno", 0);

Update the diff to use dnvlist_get_number().

hrs marked an inline comment as done.Jul 3 2024, 8:03 PM
lib/libcasper/services/cap_net/cap_net.c
368

Thanks! Updated the diff.

hrs marked an inline comment as done.Jul 3 2024, 8:04 PM
This revision is now accepted and ready to land.Jul 4 2024, 6:58 PM