HANDLECOND(3)

πŸ“¦
version 2022.10.16 Β· 2 versions
, in opensuse-leap 16.0

πŸ’… HANDLECOND(3) β€” like, the handlecond() page from SchilyΒ΄s LIBRARY FUNCTIONS ✨

okay bestie, sit down, grab a strawberry πŸ“ β€” we're learning how to set up a condition handler, and honestly? it's giving stack frame main character energy.


✨ NAME ✨

handlecond() β€” sets a function to handle a condition πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <schily/sigblk.h>

void
handlecond(signame, sp, func, arg1)
char *signame;
SIGBLK    *sp;
int  (*func)();
long arg1;

void
starthandlecond(sigfirst)
SIGBLK    *sigfirst;

void
unhandlecond(sigfirst)
SIGBLK    *sigfirst;

🌸 DESCRIPTION 🌸

So handlecond() sets up a handler for a condition. Important: the user must explicitly allocate the condition block and pass it in β€” nobody's doing that for you, bestie πŸ’….

handlecond() establishes function func as the condition handler for the condition signame. And arg1? That gets passed to func at the time of condition signalling. Also, the signame "any_other" catches all conditions β€” like the ultimate catch-all, no cap πŸ‘‘

The specified function gets called with the actual condition being signalled, with arguments from the latest handlecond() call for that function in the given frame and from the call to raisecond(). For instance:

int func (signame, arg1, arg2)
     char *signame; /* the actual condition being
               /* signalled */
     int arg1; /* arg1 comes from the handle
               /* call that set up the handler */
     int arg2; /* arg2 comes from the raise call */

If the function returns TRUE (non-zero), it's assumed the condition has been successfully handled β€” slay πŸ’–. Otherwise, the condition is signalled farther down the stack. literally just cascading down, iykyk.

starthandlecond() sets an initial marker to the current stack frame. It needs to be called before handlecond() may be used, and the argument needs to be a variable local to the current function.

unhandlecond() needs to be called before a function may call return or fall out of the function body. The argument needs to be the same as used for the starthandlecond() function. same one, bestie, don't get cute with it πŸ™ˆ


πŸŽ€ RETURNS πŸŽ€

none β€” that's it, that's the whole section, we love a low-effort king πŸ‘‘


πŸ’œ NOTES πŸ’œ

  • Be careful when declaring args to func if they are not long β€” both args will occupy sizeof(long) bytes in the arglist. like, they're thicc, they take up space, respect it πŸ’€
  • If FALSE is returned by a condition handler, and there is an any_other handler in the same block, the any_other handler will be invoked (only once, since it too may return FALSE).
  • To revert a condition handler simply use NULL as func. bye bye handler πŸ‘‹
  • SIGBLK, defined in <schily/sigblk.h>, must be included. handlecond() is frequently used with longjmp() and setjmp().
  • Eah function which calls handlecond() must call unhandlecond() before it returns. Otherwise the return will fail or cause a core dump.
🫢 yes, that typo is in the original ("Eah"). it's iconic, we keep it. and yes β€” forget the unhandlecond() and you get a core dump. not cute. do not do this.

πŸ”₯ BUGS πŸ”₯

  • handlecond() makes the framepointer odd, to mark the current stack frame.
  • This confuses programs like adb(1) and dbx(1) because the debuggers scan the stack frame to get the call stack.
πŸ’€ so your debugger's gonna be confused by the funky framepointer. that's the trade, bestie. the odd framepointer is the marker, the debuggers just weren't ready for it.

okay and that's the whole vibe 🌈 β€” Joerg Schilling, dated 2022/09/09, page HANDLECOND(3), from SchilyΒ΄s LIBRARY FUNCTIONS. go forth and handle your conditions, bestie πŸ‘‘βœ¨πŸ¦‹

πŸ“¦ where this page comes from