libfiu(3)
π libfiu(3) β Library Functions Manual π
okay bestie, sit down, hydrate, and let me tell you about libfiu π«Ά this is the man page for the library functions themselves β not some boring wrapper, the whole actual API. no cap.
πΈ NAME πΈ
libfiu β fault injection in userspace β¨ (yes, we're breaking things ON PURPOSE, and it's iconic)
π SYNOPSIS π
/* Core API */
#include <fiu.h>
int fiu_init(unsigned int flags);
int fiu_fail(const char *name);
void *fiu_failinfo(void);
[void] fiu_do_on(char *name, action); [macro]
[void] fiu_exit_on(char *name); [macro]
[void] fiu_return_on(char *name, retval); [macro]
/* Control API */
#include <fiu-control.h>
int fiu_enable(const char *name, int failnum,
void *failinfo, unsigned int flags);
int fiu_enable_random(const char *name, int failnum,
void *failinfo, unsigned int flags, float probability);
typedef int external_cb_t(const char *name, int *failnum,
void **failinfo, unsigned int *flags);
int fiu_enable_external(const char *name, int failnum,
void *failinfo, unsigned int flags,
external_cb_t *external_cb);
int fiu_enable_stack(const char *name, int failnum,
void *failinfo, unsigned int flags,
void *func, int func_pos_in_stack);
int fiu_enable_stack_by_name(const char *name, int failnum,
void *failinfo, unsigned int flags,
const char *func_name, int func_pos_in_stack);
int fiu_disable(const char *name);
int fiu_rc_fifo(const char *basename);
like, that's the whole shape of it. memorize nothing, just vibe check it π
π DESCRIPTION π
so libfiu is a library for fault injection. what does that even mean? it means it gives you functions to mark "points of failure" inside your code (that's the core API π§), plus functions to enable and disable the failure of those points (that's the control API π).
the core API lives inside the code you want to perform fault injection on. the control API lives inside the testing code, so it can control the injection of failures. two little worlds, one cute library π¦
heads up bestie: this page is an API reference and not a complete manual. it does not go into detail about how to use the library. the library's manual can be found in the distribution π
β CORE API β
to use the core API, you should #include <fiu.h> (or <fiu-local.h>, see below π).
because fault injection is usually a debugging/testing facility β unwanted at runtime, lowkey a menace β some special considerations were taken to minimize the impact of the core API. first of all, if FIU_ENABLE is not defined, then fiu.h will define empty stubs for all the core API, effectively disabling fault injection completely. poof, gone, no overhead energy π
also, the special header fiu-local.h is shipped with libfiu. it's meant to be included in your project to avoid having libfiu as a mandatory build-time dependency. you can add it to your project, and #include it instead of fiu.h. it will take care of including the real fiu.h only when FIU_ENABLE is defined. it's entirely optional, but recommended. see the library's manual for more details. honestly? bestie behavior π«Ά
fiu_init(flags)
initializes the library. ideally, you should only call this once, although it can cope with multiple calls (it's flexible like that π). the flags parameter is currently unused and must be set to 0. returns 0 on success, < 0 on error.
fiu_fail(name)
returns the failure status of the given point of failure. 0 means it should not fail. by default, all points of failure do not fail; they're enabled in runtime using the control API. so like, nothing is broken until you say so π₯
fiu_failinfo()
returns the information associated with the last failure, or NULL if there isn't one. this function is thread-aware and will only return information about failures in the calling thread. so it knows exactly which thread it's talking to, no cross-thread drama π
fiu_do_on(name, action) [macro]
this is a macro that uses fiu_fail() to perform the given action when the given point of failure fails. the action can be any valid C statement. any. valid. C. statement. go off β¨
fiu_exit_on(name) [macro]
this is a macro that uses fiu_fail() to exit the process when the given point of failure fails. the process is exit using exit(3), which is given the status EXIT_FAILURE. yeah bestie we're leaving the function entirely, no warning, main character exit πͺ
fiu_return_on(name, retval) [macro]
this is a macro that uses fiu_fail() to make the current function return the given value (retval, whose type obviously depends on the return type of the function). type safety? you handle it. we're just out here returning π
π CONTROL API π
to use the control API, you should #include <fiu-control.h>.
fiu_enable(name, failnum, failinfo, flags)
enables the given point of failure. failnum is what fiu_fail() will return, and must be != 0. failinfo is what fiu_failinfo() will return when called after the given point of failure has failed. flags can be either 0 or FIU_ONETIME, which indicates that this point of failure should only fail once. returns 0 if success, < 0 otherwise. if the point of failure was already enabled, this overwrites the previous values. (sorry to the old values, they're being replaced π)
successive calls to fiu_fail() will return failnum until this point of failure is disabled. if FIU_ONETIME was passed in the flags, this point of failure is disabled immediately after failing once. one and done, iconic.
if the name ends with an asterisk, then it this will match all points of failure that begin with the given name (excluding the asterisk, of course). wildcard behavior, we love her π
fiu_enable_random(name, failnum, failinfo, flags, probability)
enables the given point of failure, with the given probability (between 0 and 1). the rest of the parameters, as well as the return value, are the same as the ones in fiu_enable(). chaos, but make it statistical π²
fiu_enable_external(name, failnum, failinfo, flags, external_cb)
enables the given point of failure, leaving the decision whether to fail or not to the given external function, which should return 0 if it is not to fail, or 1 otherwise. the rest of the parameters, as well as the return value, are the same as the ones in fiu_enable(). you're outsourcing the drama to a callback and honestly? valid π
int fiu_enable_stack(name, failnum, failinfo, flags, func, func_pos_in_stack)
enables the given point of failure, but only if func is in the stack at func_pos_in_stack. π
func must be a function pointer, and func_pos_in_stack is the position where we expect the function to be, or -1 for "any" (values other than -1 are not yet supported). the rest of the parameters, as well as the return value, are the same as the ones in fiu_enable().
this function relies on some GNU extensions, so it may be not available in all platforms. (check before you commit, bestie π§)
int fiu_enable_stack_by_name(name, failnum, failinfo, flags, func_name, func_pos_in_stack)
enables the given point of failure, but only if func_name is in the stack at func_pos_in_stack. same energy, but by name this time π
func must be the name of a function (resolved at runtime using dlsym()); the rest of the parameters, as well as the return value, are the same as the ones in fiu_enable_stack.
this function relies on some GNU extensions, so it may be not available in all platforms. same warning, same vibes β οΈ
fiu_disable(name)
disables the given point of failure, undoing the actions of the fiu_enable*() functions. it's the uno reverse card π
fiu_rc_fifo(basename)
enables remote control over named pipes with the given basename. see the remote control documentation that comes with the library for more detail. remote control, but make it a FIFO π
π¦ THREAD SAFETY π¦
the library is thread-safe. the list of enabled failure points is shared among all threads. one big happy (shared) list π«Ά
care should be taken in the user-provided functions given to fiu_enable_external(), as they can be run in parallel. so like, no sneaky shared state in there, bestie, that's a vibe check you do NOT want to fail π
β¨ SEE ALSO β¨
π BUGS π
if you want to report bugs, or have any questions or comments, just let me know at albertito@blitiri.com.ar. for more information about libfiu, you can go to http://blitiri.com.ar/p/libfiu.
and that's the whole page, bestie π this was libfiu(3) from the Library Functions Manual, dated 17/Feb/2009, version libfiu(3) π go forth and break things on purpose, responsibly. periodt. π β¨
π¦ where this page comes from
- debian bookworm: libfiu-dev 1.1-3+b2 Β· BOLA
- debian trixie: libfiu-dev 1.2-3+b2 Β· BOLA
- ubuntu jammy: libfiu-dev 1.00-7ubuntu3 Β· BOLA
- ubuntu noble: libfiu-dev 1.2-2 Β· BOLA
- ubuntu questing: libfiu-dev 1.2-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms