#endif
/* md5.c */
-
void fr_md5_calc(uint8_t *, uint8_t const *, unsigned int);
/* radius.c */
void fr_strerror_printf(char const *, ...) CC_HINT(format (printf, 1, 2));
void fr_perror(char const *, ...) CC_HINT(format (printf, 1, 2));
-extern bool fr_assert_cond(char const *file, int line, char const *expr, bool cond);
-#define fr_assert(_x) fr_assert_cond(__FILE__, __LINE__, #_x, (_x))
-
-extern void NEVER_RETURNS _fr_exit(char const *file, int line, int status);
-#define fr_exit(_x) _fr_exit(__FILE__, __LINE__, (_x))
-
-extern void NEVER_RETURNS _fr_exit_now(char const *file, int line, int status);
-#define fr_exit_now(_x) _fr_exit_now(__FILE__, __LINE__, (_x))
extern char const *fr_strerror(void);
extern char const *fr_syserror(int num);
int fr_crypt_check(char const *key, char const *salt);
/* cbuff.c */
+
typedef struct fr_cbuff fr_cbuff_t;
fr_cbuff_t *fr_cbuff_alloc(TALLOC_CTX *ctx, uint32_t size, bool lock);
void fr_fault_set_log_fn(fr_fault_log_t func);
void fr_fault_set_log_fd(int fd);
-#ifdef WITH_VERIFY_PTR
+# ifdef WITH_VERIFY_PTR
void fr_verify_vp(char const *file, int line, VALUE_PAIR const *vp);
void fr_verify_list(char const *file, int line, TALLOC_CTX *expected, VALUE_PAIR *vps);
-#endif
+# endif
+
+bool fr_assert_cond(char const *file, int line, char const *expr, bool cond);
+# define fr_assert(_x) fr_assert_cond(__FILE__, __LINE__, #_x, (_x))
+
+void NEVER_RETURNS _fr_exit(char const *file, int line, int status);
+# define fr_exit(_x) _fr_exit(__FILE__, __LINE__, (_x))
+
+void NEVER_RETURNS _fr_exit_now(char const *file, int line, int status);
+# define fr_exit_now(_x) _fr_exit_now(__FILE__, __LINE__, (_x))
/* rbtree.c */
typedef struct rbtree_t rbtree_t;
/*
* Here we temporarily enable the dumpable flag so if GBD or LLDB
- * is called in the panic_action, they can pattach tot he running
+ * is called in the panic_action, they can pattach to the running
* process.
*/
if (fr_get_dumpable_flag() == 0) {
*/
static void _fr_fault_mem_report(int sig)
{
- fr_fault_log("CAUGHT SIGNAL: %s\n", strsignal(sig));
+ FR_FAULT_LOG("CAUGHT SIGNAL: %s", strsignal(sig));
if (fr_log_talloc_report(NULL) < 0) fr_perror("memreport");
}
inline void fr_verify_vp(char const *file, int line, VALUE_PAIR const *vp)
{
if (!vp) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR pointer was NULL", file, line);
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR pointer was NULL", file, line);
fr_assert(0);
fr_exit_now(0);
}
TALLOC_CTX *parent;
if (!talloc_get_type(vp->data.ptr, uint8_t)) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" data buffer type should be "
- "uint8_t but is %s\n", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" data buffer type should be "
+ "uint8_t but is %s\n", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
(void) talloc_get_type_abort(vp->data.ptr, uint8_t);
}
len = talloc_array_length(vp->vp_octets);
if (vp->length > len) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" length %zu is greater than "
- "uint8_t data buffer length %zu\n", file, line, vp->da->name, vp->length, len);
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" length %zu is greater than "
+ "uint8_t data buffer length %zu\n", file, line, vp->da->name, vp->length, len);
fr_assert(0);
fr_exit_now(1);
}
parent = talloc_parent(vp->data.ptr);
if (parent != vp) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" char buffer is not "
- "parented by VALUE_PAIR %p, instead parented by %p (%s)\n",
- file, line, vp->da->name,
- vp, parent, parent ? talloc_get_name(parent) : "NULL");
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" char buffer is not "
+ "parented by VALUE_PAIR %p, instead parented by %p (%s)\n",
+ file, line, vp->da->name,
+ vp, parent, parent ? talloc_get_name(parent) : "NULL");
fr_assert(0);
fr_exit_now(1);
}
TALLOC_CTX *parent;
if (!talloc_get_type(vp->data.ptr, char)) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" data buffer type should be "
- "char but is %s\n", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" data buffer type should be "
+ "char but is %s\n", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
(void) talloc_get_type_abort(vp->data.ptr, char);
}
len = (talloc_array_length(vp->vp_strvalue) - 1);
if (vp->length > len) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" length %zu is greater than "
- "char buffer length %zu\n", file, line, vp->da->name, vp->length, len);
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" length %zu is greater than "
+ "char buffer length %zu\n", file, line, vp->da->name, vp->length, len);
fr_assert(0);
fr_exit_now(1);
}
if (vp->vp_strvalue[vp->length] != '\0') {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" char buffer not \\0 "
- "terminated\n", file, line, vp->da->name);
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" char buffer not \\0 "
+ "terminated\n", file, line, vp->da->name);
fr_assert(0);
fr_exit_now(1);
}
parent = talloc_parent(vp->data.ptr);
if (parent != vp) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" uint8_t buffer is not "
- "parented by VALUE_PAIR %p, instead parented by %p (%s)\n",
- file, line, vp->da->name,
- vp, parent, parent ? talloc_get_name(parent) : "NULL");
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR \"%s\" uint8_t buffer is not "
+ "parented by VALUE_PAIR %p, instead parented by %p (%s)\n",
+ file, line, vp->da->name,
+ vp, parent, parent ? talloc_get_name(parent) : "NULL");
fr_assert(0);
fr_exit_now(1);
}
parent = talloc_parent(vp);
if (expected && (parent != expected)) {
- fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: Expected VALUE_PAIR \"%s\" to be parented "
- "by %p (%s), instead parented by %p (%s)\n",
- file, line, vp->da->name,
- expected, talloc_get_name(expected),
- parent, parent ? talloc_get_name(parent) : "NULL");
+ FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: Expected VALUE_PAIR \"%s\" to be parented "
+ "by %p (%s), instead parented by %p (%s)\n",
+ file, line, vp->da->name,
+ expected, talloc_get_name(expected),
+ parent, parent ? talloc_get_name(parent) : "NULL");
fr_log_talloc_report(expected);
if (parent) fr_log_talloc_report(parent);
}
}
#endif
+
+bool fr_assert_cond(char const *file, int line, char const *expr, bool cond)
+{
+ if (!cond) {
+ FR_FAULT_LOG("SOFT ASSERT FAILED %s[%u]: %s", file, line, expr);
+#if !defined(NDEBUG) && defined(SIGUSR1)
+ fr_fault(SIGUSR1);
+#endif
+ return false;
+ }
+
+ return cond;
+}
+
+/** Exit possibly printing a message about why we're exiting.
+ *
+ * Use the fr_exit(status) macro instead of calling this function
+ * directly.
+ *
+ * @param file where fr_exit() was called.
+ * @param line where fr_exit() was called.
+ * @param status we're exiting with.
+ */
+void NEVER_RETURNS _fr_exit(char const *file, int line, int status)
+{
+#ifndef NDEBUG
+ char const *error = fr_strerror();
+
+ if (error && (status != 0)) {
+ FR_FAULT_LOG("EXIT(%i) CALLED %s[%u]. Last error was: %s", status, file, line, error);
+ } else {
+ FR_FAULT_LOG("EXIT(%i) CALLED %s[%u]", status, file, line);
+ }
+#endif
+ fprintf(stderr, "If running under a debugger it should break <<here>>");
+ fflush(stderr);
+
+ fr_debug_break(); /* If running under GDB we'll break here */
+
+ exit(status);
+}
+
+/** Exit possibly printing a message about why we're exiting.
+ *
+ * Use the fr_exit_now(status) macro instead of calling this function
+ * directly.
+ *
+ * @param file where fr_exit_now() was called.
+ * @param line where fr_exit_now() was called.
+ * @param status we're exiting with.
+ */
+void NEVER_RETURNS _fr_exit_now(char const *file, int line, int status)
+{
+#ifndef NDEBUG
+ char const *error = fr_strerror();
+
+ if (error && (status != 0)) {
+ FR_FAULT_LOG("_EXIT(%i) CALLED %s[%u]. Last error was: %s", status, file, line, error);
+ } else {
+ FR_FAULT_LOG("_EXIT(%i) CALLED %s[%u]", status, file, line);
+ }
+#endif
+ fprintf(stderr, "If running under a debugger it should break <<here>>\n");
+ fflush(stderr);
+
+ fr_debug_break(); /* If running under GDB we'll break here */
+
+ _exit(status);
+}