explain_select(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– explain_select(3) β€” Library Functions Manual πŸ’–

okay bestie, so you know how select(2) can just randomly fail on you and leave you staring at errno like πŸ‘οΈπŸ‘„πŸ‘οΈ? yeah. this page is from the Library Functions Manual and it's all about the libexplain glow-up that turns that cryptic error into an actual explanation. sit down, hydrate, let's go πŸ“


✨ NAME ✨

explain_select β€” explain select(2) errors πŸ’…


🌸 SYNOPSIS 🌸

#include <sys/select.h>
#include <libexplain/select.h>
const char *explain_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
const char *explain_errno_select(int errnum, int nfds, fd_set *readfds,
fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
void explain_message_select(char *message, int message_size, int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval
*timeout);
void explain_message_errno_select(char *message, int message_size, int
errnum, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);

πŸ¦‹ DESCRIPTION πŸ¦‹

so these functions? they're your little translators πŸ’œ. you use them to get explanations for errors that the select(2) system call hands back to you. no more raw errno staring contests, no cap.


🌈 explain_select

const char *explain_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);

the explain_select function is the moment ✨ it gets you an explanation of an error returned by the select(2) system call. the absolute bare minimum the message will contain is the value of strerror(errno), but usually it does so much better and points at the underlying cause in more detail. it's giving detective energy πŸ”

the errno global variable is what gets used to obtain the error value to be decoded.

this function is intended to be used in a fashion similar to the following example:

if (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
    fprintf(stderr, "%s\n", explain_select(nfds,
        readfds, writefds, exceptfds, timeout));
    exit(EXIT_FAILURE);
}
  • nfds β€” the original nfds, exactly as passed to the select(2) system call.
  • readfds β€” the original readfds, exactly as passed to the select(2) system call.
  • writefds β€” the original writefds, exactly as passed to the select(2) system call.
  • exceptfds β€” the original exceptfds, exactly as passed to the select(2) system call.
  • timeout β€” the original timeout, exactly as passed to the select(2) system call.

Returns: the message explaining the error πŸ‘‘ this message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. it will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. so like. screenshot it or copy it, don't just vibe with the pointer 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. fr fr, be careful.

πŸ’« explain_errno_select

const char *explain_errno_select(int errnum, int nfds, fd_set *readfds,
fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

the explain_errno_select function gets you an explanation of an error returned by the select(2) system call. minimum content = the value of strerror(errnum), but usually it goes way harder and indicates the underlying cause in more detail 🫢

this function is intended to be used in a fashion similar to the following example:

if (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_select(err,
        nfds, readfds, writefds, exceptfds, timeout));
    exit(EXIT_FAILURE);
}
  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. this is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. yes literally, they will snatch it from you πŸ’€
  • nfds β€” the original nfds, exactly as passed to the select(2) system call.
  • readfds β€” the original readfds, exactly as passed to the select(2) system call.
  • writefds β€” the original writefds, exactly as passed to the select(2) system call.
  • exceptfds β€” the original exceptfds, exactly as passed to the select(2) system call.
  • timeout β€” the original timeout, exactly as passed to the select(2) system call.

Returns: the message explaining the error ✨ this message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. this will be overwritten by the next call to any libexplain function which shares this buffer, including other threads.

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.

πŸŽ€ explain_message_select

void explain_message_select(char *message, int message_size, int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval
*timeout);

the explain_message_select function may be used to obtain an explanation of an error returned by the select(2) system call. least it'll contain is the value of strerror(errno), but usually it does much better and indicates the underlying cause in more detail 🌸

the errno global variable will be used to obtain the error value to be decoded.

this function is intended to be used in a fashion similar to the following example:

if (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
    char message[3000];
    explain_message_select(message, sizeof(message),
        nfds, readfds, writefds, exceptfds, timeout);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}
  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe πŸ‘‘ that's the whole point, bestie.
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • nfds β€” the original nfds, exactly as passed to the select(2) system call.
  • readfds β€” the original readfds, exactly as passed to the select(2) system call.
  • writefds β€” the original writefds, exactly as passed to the select(2) system call.
  • exceptfds β€” the original exceptfds, exactly as passed to the select(2) system call.
  • timeout β€” the original timeout, exactly as passed to the select(2) system call.

🧚 explain_message_errno_select

void explain_message_errno_select(char *message, int message_size, int
errnum, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);

the explain_message_errno_select function may be used to obtain an explanation of an error returned by the select(2) system call. least it'll contain is the value of strerror(errnum), but usually it does much better and indicates the underlying cause in more detail πŸ’œ

this function is intended to be used in a fashion similar to the following example:

if (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_select(message, sizeof(message), err,
        nfds, readfds, writefds, exceptfds, timeout);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}
  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe ✨
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. this is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. again. they WILL do it πŸ™ˆ
  • nfds β€” the original nfds, exactly as passed to the select(2) system call.
  • readfds β€” the original readfds, exactly as passed to the select(2) system call.
  • writefds β€” the original writefds, exactly as passed to the select(2) system call.
  • exceptfds β€” the original exceptfds, exactly as passed to the select(2) system call.
  • timeout β€” the original timeout, exactly as passed to the select(2) system call.

🌈 SEE ALSO 🌈


libexplain version 1.4 Copyright (C) 2008 Peter Miller


and that's the whole page bestie 🫢 go forth and decode your errnos, you absolute icon ⭐ this was explain_select(3) from the Library Functions Manual, brought to you by libexplain version 1.4, Copyright (C) 2008 Peter Miller β€” mwah, no notes πŸ’–πŸŽ€

πŸ“¦ where this page comes from