SAM_H...ISTER(3)

πŸ’– SAM_HC_CALLBACK_REGISTER β€” the Corosync Cluster Engine Programmer's Manual's own little icon πŸ’–

okay bestie so we're doing a page from the Corosync Cluster Engine Programmer's Manual and it's sam_hc_callback_register(3) β€” section 3, library call, very demure, very mindful, very health-check. let's get into it 🫢


✨ NAME ✨

sam_hc_callback_register β€” register a health check callback πŸ©ΊπŸ’…


✨ SYNOPSIS ✨

#include <corosync/sam.h>

cs_error_t sam_hc_callback_register (sam_hc_callback_t cb);

like, that's the whole vibe. one function, one argument, so clean ✨


✨ DESCRIPTION ✨

so sam_hc_callback_register is literally just here to let you hand over a healthcheck callback that you wrote yourself. you register it, and boom β€” after you call this function, SAM switches from application driven healthchecking over to event driven healthchecking. new era unlocked πŸ’«

and here's the slay part: once you're in that mode, you do not need to run sam_hc_send(3) anymore. not once. it's giving self-sufficient. πŸ‘‘

the parameter cb is a callback function of type sam_hc_callback_t, and it's defined like this:

typedef int (*sam_hc_callback_t)(void);

this function gets called regularly (she's consistent, we love that πŸŽ€) and it has to return 0 if the process is functioning normally, or -1 if the process is executing abnormally. and when -1 comes back? the SAM server executes the registered recovery policy. so like, don't return -1 unless you mean it fr fr 😭

you can also pass a value of NULL into this function to switch back into application driven healthchecking. cb to NULL. just like that. πŸ¦‹


✨ RETURN VALUE ✨

this call returns the CS_OK value if it's successful β€” otherwise an error is returned. (the original says "and error is returned", which is honestly so real of it, we're keeping it as-is πŸ’€)


✨ ERRORS ✨

  • CS_ERR_BAD_HANDLE β€” SAM was not initialized and registered, or health checking is in running state. so like... she's not ready, or she's already mid-glow-up. either way, no πŸ’…
  • CS_ERR_LIBRARY β€” an internal library call failed. this can happen during fork() or pipe() system calls, and you can read the errno variable to retrieve more information. bestie go check your errno, she's holding the tea πŸ«–

✨ SEE ALSO ✨

and then there's this whole other list of error codes hanging out down here, which is iconic of the original and we're keeping every single one 🌈

  • CS_ERR_TRY_AGAIN β€” Resource temporarily unavailable
  • CS_ERR_INVALID_PARAM β€” Invalid argument
  • CS_ERR_ACCESS β€” Permission denied
  • CS_ERR_LIBRARY β€” The connection failed
  • CS_ERR_INTERRUPT β€” System call interrupted by a signal
  • CS_ERR_NOT_SUPPORTED β€” The requested protocol/functionality not supported
  • CS_ERR_MESSAGE_ERROR β€” Incorrect auth message received
  • CS_ERR_NO_MEMORY β€” Not enough memory to complete the requested task
lowkey important: if you're getting CS_ERR_BAD_HANDLE, check that SAM is actually initialized and registered and that health checking isn't already in a running state. that's the whole checklist, no cap 🧚

and that's the page!! πŸŽ€ this one's from the corosync Man Page, dated 12/01/2009 β€” yes she's an elder icon and she still ate. go register your callback, bestie, you got this πŸ’œπŸŒΈ

πŸ“¦ where this page comes from