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
F105568433: D45859.diff
Tue, Dec 17, 6:32 PM
Unknown Object (File)
Thu, Nov 21, 11:17 PM
Unknown Object (File)
Wed, Nov 20, 12:44 AM
Unknown Object (File)
Tue, Nov 19, 8:47 PM
Unknown Object (File)
Oct 27 2024, 10:14 AM
Unknown Object (File)
Sep 30 2024, 9:33 AM
Unknown Object (File)
Sep 29 2024, 6:16 PM
Unknown Object (File)
Sep 29 2024, 2:32 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 58480
Build 55368: 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
369

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
369

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