explain_exit(3)

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

🌸 explain_exit β€” from the libexplain manual, section 3 ✨

okay bestie, pull up a chair, because this one is short but it is so useful. it's explain_exit(3) from the Library Functions Manual, and it's giving "tell me why my program died before it dies" energy. πŸ’…


πŸ’– NAME πŸ’–

explain_exit β€” print an explanation of exit status before exiting

like, literally the name says it all. it explains, and then it exits. iconic behaviour.


✨ SYNOPSIS ✨

#include <libexplain/libexplain.h>
void explain_exit_on_exit(void);
void explain_exit_on_error(void);
void explain_exit_cancel(void);

three little functions, zero arguments, all void. no notes. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea. the explain_exit_on_exit function may be used to have the calling program print an explanation of its exit status β€” that's the value you passed to exit(3), or the return value from main β€” right before it terminates. immediately before. like, last-breath confession vibes. 😭

the explain_exit_on_error function may be used to have the calling program print an explanation of its exit status immediately before it terminates, if that exit status is not EXIT_SUCCESS. so if everything went fine, it stays quiet. no drama. but the second something goes wrong? it speaks. πŸ”₯

the explain_exit_cancel function may be used to cancel the effect of the explain_exit_on_exit or explain_exit_on_error function. changed your mind, bestie, and that's valid.

these functions may be called multiple times, and in any order. the last called has precedence. and the explanation will never be printed more than once β€” so don't worry about it spamming your terminal, it is not that kind of girl. πŸ‘‘


🧚 Call Exit As Normal

in order to have the explanation printed, simply call exit(3) as normal, or return from main as normal.

not me needing to say this but: do not call any of these functions in order to exit your program. they are called before you exit your program. they are setup, not the exit itself. do not use them as your exit. periodt. πŸ’€

🌈 Caveat

this functionality is only available on systems with the on_exit(3) system call. 🫢

unfortunately, the atexit(3) system call is not sufficiently capable, as it does not pass the exit status to the registered function. it's just not built for this. we don't make the rules. πŸ™ˆ


⭐ SEE ALSO ⭐

  • exit(3) β€” cause normal process termination
  • atexit(3) β€” register a function to be called at normal process termination
  • on_exit(3) β€” register a function to be called at normal process termination

iykyk, go read those next. πŸ’œ


libexplain version 1.4 Copyright (C) 2009 Peter Miller


πŸ“ AUTHOR πŸ“

Written by Peter Miller <pmiller@opensource.org.au>


and that's the whole page, bestie! πŸŽ€ this one comes to you from libexplain version 1.4, and the footer just says explain_exit(3) one more time for the road, like a little goodbye wave. no date on this one, so we keep it mysterious. slay, bye! πŸ’–βœ¨

πŸ“¦ where this page comes from