opnsense-src/lib/libcasper
Hiroki Sato b60053fde1 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
2025-06-13 03:16:49 +09:00
..
libcasper Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
services libcasper: Fix inconsistent error codes of cap_get{addr,name}info() 2025-06-13 03:16:49 +09:00
tests Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
Makefile Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
Makefile.inc Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00