explain_nanosleep(3)

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

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

okay bestie, sit DOWN because we're about to talk about explain_nanosleep(3), from the libexplain library functions manual. this is the page that tells you why your nanosleep(2) call flopped, and honestly? it's giving "therapist for your errno" and i'm obsessed πŸ’…


✨ NAME ✨

explain_nanosleep β€” explain nanosleep(2) errors 🫢


✨ SYNOPSIS ✨

#include <libexplain/nanosleep.h>
const char *explain_nanosleep(const struct timespec *req, struct
timespec *rem);
const char *explain_errno_nanosleep(int errnum, const struct timespec
*req, struct timespec *rem);
void explain_message_nanosleep(char *message, int message_size, const
struct timespec *req, struct timespec *rem);
void explain_message_errno_nanosleep(char *message, int message_size,
int errnum, const struct timespec *req, struct timespec *rem);

✨ DESCRIPTION ✨

so here's the tea β˜• β€” these functions are your little translators. you hand them the wreckage of a failed nanosleep(2) system call, and they hand you back an explanation. not just a shrug, an actual explanation. periodt.

🌸 explain_nanosleep 🌸

const char *explain_nanosleep(const struct timespec *req, struct
timespec *rem);

explain_nanosleep is the one you call to get an explanation of an error returned by the nanosleep(2) system call. the least you're gonna get in that message is the value of strerror(errno), but usually it does so much better and actually tells you the underlying cause in more detail. like, it's not just gonna say "something broke", it's gonna say what broke and why. main character energy fr fr ✨

the errno global variable is what gets used to grab the error value that's gonna be decoded.

  • req β€” the original req, exactly as passed to the nanosleep(2) system call. no edits, no glow-up, just the raw original.
  • rem β€” the original rem, exactly as passed to the nanosleep(2) system call. same deal πŸ’–

Returns: the message explaining the error. and here's the important part bestie β€” this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. so it will be overwritten by the next call to any libexplain function that shares this buffer, including calls from other threads. so don't get attached to it, okay? 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. not me calling this from multiple threads and wondering why everything's cursed πŸ’€

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

if (nanosleep(req, rem) < 0)
{
    fprintf(stderr, "%s\n", explain_nanosleep(req, rem));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function. so if you want the whole thing ready-made, that's your girl πŸ‘‘


🌈 explain_errno_nanosleep 🌈

const char *explain_errno_nanosleep(int errnum, const struct timespec
*req, struct timespec *rem);

explain_errno_nanosleep is used to obtain an explanation of an error returned by the nanosleep(2) system call. again, the least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. iconic behaviour, no notes 🌟

  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. and why does the timing matter? because if you need to call any code between the system call you're explaining and this function, you HAVE to stash it first β€” many libc functions will alter the value of errno. so grab it early or it's gone, girl πŸ™ˆ
  • req β€” the original req, exactly as passed to the nanosleep(2) system call.
  • rem β€” the original rem, exactly as passed to the nanosleep(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. yes, again. it's the same buffer, bestie, it's a whole vibe πŸ¦‹

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

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

if (nanosleep(req, rem) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_nanosleep(err, req,
    rem));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function.


πŸŽ€ explain_message_nanosleep πŸŽ€

void explain_message_nanosleep(char *message, int message_size, const
struct timespec *req, struct timespec *rem);

explain_message_nanosleep is used to obtain an explanation of an error returned by the nanosleep(2) system call. the least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. we love an overachiever πŸ’œ

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

  • message β€” the location in which to store the returned message. and here's the slay: if a suitable message return buffer is supplied, this function is thread safe. look at her go!! πŸ”₯
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • req β€” the original req, exactly as passed to the nanosleep(2) system call.
  • rem β€” the original rem, exactly as passed to the nanosleep(2) system call.

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

if (nanosleep(req, rem) < 0)
{
    char message[3000];
    explain_message_nanosleep(message, sizeof(message), req,
    rem);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function. yes, char message[3000], that's the size, don't come for me, it's literally what the page says πŸ’–


🧚 explain_message_errno_nanosleep 🧚

void explain_message_errno_nanosleep(char *message, int message_size,
int errnum, const struct timespec *req, struct timespec *rem);

explain_message_errno_nanosleep is used to obtain an explanation of an error returned by the nanosleep(2) system call. the least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. the whole combo meal, fr fr πŸ“

  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. she said "i bring my own buffer" and honestly? respect 🫢
  • 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. save it before something else eats it, bestie 😭
  • req β€” the original req, exactly as passed to the nanosleep(2) system call.
  • rem β€” the original rem, exactly as passed to the nanosleep(2) system call.

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

if (nanosleep(req, rem) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_nanosleep(message, sizeof(message),
    err, req, rem);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function.


✨ SEE ALSO ✨


libexplain version 1.4 Copyright (C) 2013 Peter Miller


and that's the whole page, bestie!! πŸŽ€ go forth, sleep with high resolution, and if it fails, at least you'll know exactly why. this has been the explain_nanosleep(3) page from the Library Functions Manual β€” libexplain version 1.4, Copyright (C) 2013 Peter Miller, dated and everything. mwah πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from