2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * @brief Various functions to aid in debugging
21 * @copyright 2013 The FreeRADIUS server project
22 * @copyright 2013 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
25 #include <freeradius-devel/libradius.h>
28 #if defined(HAVE_MALLOPT) && defined(HAVE_MALLOC_H)
33 * runtime backtrace functions are not POSIX but are included in
34 * glibc, OSX >= 10.5 and various BSDs
37 # include <execinfo.h>
40 #ifdef HAVE_SYS_PRCTL_H
41 # include <sys/prctl.h>
44 #ifdef HAVE_SYS_RESOURCE_H
45 # include <sys/resource.h>
49 # define PTHREAD_MUTEX_LOCK pthread_mutex_lock
50 # define PTHREAD_MUTEX_UNLOCK pthread_mutex_unlock
52 # define PTHREAD_MUTEX_LOCK(_x)
53 # define PTHREAD_MUTEX_UNLOCK(_x)
57 # ifndef MAX_BT_FRAMES
58 # define MAX_BT_FRAMES 128
61 # define MAX_BT_CBUFF 1048576 //!< Should be a power of 2
64 # ifdef HAVE_PTHREAD_H
65 static pthread_mutex_t fr_debug_init = PTHREAD_MUTEX_INITIALIZER;
68 typedef struct fr_bt_info {
69 void *obj; //!< Memory address of the block of allocated memory.
70 void *frames[MAX_BT_FRAMES]; //!< Backtrace frame data
71 int count; //!< Number of frames stored
75 void *obj; //!< Pointer to the parent object, this is our needle
76 //!< when we iterate over the contents of the circular buffer.
77 fr_cbuff_t *cbuff; //!< Where we temporarily store the backtraces
81 static char panic_action[512]; //!< The command to execute when panicking.
82 static fr_fault_cb_t panic_cb = NULL; //!< Callback to execute whilst panicking, before the
84 static fr_fault_log_t fr_fault_log = NULL; //!< Function to use to process logging output.
85 static int fr_fault_log_fd = STDERR_FILENO; //!< Where to write debug output.
87 static int fr_debugger_present = -1; //!< Whether were attached to by a debugger.
89 #ifdef HAVE_SYS_RESOURCE_H
90 static struct rlimit core_limits;
93 static TALLOC_CTX *talloc_null_ctx;
94 static TALLOC_CTX *talloc_autofree_ctx;
96 #define FR_FAULT_LOG(fmt, ...) fr_fault_log(fmt "\n", ## __VA_ARGS__)
98 /** Stub callback to see if the SIGTRAP handler is overriden
100 * @param signum signal raised.
102 static void _sigtrap_handler(UNUSED int signum)
104 fr_debugger_present = 0;
105 signal(SIGTRAP, SIG_DFL);
108 /** Break in debugger (if were running under a debugger)
110 * If the server is running under a debugger this will raise a
111 * SIGTRAP which will pause the running process.
113 * If the server is not running under debugger then this will do nothing.
115 void fr_debug_break(void)
117 if (fr_debugger_present == -1) {
118 fr_debugger_present = 0;
119 signal(SIGTRAP, _sigtrap_handler);
121 } else if (fr_debugger_present == 1) {
127 /** Print backtrace entry for a given object
129 * @param cbuff to search in.
130 * @param obj pointer to original object
132 void backtrace_print(fr_cbuff_t *cbuff, void *obj)
137 while ((p = fr_cbuff_rp_next(cbuff, NULL))) {
138 if ((p->obj == obj) || !obj) {
141 fprintf(stderr, "Stacktrace for: %p\n", p->obj);
142 backtrace_symbols_fd(p->frames, p->count, STDERR_FILENO);
147 fprintf(stderr, "No backtrace available for %p", obj);
151 /** Generate a backtrace for an object
153 * If this is the first entry being inserted
155 int fr_backtrace_do(fr_bt_marker_t *marker)
159 if (!fr_assert(marker->obj) || !fr_assert(marker->cbuff)) return -1;
161 bt = talloc_zero(NULL, fr_bt_info_t);
164 bt->obj = marker->obj;
165 bt->count = backtrace(bt->frames, MAX_BT_FRAMES);
167 fr_cbuff_rp_insert(marker->cbuff, bt);
172 /** Inserts a backtrace marker into the provided context
174 * Allows for maximum laziness and will initialise a circular buffer if one has not already been created.
176 * Code augmentation should look something like:
178 // Create a static cbuffer pointer, the first call to backtrace_attach will initialise it
179 static fr_cbuff_t *my_obj_bt;
181 my_obj_t *alloc_my_obj(TALLOC_CTX *ctx) {
184 this = talloc(ctx, my_obj_t);
186 // Attach backtrace marker to object
187 backtrace_attach(&my_obj_bt, this);
193 * Then, later when a double free occurs:
195 (gdb) call backtrace_print(&my_obj_bt, <pointer to double freed memory>)
198 * which should print a limited backtrace to stderr. Note, this backtrace will not include any argument
199 * values, but should at least show the code path taken.
201 * @param cbuff this should be a pointer to a static *fr_cbuff.
202 * @param obj we want to generate a backtrace for.
204 fr_bt_marker_t *fr_backtrace_attach(fr_cbuff_t **cbuff, TALLOC_CTX *obj)
206 fr_bt_marker_t *marker;
208 if (*cbuff == NULL) {
209 PTHREAD_MUTEX_LOCK(&fr_debug_init);
210 /* Check again now we hold the mutex - eww*/
211 if (*cbuff == NULL) *cbuff = fr_cbuff_alloc(NULL, MAX_BT_CBUFF, true);
212 PTHREAD_MUTEX_UNLOCK(&fr_debug_init);
215 marker = talloc(obj, fr_bt_marker_t);
220 marker->obj = (void *) obj;
221 marker->cbuff = *cbuff;
223 fprintf(stderr, "Backtrace attached to %s %p\n", talloc_get_name(obj), obj);
225 * Generate the backtrace for memory allocation
227 fr_backtrace_do(marker);
228 talloc_set_destructor(marker, fr_backtrace_do);
233 void backtrace_print(UNUSED fr_cbuff_t *cbuff, UNUSED void *obj)
235 fprintf(stderr, "Server built without fr_backtrace_* support, requires execinfo.h and possibly -lexecinfo\n");
237 fr_bt_marker_t *fr_backtrace_attach(UNUSED fr_cbuff_t **cbuff, UNUSED TALLOC_CTX *obj)
239 fprintf(stderr, "Server built without fr_backtrace_* support, requires execinfo.h and possibly -lexecinfo\n");
242 #endif /* ifdef HAVE_EXECINFO */
244 static int _panic_on_free(UNUSED char *foo)
247 return -1; /* this should make the free fail */
250 /** Insert memory into the context of another talloc memory chunk which
251 * causes a panic when freed.
253 * @param ctx TALLOC_CTX to monitor for frees.
255 void fr_panic_on_free(TALLOC_CTX *ctx)
259 ptr = talloc(ctx, char);
260 talloc_set_destructor(ptr, _panic_on_free);
263 /** Set the dumpable flag, also controls whether processes can PATTACH
265 * @param dumpable whether we should allow core dumping
267 #if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE)
268 static int fr_set_dumpable_flag(bool dumpable)
270 if (prctl(PR_SET_DUMPABLE, dumpable ? 1 : 0) < 0) {
271 fr_strerror_printf("Cannot re-enable core dumps: prctl(PR_SET_DUMPABLE) failed: %s",
279 static int fr_set_dumpable_flag(UNUSED bool dumpable)
281 fr_strerror_printf("Changing value of PR_DUMPABLE not supported on this system");
286 /** Get the processes dumpable flag
289 #if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_DUMPABLE)
290 static int fr_get_dumpable_flag(void)
294 ret = prctl(PR_GET_DUMPABLE);
296 fr_strerror_printf("Cannot get dumpable flag: %s", fr_syserror(errno));
301 * Linux is crazy and prctl sometimes returns 2 for disabled
303 if (ret != 1) return 0;
307 static int fr_get_dumpable_flag(void)
309 fr_strerror_printf("Getting value of PR_DUMPABLE not supported on this system");
315 /** Get the current maximum for core files
317 * Do this before anything else so as to ensure it's properly initialized.
319 int fr_set_dumpable_init(void)
321 #ifdef HAVE_SYS_RESOURCE_H
322 if (getrlimit(RLIMIT_CORE, &core_limits) < 0) {
323 fr_strerror_printf("Failed to get current core limit: %s", fr_syserror(errno));
330 /** Enable or disable core dumps
332 * @param allow_core_dumps whether to enable or disable core dumps.
334 int fr_set_dumpable(bool allow_core_dumps)
337 * If configured, turn core dumps off.
339 if (!allow_core_dumps) {
340 #ifdef HAVE_SYS_RESOURCE_H
341 struct rlimit no_core;
343 no_core.rlim_cur = 0;
344 no_core.rlim_max = 0;
346 if (setrlimit(RLIMIT_CORE, &no_core) < 0) {
347 fr_strerror_printf("Failed disabling core dumps: %s", fr_syserror(errno));
355 if (fr_set_dumpable_flag(true) < 0) return -1;
358 * Reset the core dump limits to their original value.
360 #ifdef HAVE_SYS_RESOURCE_H
361 if (setrlimit(RLIMIT_CORE, &core_limits) < 0) {
362 fr_strerror_printf("Cannot update core dump limit: %s", fr_syserror(errno));
370 /** Check to see if panic_action file is world writeable
372 * @return 0 if file is OK, else -1.
374 static int fr_fault_check_permissions(void)
382 * Try and guess which part of the command is the binary, and check to see if
383 * it's world writeable, to try and save the admin from their own stupidity.
385 * @fixme we should do this properly and take into account single and double
388 if ((q = strchr(panic_action, ' '))) {
390 * need to use a static buffer, because mallocing memory in a signal handler
391 * is a bad idea and can result in deadlock.
393 len = snprintf(filename, sizeof(filename), "%.*s", (int)(q - panic_action), panic_action);
394 if (is_truncated(len, sizeof(filename))) {
395 fr_strerror_printf("Failed writing panic_action to temporary buffer (truncated)");
403 if (stat(p, &statbuf) == 0) {
405 if ((statbuf.st_mode & S_IWOTH) != 0) {
406 fr_strerror_printf("panic_action file \"%s\" is globally writable", p);
415 /** Prints a simple backtrace (if execinfo is available) and calls panic_action if set.
419 void fr_fault(int sig)
421 char cmd[sizeof(panic_action) + 20];
423 size_t left = sizeof(cmd), ret;
425 char const *p = panic_action;
431 * Makes the backtraces slightly cleaner
433 memset(cmd, 0, sizeof(cmd));
435 FR_FAULT_LOG("CAUGHT SIGNAL: %s", strsignal(sig));
438 * Check for administrator sanity.
440 if (fr_fault_check_permissions() < 0) {
441 FR_FAULT_LOG("Refusing to execute panic action: %s", fr_strerror());
446 * Run the callback if one was registered
448 if (panic_cb && (panic_cb(sig) < 0)) goto finish;
451 * Produce a simple backtrace - They've very basic but at least give us an
452 * idea of the area of the code we hit the issue in.
454 * See below in fr_fault_setup() and
455 * https://sourceware.org/bugzilla/show_bug.cgi?id=16159
456 * for why we only print backtraces in debug builds if we're using GLIBC.
458 #if defined(HAVE_EXECINFO) && (!defined(NDEBUG) || !defined(__GNUC__))
460 size_t frame_count, i;
461 void *stack[MAX_BT_FRAMES];
464 frame_count = backtrace(stack, MAX_BT_FRAMES);
466 FR_FAULT_LOG("Backtrace of last %zu frames:", frame_count);
469 * Only use backtrace_symbols() if we don't have a logging fd.
470 * If the server has experienced memory corruption, there's
471 * a high probability that calling backtrace_symbols() which
472 * mallocs more memory, will fail.
474 if (fr_fault_log_fd < 0) {
475 strings = backtrace_symbols(stack, frame_count);
476 for (i = 0; i < frame_count; i++) {
477 FR_FAULT_LOG("%s", strings[i]);
481 backtrace_symbols_fd(stack, frame_count, fr_fault_log_fd);
486 /* No panic action set... */
487 if (panic_action[0] == '\0') {
488 FR_FAULT_LOG("No panic action set");
492 /* Substitute %p for the current PID (useful for attaching a debugger) */
493 while ((q = strstr(p, "%p"))) {
494 out += ret = snprintf(out, left, "%.*s%d", (int) (q - p), p, (int) getpid());
497 FR_FAULT_LOG("Panic action too long");
503 if (strlen(p) >= left) goto oob;
504 strlcpy(out, p, left);
506 FR_FAULT_LOG("Calling: %s", cmd);
509 bool disable = false;
512 * Here we temporarily enable the dumpable flag so if GBD or LLDB
513 * is called in the panic_action, they can pattach to the running
516 if (fr_get_dumpable_flag() == 0) {
517 if ((fr_set_dumpable_flag(true) < 0) || !fr_get_dumpable_flag()) {
518 FR_FAULT_LOG("Failed setting dumpable flag, pattach may not work: %s", fr_strerror());
522 FR_FAULT_LOG("Temporarily setting PR_DUMPABLE to 1");
528 * We only want to error out here, if dumpable was originally disabled
529 * and we managed to change the value to enabled, but failed
530 * setting it back to disabled.
533 FR_FAULT_LOG("Resetting PR_DUMPABLE to 0");
534 if (fr_set_dumpable_flag(false) < 0) {
535 FR_FAULT_LOG("Failed reseting dumpable flag to off: %s", fr_strerror());
536 FR_FAULT_LOG("Exiting due to insecure process state");
542 FR_FAULT_LOG("Panic action exited with %i", code);
546 if (sig == SIGUSR1) {
554 /** Work around debuggers which can't backtrace past the signal handler
556 * At least this provides us some information when we get talloc errors.
558 static void _fr_talloc_fault(char const *reason)
560 fr_fault_log("talloc abort: %s\n", reason);
565 /** Wrapper to pass talloc log output to our fr_fault_log function
568 static void _fr_talloc_log(char const *msg)
570 fr_fault_log("%s\n", msg);
573 /** Generate a talloc memory report for a context and print to stderr/stdout
575 * @param ctx to generate a report for, may be NULL in which case the root context is used.
577 int fr_log_talloc_report(TALLOC_CTX *ctx)
583 fd = dup(fr_fault_log_fd);
585 fr_strerror_printf("Couldn't write memory report, failed to dup log fd: %s", fr_syserror(errno));
588 log = fdopen(fd, "w");
591 fr_strerror_printf("Couldn't write memory report, fdopen failed: %s", fr_syserror(errno));
596 fprintf(log, "Current state of talloced memory:\n");
597 talloc_report_full(talloc_null_ctx, log);
599 fprintf(log, "Talloc chunk lineage:\n");
600 fprintf(log, "%p (%s)", ctx, talloc_get_name(ctx));
601 while ((ctx = talloc_parent(ctx))) fprintf(log, " < %p (%s)", ctx, talloc_get_name(ctx));
605 fprintf(log, "Talloc context level %i:\n", i++);
606 talloc_report_full(ctx, log);
607 } while ((ctx = talloc_parent(ctx)) &&
608 (talloc_parent(ctx) != talloc_autofree_ctx) && /* Stop before we hit the autofree ctx */
609 (talloc_parent(ctx) != talloc_null_ctx)); /* Stop before we hit NULL ctx */
617 /** Signal handler to print out a talloc memory report
621 static void _fr_fault_mem_report(int sig)
623 FR_FAULT_LOG("CAUGHT SIGNAL: %s", strsignal(sig));
625 if (fr_log_talloc_report(NULL) < 0) fr_perror("memreport");
628 static int _fr_disable_null_tracking(UNUSED bool *p)
630 talloc_disable_null_tracking();
634 /** Registers signal handlers to execute panic_action on fatal signal
636 * May be called multiple time to change the panic_action/program.
638 * @param cmd to execute on fault. If present %p will be substituted
639 * for the parent PID before the command is executed, and %e
640 * will be substituted for the currently running program.
641 * @param program Name of program currently executing (argv[0]).
642 * @return 0 on success -1 on failure.
644 int fr_fault_setup(char const *cmd, char const *program)
646 static bool setup = false;
648 char *out = panic_action;
649 size_t left = sizeof(panic_action), ret;
655 /* Substitute %e for the current program */
656 while ((q = strstr(p, "%e"))) {
657 out += ret = snprintf(out, left, "%.*s%s", (int) (q - p), p, program ? program : "");
660 fr_strerror_printf("Panic action too long");
666 if (strlen(p) >= left) goto oob;
667 strlcpy(out, p, left);
669 *panic_action = '\0';
673 * Check for administrator sanity.
675 if (fr_fault_check_permissions() < 0) return -1;
677 /* Unsure what the side effects of changing the signal handler mid execution might be */
681 if (fr_set_signal(SIGSEGV, fr_fault) < 0) return -1;
684 if (fr_set_signal(SIGBUS, fr_fault) < 0) return -1;
687 if (fr_set_signal(SIGABRT, fr_fault) < 0) return -1;
689 * Use this instead of abort so we get a
690 * full backtrace with broken versions of LLDB
692 talloc_set_abort_fn(_fr_talloc_fault);
695 if (fr_set_signal(SIGFPE, fr_fault) < 0) return -1;
699 if (fr_set_signal(SIGUSR1, fr_fault) < 0) return -1;
703 if (fr_set_signal(SIGUSR2, _fr_fault_mem_report) < 0) return -1;
707 * Setup the default logger
709 if (!fr_fault_log) fr_fault_set_log_fn(NULL);
710 talloc_set_log_fn(_fr_talloc_log);
713 * Needed for memory reports
719 tmp = talloc(NULL, bool);
720 talloc_null_ctx = talloc_parent(tmp);
724 * Disable null tracking on exit, else valgrind complains
726 talloc_autofree_ctx = talloc_autofree_context();
727 marker = talloc(talloc_autofree_ctx, bool);
728 talloc_set_destructor(marker, _fr_disable_null_tracking);
731 #if defined(HAVE_MALLOPT) && !defined(NDEBUG)
733 * If were using glibc malloc > 2.4 this scribbles over
734 * uninitialised and freed memory, to make memory issues easier
737 if (!getenv("TALLOC_FREE_FILL")) mallopt(M_PERTURB, 0x42);
738 mallopt(M_CHECK_ACTION, 3);
741 #if defined(HAVE_EXECINFO) && defined(__GNUC__) && !defined(NDEBUG)
743 * We need to pre-load lgcc_s, else we can get into a deadlock
744 * in fr_fault, as backtrace() attempts to dlopen it.
746 * Apparently there's a performance impact of loading lgcc_s,
747 * so only do it if this is a debug build.
749 * See: https://sourceware.org/bugzilla/show_bug.cgi?id=16159
754 backtrace(stack, 10);
763 /** Set a callback to be called before fr_fault()
765 * @param func to execute. If callback returns < 0
766 * fr_fault will exit before running panic_action code.
768 void fr_fault_set_cb(fr_fault_cb_t func)
773 /** Default logger, logs output to stderr
776 static void CC_HINT(format (printf, 1, 2)) _fr_fault_log(char const *msg, ...)
781 vfprintf(stderr, msg, ap);
786 /** Set a file descriptor to log panic_action output to.
788 * @param func to call to output log messages.
790 void fr_fault_set_log_fn(fr_fault_log_t func)
792 fr_fault_log = func ? func : _fr_fault_log;
795 /** Set a file descriptor to log memory reports to.
797 * @param fd to write output to.
799 void fr_fault_set_log_fd(int fd)
801 fr_fault_log_fd = fd;
805 #ifdef WITH_VERIFY_PTR
808 * Verify a VALUE_PAIR
810 inline void fr_verify_vp(char const *file, int line, VALUE_PAIR const *vp)
813 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR pointer was NULL", file, line);
818 (void) talloc_get_type_abort(vp, VALUE_PAIR);
820 if (vp->data.ptr) switch (vp->da->type) {
827 if (!talloc_get_type(vp->data.ptr, uint8_t)) {
828 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" data buffer type should be "
829 "uint8_t but is %s\n", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
830 (void) talloc_get_type_abort(vp->data.ptr, uint8_t);
833 len = talloc_array_length(vp->vp_octets);
834 if (vp->length > len) {
835 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" length %zu is greater than "
836 "uint8_t data buffer length %zu\n", file, line, vp->da->name, vp->length, len);
841 parent = talloc_parent(vp->data.ptr);
843 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" char buffer is not "
844 "parented by VALUE_PAIR %p, instead parented by %p (%s)\n",
845 file, line, vp->da->name,
846 vp, parent, parent ? talloc_get_name(parent) : "NULL");
858 if (!talloc_get_type(vp->data.ptr, char)) {
859 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" data buffer type should be "
860 "char but is %s\n", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
861 (void) talloc_get_type_abort(vp->data.ptr, char);
864 len = (talloc_array_length(vp->vp_strvalue) - 1);
865 if (vp->length > len) {
866 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" length %zu is greater than "
867 "char buffer length %zu\n", file, line, vp->da->name, vp->length, len);
872 if (vp->vp_strvalue[vp->length] != '\0') {
873 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" char buffer not \\0 "
874 "terminated\n", file, line, vp->da->name);
879 parent = talloc_parent(vp->data.ptr);
881 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" uint8_t buffer is not "
882 "parented by VALUE_PAIR %p, instead parented by %p (%s)\n",
883 file, line, vp->da->name,
884 vp, parent, parent ? talloc_get_name(parent) : "NULL");
899 void fr_verify_list(char const *file, int line, TALLOC_CTX *expected, VALUE_PAIR *vps)
905 for (vp = fr_cursor_init(&cursor, &vps);
907 vp = fr_cursor_next(&cursor)) {
910 parent = talloc_parent(vp);
911 if (expected && (parent != expected)) {
912 FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: Expected VALUE_PAIR \"%s\" to be parented "
913 "by %p (%s), instead parented by %p (%s)\n",
914 file, line, vp->da->name,
915 expected, talloc_get_name(expected),
916 parent, parent ? talloc_get_name(parent) : "NULL");
918 fr_log_talloc_report(expected);
919 if (parent) fr_log_talloc_report(parent);
928 bool fr_assert_cond(char const *file, int line, char const *expr, bool cond)
931 FR_FAULT_LOG("SOFT ASSERT FAILED %s[%u]: %s", file, line, expr);
932 #if !defined(NDEBUG) && defined(SIGUSR1)
941 /** Exit possibly printing a message about why we're exiting.
943 * Use the fr_exit(status) macro instead of calling this function
946 * @param file where fr_exit() was called.
947 * @param line where fr_exit() was called.
948 * @param status we're exiting with.
950 void NEVER_RETURNS _fr_exit(char const *file, int line, int status)
953 char const *error = fr_strerror();
955 if (error && (status != 0)) {
956 FR_FAULT_LOG("EXIT(%i) CALLED %s[%u]. Last error was: %s", status, file, line, error);
958 FR_FAULT_LOG("EXIT(%i) CALLED %s[%u]", status, file, line);
961 fprintf(stderr, "If running under a debugger it should break <<here>>");
964 fr_debug_break(); /* If running under GDB we'll break here */
969 /** Exit possibly printing a message about why we're exiting.
971 * Use the fr_exit_now(status) macro instead of calling this function
974 * @param file where fr_exit_now() was called.
975 * @param line where fr_exit_now() was called.
976 * @param status we're exiting with.
978 void NEVER_RETURNS _fr_exit_now(char const *file, int line, int status)
981 char const *error = fr_strerror();
983 if (error && (status != 0)) {
984 FR_FAULT_LOG("_EXIT(%i) CALLED %s[%u]. Last error was: %s", status, file, line, error);
986 FR_FAULT_LOG("_EXIT(%i) CALLED %s[%u]", status, file, line);
989 fprintf(stderr, "If running under a debugger it should break <<here>>\n");
992 fr_debug_break(); /* If running under GDB we'll break here */