explain_setreuid(3)
π NAME π
okay bestie, so this whole page is about explain_setreuid β it lives in the explain_setreuid(3) corner of the library, and its entire job is explaining the errors that setreuid(2) throws at you. like, translating cryptic kernel sadness into actual human words. no cap. β¨
π¦ SYNOPSIS π¦
#include <libexplain/setreuid.h>
const char *explain_setreuid(uid_t ruid, uid_t euid);
const char *explain_errno_setreuid(int errnum, uid_t ruid, uid_t euid);
void explain_message_setreuid(char *message, int message_size, uid_t ruid, uid_t euid);
void explain_message_errno_setreuid(char *message, int message_size, int errnum, uid_t ruid, uid_t euid);
πΈ DESCRIPTION πΈ
so these functions are the ones you call when setreuid(2) comes back with an error and you're like "bestie what does that MEAN". they hand you explanations. it's giving translator, it's giving emotional support for syscalls. π«Ά
π explain_setreuid
const char *explain_setreuid(uid_t ruid, uid_t euid);
explain_setreuid gets you an explanation of an error that came back from the setreuid(2) system call. the least the message will contain is the value of strerror(errno) β but usually it does way better than that and tells you the underlying cause in actual detail. lowkey overachiever. π
the errno global variable is the one it peeks at to grab the error value it's gonna decode.
- ruid β the original
ruid, exactly as passed to thesetreuid(2)system call. - euid β the original
euid, exactly as passed to thesetreuid(2)system call.
Returns:
the message explaining the error. heads up though: this message buffer is shared by all the libexplain functions that don't supply a buffer in their argument list. so it WILL get overwritten by the next call to any libexplain function that shares this buffer β including calls from other threads. π
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 getting raced on a shared buffer π
Example: this function is meant to be used in a fashion similar to the following example:
if (setreuid(ruid, euid) < 0)
{
fprintf(stderr, "%s\n", explain_setreuid(ruid, euid));
exit(EXIT_FAILURE);
}
and the above code example is available pre-packaged as the explain_setreuid_or_die(3) function. slay, they did the work for you. β¨
π explain_errno_setreuid
const char *explain_errno_setreuid(int errnum, uid_t ruid, uid_t euid);
explain_errno_setreuid gets you an explanation of an error returned by the setreuid(2) system call. again, the least the message will contain is the value of strerror(errno), but usually it does much better and points at the underlying cause in more detail. π¦
- errnum β the error value to be decoded, usually grabbed from the
errnoglobal variable right before this function is called. this one matters if you need to run any code between the system call you're explaining and this function, because a whole bunch of libc functions will mess with the value oferrno. fr fr, guard it. - ruid β the original
ruid, exactly as passed to thesetreuid(2)system call. - euid β the original
euid, exactly as passed to thesetreuid(2)system call.
Returns:
the message explaining the error. and yeah, same situation as before: this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. it will be overwritten by the next call to any libexplain function that shares this buffer, other threads included. π
Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library do too.
Example: this function is intended to be used in a fashion similar to the following example:
if (setreuid(ruid, euid) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_setreuid(err, ruid, euid));
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_setreuid_or_die(3) function. π
π explain_message_setreuid
void explain_message_setreuid(char *message, int message_size, uid_t ruid, uid_t euid);
explain_message_setreuid is the one you use to obtain an explanation of an error returned by the setreuid(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. main character energy, honestly. π
the errno global variable is what it uses to obtain the error value to be decoded.
- message β the location in which to store the returned message. if you supply a suitable message return buffer, this function is thread safe. π«Ά (see? sometimes we're fine.)
- message_size β the size in bytes of the location in which to store the returned message.
- ruid β the original
ruid, exactly as passed to thesetreuid(2)system call. - euid β the original
euid, exactly as passed to thesetreuid(2)system call.
Example: this function is intended to be used in a fashion similar to the following example:
if (setreuid(ruid, euid) < 0)
{
char message[3000];
explain_message_setreuid(message, sizeof(message), ruid, euid);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_setreuid_or_die(3) function. iconic. β¨
π§ explain_message_errno_setreuid
void explain_message_errno_setreuid(char *message, int message_size, int errnum, uid_t ruid, uid_t euid);
explain_message_errno_setreuid is used to obtain an explanation of an error returned by the setreuid(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 way this one eats every time π
- 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
errnoglobal 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 oferrno. ngl, this trips people up constantly. π - ruid β the original
ruid, exactly as passed to thesetreuid(2)system call. - euid β the original
euid, exactly as passed to thesetreuid(2)system call.
Example: this function is intended to be used in a fashion similar to the following example:
if (setreuid(ruid, euid) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_setreuid(message, sizeof(message), err, ruid, euid);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_setreuid_or_die(3) function. periodt. π
π SEE ALSO π
setreuid(2)β set the real and effective user IDexplain_setreuid_or_die(3)β set the real and effective user ID and report errors
π COPYRIGHT π
this whole vibe is libexplain version 1.4, and the copyright belongs to Copyright (C) 2012 Peter Miller. respect the icon, bestie. π
okay that's the whole page, mwah π β written for explain_setreuid(3), from the Library Functions Manual, and that's the version 1.4 / 2012 Peter Miller energy right there at the bottom where it always lives. go forth and decode your errnos, you gorgeous nerd. π¦β¨
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2012 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms