*/
NEVER_RETURNS void fr_fault(int sig)
{
- char cmd[sizeof(panic_action) + 20];
- char *out = cmd;
- size_t left = sizeof(cmd), ret;
+ char cmd[sizeof(panic_action) + 20];
+ char *out = cmd;
+ size_t left = sizeof(cmd), ret;
- char const *p = panic_action;
- char const *q;
+ char const *p = panic_action;
+ char const *q;
- int code;
+ int code;
/*
* If a debugger is attached, we don't want to run the panic action,
FR_FAULT_LOG("CAUGHT SIGNAL: %s", strsignal(sig));
- /*
- * Check for administrator sanity.
- */
- if (fr_fault_check_permissions() < 0) {
- FR_FAULT_LOG("Refusing to execute panic action: %s", fr_strerror());
- goto finish;
- }
-
/*
* Run the callback if one was registered
*/
goto finish;
}
+ /*
+ * Check for administrator sanity.
+ */
+ if (fr_fault_check_permissions() < 0) {
+ FR_FAULT_LOG("Refusing to execute panic action: %s", fr_strerror());
+ goto finish;
+ }
+
/* Substitute %p for the current PID (useful for attaching a debugger) */
while ((q = strstr(p, "%p"))) {
out += ret = snprintf(out, left, "%.*s%d", (int) (q - p), p, (int) getpid());
fr_exit_now(128 + sig);
}
-
finish:
/*
* (Re-)Raise the signal, so that if we're running under
- * a debugger, the debugger can break when it receives
- * the signal.
+ * a debugger.
+ *
+ * This allows debuggers to function normally and catch
+ * fatal signals.
*/
- fr_unset_signal(sig); /* Make sure we don't get into a loop */
-
+ fr_unset_signal(sig); /* Make sure we don't get into a loop */
raise(sig);
-
fr_exit_now(128 + sig); /* Function marked as noreturn */
}