The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
debug.c
Go to the documentation of this file.
1/*
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.
6 *
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.
11 *
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
15 */
16
17/** Functions to help with debugging
18 *
19 * @file src/lib/util/debug.c
20 *
21 * @copyright 2013 The FreeRADIUS server project
22 * @copyright 2013 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 */
24#include <freeradius-devel/util/backtrace.h>
25#include <freeradius-devel/util/debug.h>
26#include <freeradius-devel/util/hash.h>
27#include <freeradius-devel/util/strerror.h>
28#include <freeradius-devel/util/syserror.h>
29
30#include <pthread.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <sys/stat.h>
34#include <sys/wait.h>
35
36#if defined(HAVE_MALLOPT) && defined(HAVE_MALLOC_H)
37# include <malloc.h>
38#endif
39
40#ifdef HAVE_SYS_PRCTL_H
41# include <sys/prctl.h>
42#endif
43
44#ifdef HAVE_SYS_PROCCTL_H
45# include <sys/procctl.h>
46#endif
47
48#ifdef HAVE_SYS_PTRACE_H
49# include <sys/ptrace.h>
50# if !defined(PT_ATTACH) && defined(PTRACE_ATTACH)
51# define PT_ATTACH PTRACE_ATTACH
52# endif
53# if !defined(PT_DETACH) && defined(PTRACE_DETACH)
54# define PT_DETACH PTRACE_DETACH
55# endif
56#endif
57
58#ifdef HAVE_SYS_RESOURCE_H
59# include <sys/resource.h>
60#endif
61
62#ifdef __APPLE__
63#include <sys/sysctl.h>
64#endif
65
66static char panic_action[512]; //!< The command to execute when panicking.
67static fr_fault_cb_t panic_cb = NULL; //!< Callback to execute whilst panicking, before the
68 //!< panic_action.
69
70static bool dump_core; //!< Whether we should drop a core on fatal signals.
71
72int fr_fault_log_fd = STDERR_FILENO; //!< Where to write debug output.
73
74fr_debug_state_t fr_debug_state = DEBUGGER_STATE_UNKNOWN; //!< Whether we're attached to by a debugger.
75
76#ifdef HAVE_SYS_RESOURCE_H
77static struct rlimit init_core_limit;
78#endif
79
80static TALLOC_CTX *talloc_autofree_ctx;
81
82/*
83 * On BSD systems, ptrace(PT_DETACH) uses a third argument for
84 * resume address, with the magic value (void *)1 to resume where
85 * process stopped. Specifying NULL there leads to a crash because
86 * process resumes at address 0.
87 */
88#if defined(HAVE_SYS_PTRACE_H)
89# ifdef __linux__
90# define _PTRACE(_x, _y) ptrace(_x, _y, NULL, NULL)
91# define _PTRACE_DETACH(_x) ptrace(PT_DETACH, _x, NULL, NULL)
92# elif !defined(__APPLE__) && !defined(__EMSCRIPTEN__) && !defined(HAVE_SYS_PROCCTL_H)
93# define _PTRACE(_x, _y) ptrace(_x, _y, NULL, 0)
94# define _PTRACE_DETACH(_x) ptrace(PT_DETACH, _x, (void *)1, 0)
95#endif
96
97# ifdef HAVE_CAPABILITY_H
98# include <sys/capability.h>
99# endif
100#endif
101
102#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H
103# include <sanitizer/lsan_interface.h>
104#endif
105
106#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H
107static int lsan_test_pipe[2] = {-1, -1};
108static int lsan_test_pid = -1;
109static int lsan_state = INT_MAX;
110static bool lsan_disable = false; //!< Explicitly disable LSAN
111
112/*
113 * Some versions of lsan_interface.h are broken and don't declare
114 * the prototypes of the functions properly, omitting the zero argument
115 * specifier (void), so we need to disable the warning.
116 *
117 * Observed with clang 5.
118 */
119DIAG_OFF(missing-prototypes)
120/** Callback for LSAN - do not rename
121 *
122 */
123char const CC_HINT(used) *__lsan_default_suppressions(void)
124{
125 return
126 "leak:CRYPTO_THREAD_lock_new\n" /* OpenSSL init leak - reported by heaptrack */
127 /* librdkafka initialises Cyrus SASL on first rd_kafka_new(), which dlopens
128 * libsasl2 and never unloads it. Not an rlm_kafka bug. */
129 "leak:rd_kafka_sasl_cyrus_global_init\n"
130#if defined(__APPLE__)
131 "leak:*gmtsub*\n"
132 "leak:ImageLoaderMachO::doImageInit\n"
133 "leak:initializeNonMetaClass\n"
134 "leak:_st_tzset_basic\n"
135 "leak:attachCategories\n"
136 "leak:fork\n"
137 "leak:getaddrinfo\n"
138 "leak:getpwuid_r\n"
139 "leak:libSystem_atfork_child\n"
140 "leak:libsystem_notify\n"
141 "leak:load_images\n"
142 "leak:newlocale\n"
143 /* Perl >= 5.32.0 - Upstream bug, tracked by https://github.com/Perl/perl5/issues/18108 */
144 "leak:perl_construct\n"
145 "leak:realizeClassWithoutSwift\n"
146 "leak:tzset\n"
147 "leak:tzsetwall_basic\n"
148 /* macOS Objective-C runtime and CoreFoundation lazily allocate
149 * metadata on first class touch (e.g. inside libsasl2 which
150 * librdkafka dlopens, or on dispatch-apply worker threads).
151 * These stacks have no symbols, only library paths; suppress by
152 * path substring since the process-wide state is reclaimed on
153 * exit by the OS. */
154 "leak:libobjc.A.dylib\n"
155 "leak:CoreFoundation.framework\n"
156#elif defined(__linux__)
157 "leak:*getpwnam_r*\n" /* libc startup leak - reported by heaptrack */
158 "leak:_dl_init\n" /* dl startup leak - reported by heaptrack */
159 "leak:initgroups\n" /* libc startup leak - reported by heaptrack */
160 "leak:kqueue\n"
161#endif
162 ;
163}
164
165/** Callback for LSAN - do not rename
166 *
167 * Turn off suppressions by default as it interferes with interpreting
168 * output from some of the test utilities.
169 */
170char const CC_HINT(used) *__lsan_default_options(void)
171{
172 return "print_suppressions=0";
173}
174
175/** Callback for LSAN - do not rename
176 *
177 */
178int CC_HINT(used) __lsan_is_turned_off(void)
179{
180 uint8_t ret = 1;
181
182 /* Disable LSAN explicitly - Used for tests involving fork() */
183 if (lsan_disable) return 1;
184
185 /* Parent */
186 if (lsan_test_pid != 0) return 0;
187
188 /* Child */
189 if (write(lsan_test_pipe[1], &ret, sizeof(ret)) < 0) {
190 fprintf(stderr, "Writing LSAN status failed: %s", fr_syserror(errno));
191 }
192 close(lsan_test_pipe[1]);
193 return 0;
194}
195DIAG_ON(missing-prototypes)
196
197/** Determine if we're running under LSAN (Leak Sanitizer)
198 *
199 * @return
200 * - 0 if we're not.
201 * - 1 if we are.
202 * - -1 if we can't tell because of an error.
203 * - -2 if we can't tell because we were compiled with support for the LSAN interface.
204 */
205int fr_get_lsan_state(void)
206{
207 uint8_t ret = 0;
208
209 if (lsan_state != INT_MAX) return lsan_state;/* Use cached result */
210
211 if (pipe(lsan_test_pipe) < 0) {
212 fr_strerror_printf("Failed opening internal pipe: %s", fr_syserror(errno));
213 return -1;
214 }
215
216 lsan_test_pid = fork();
217 if (lsan_test_pid == -1) {
218 fr_strerror_printf("Error forking: %s", fr_syserror(errno));
219 return -1;
220 }
221
222 /* Child */
223 if (lsan_test_pid == 0) {
224 close(lsan_test_pipe[0]); /* Close parent's side */
225 exit(EXIT_SUCCESS); /* Results in LSAN calling __lsan_is_turned_off via onexit handler */
226 }
227
228 /* Parent */
229 close(lsan_test_pipe[1]); /* Close child's side */
230
231 while ((read(lsan_test_pipe[0], &ret, sizeof(ret)) < 0) && (errno == EINTR));
232
233 close(lsan_test_pipe[0]); /* Close our side (so we don't leak FDs) */
234
235 /* Collect child */
236 waitpid(lsan_test_pid, NULL, 0);
237
238 lsan_state = ret; /* Cache test results */
239
240 return ret;
241}
242#else
244{
245 fr_strerror_const("Not built with support for LSAN interface");
246 return -2;
247}
248#endif
249
250#if defined(HAVE_SYS_PROCCTL_H)
251int fr_get_debug_state(void)
252{
253 int status;
254
255 if (procctl(P_PID, getpid(), PROC_TRACE_STATUS, &status) == -1) {
256 fr_strerror_printf("Cannot get dumpable flag: procctl(PROC_TRACE_STATUS) failed: %s", fr_syserror(errno));
258 }
259
260 /*
261 * As FreeBSD docs say about "PROC_TRACE_STATUS":
262 *
263 * Returns the current tracing status for the specified process in the
264 * integer variable pointed to by data. If tracing is disabled, data
265 * is set to -1. If tracing is enabled, but no debugger is attached by
266 * the ptrace(2) syscall, data is set to 0. If a debugger is attached,
267 * data is set to the pid of the debugger process.
268 */
269 if (status <= 0) return DEBUGGER_STATE_NOT_ATTACHED;
270
272}
273#elif defined(__APPLE__)
274/** The ptrace_attach() method no longer works as of macOS 11.4 (we always get eperm)
275 *
276 * Apple published this helpful article here which provides the
277 * magical invocation: https://developer.apple.com/library/archive/qa/qa1361/_index.html
278 *
279 * @return
280 * - 0 if we're not.
281 * - 1 if we are.
282 * - -1
283 */
284int fr_get_debug_state(void)
285{
286 int ret;
287 int mib[4];
288 struct kinfo_proc info;
289 size_t size;
290
291 /*
292 * Initialize the flags so that, if sysctl fails for some
293 * reason, we get a predictable result.
294 */
295 info.kp_proc.p_flag = 0;
296
297 /*
298 * Initialize mib, which tells sysctl the info we want, in this case
299 * we're looking for information about a specific process ID.
300 */
301 mib[0] = CTL_KERN;
302 mib[1] = KERN_PROC;
303 mib[2] = KERN_PROC_PID;
304 mib[3] = getpid();
305
306 /* Call sysctl */
307 size = sizeof(info);
308 ret = sysctl(mib, NUM_ELEMENTS(mib), &info, &size, NULL, 0);
309 if (ret != 0) return -1;
310
311 /* We're being debugged if the P_TRACED flag is set */
312 return ((info.kp_proc.p_flag & P_TRACED) != 0);
313}
314#elif defined(HAVE_SYS_PTRACE_H) && !defined(__EMSCRIPTEN__)
315/** Determine if we're running under a debugger by attempting to attach using pattach
316 *
317 * @return
318 * - 0 if we're not.
319 * - 1 if we are.
320 * - -1 if we can't tell because of an error.
321 * - -2 if we can't tell because we don't have the CAP_SYS_PTRACE capability.
322 */
323int fr_get_debug_state(void)
324{
325 int pid;
326
327 int from_child[2] = {-1, -1};
328
329#ifdef HAVE_CAPABILITY_H
330 cap_flag_value_t state;
331 cap_t caps;
332
333 /*
334 * If we're running under linux, we first need to check if we have
335 * permission to to ptrace. We do that using the capabilities
336 * functions.
337 */
338 caps = cap_get_proc();
339 if (!caps) {
340 fr_strerror_printf("Failed getting process capabilities: %s", fr_syserror(errno));
342 }
343
344 if (cap_get_flag(caps, CAP_SYS_PTRACE, CAP_PERMITTED, &state) < 0) {
345 fr_strerror_printf("Failed getting CAP_SYS_PTRACE permitted state: %s",
346 fr_syserror(errno));
347 cap_free(caps);
349 }
350
351 if ((state == CAP_SET) && (cap_get_flag(caps, CAP_SYS_PTRACE, CAP_EFFECTIVE, &state) < 0)) {
352 fr_strerror_printf("Failed getting CAP_SYS_PTRACE effective state: %s",
353 fr_syserror(errno));
354 cap_free(caps);
356 }
357
358 /*
359 * We don't have permission to ptrace, so this test will always fail.
360 */
361 if (state == CAP_CLEAR) {
362 fr_strerror_printf("ptrace capability not set. If debugger detection is required run as root or: "
363 "setcap cap_sys_ptrace+ep <path_to_binary>");
364 cap_free(caps);
366 }
367 cap_free(caps);
368#endif
369
370 if (pipe(from_child) < 0) {
371 fr_strerror_printf("Error opening internal pipe: %s", fr_syserror(errno));
373 }
374
375 pid = fork();
376 if (pid == -1) {
377 fr_strerror_printf("Error forking: %s", fr_syserror(errno));
379 }
380
381 /* Child */
382 if (pid == 0) {
383 int8_t ret = DEBUGGER_STATE_NOT_ATTACHED;
384 int ppid = getppid();
385 int flags;
386
387 /*
388 * Disable the leak checker for this forked process
389 * so we don't get spurious leaks reported.
390 */
391#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H
392 lsan_disable = true;
393#endif
394
395DIAG_OFF(deprecated-declarations)
396 flags = PT_ATTACH;
397DIAG_ON(deprecated-declarations)
398
399 /* Close parent's side */
400 close(from_child[0]);
401
402 /*
403 * FreeBSD is extremely picky about the order of operations here
404 * we need to attach, wait *then* write whilst the parent is still
405 * suspended, then detach, continuing the process.
406 *
407 * If we don't do it in that order the read in the parent triggers
408 * a SIGKILL.
409 */
410 errno = 0;
411 _PTRACE(flags, ppid);
412 if (errno == 0) {
413 /* Wait for the parent to stop */
414 waitpid(ppid, NULL, 0);
415
416 /* Tell the parent what happened */
417 send_status:
418 if (write(from_child[1], &ret, sizeof(ret)) < 0) {
419 fprintf(stderr, "Writing ptrace status to parent failed: %s\n", fr_syserror(errno));
420 }
421
422 /* Detach */
423 _PTRACE_DETACH(ppid);
424
425
426 /*
427 * We call _exit() instead of exit(). This means that we skip the atexit() handlers,
428 * which don't need to run in a temporary child process. Skipping them means that we
429 * avoid dirtying those pages to "clean things up", which is then immediately followed by
430 * exiting.
431 *
432 * Skipping the atexit() handlers also means that we're not worried about memory leaks
433 * because things "aren't cleaned up correctly". We're not exiting cleanly here (and
434 * don't care to exit cleanly). So just exiting with no cleanups is fine.
435 */
436 _exit(0); /* don't run the atexit() handlers. */
437 /*
438 * man ptrace says the following:
439 *
440 * EPERM The specified process cannot be traced. This could be
441 * because the tracer has insufficient privileges (the
442 * required capability is CAP_SYS_PTRACE); unprivileged
443 * processes cannot trace processes that they cannot send
444 * signals to or those running set-user-ID/set-group-ID
445 * programs, for obvious reasons. Alternatively, the process
446 * may already be being traced, or (before Linux 2.6.26) be
447 * init(1) (PID 1).
448 *
449 * In any case, we are very unlikely to be able to attach to
450 * the process from the panic action.
451 *
452 * We checked for CAP_SYS_PTRACE previously, so know that
453 * we _should_ haven been ablle to attach, so if we can't, it's
454 * likely that we're already being traced.
455 */
456 } else if (errno == EPERM) {
458 goto send_status;
459 }
460
461 /*
462 * Unexpected error, we don't know whether we're already running
463 * under a debugger or not...
464 */
466 fprintf(stderr, "Debugger check failed to attach to parent with unexpected error: %s\n", fr_syserror(errno));
467 goto send_status;
468 /* Parent */
469 } else {
470 int8_t ret = DEBUGGER_STATE_UNKNOWN;
471
472 /*
473 * The child writes errno (reason) if pattach failed else 0.
474 *
475 * This read may be interrupted by pattach,
476 * which is why we need the loop.
477 */
478 while ((read(from_child[0], &ret, sizeof(ret)) < 0) && (errno == EINTR));
479
480 /* Close the pipes here (if we did it above, it might race with pattach) */
481 close(from_child[1]);
482 close(from_child[0]);
483
484 /* Collect the status of the child */
485 waitpid(pid, NULL, 0);
486
487 return ret;
488 }
489}
490#else
492{
493 fr_strerror_const("PTRACE not available");
494
496}
497#endif
498
499/** Should be run before using setuid or setgid to get useful results
500 *
501 * @note sets the fr_debug_state global.
502 */
504{
506
507#ifndef NDEBUG
508 /*
509 * There are many reasons why this might happen with
510 * a vanilla install, so we don't want to spam users
511 * with messages they won't understand and may not
512 * want to resolve.
513 */
514 if (fr_debug_state < 0) fprintf(stderr, "Getting debug state failed: %s\n", fr_strerror());
515#endif
516}
517
518/** Return current value of debug_state
519 *
520 * @param state to translate into a humanly readable value.
521 * @return humanly readable version of debug state.
522 */
524{
525 switch (state) {
527 return "Debug state unknown (ptrace functionality not available)";
528
530 return "Debug state unknown (cap_sys_ptrace capability not set)";
531
533 return "Debug state unknown";
534
536 return "Found debugger attached";
537
539 return "Debugger not attached";
540 }
541
542 return "<INVALID>";
543}
544
545/** Break in debugger (if were running under a debugger)
546 *
547 * If the server is running under a debugger this will raise a
548 * SIGTRAP which will pause the running process.
549 *
550 * If the server is not running under debugger then this will do nothing.
551 */
552void fr_debug_break(bool always)
553{
554 if (always) raise(SIGTRAP);
555
558 fprintf(stderr, "Debugger detected, raising SIGTRAP\n");
559 fflush(stderr);
560
561 raise(SIGTRAP);
562 }
563}
564
565static int _panic_on_free(UNUSED char *foo)
566{
567 fr_fault(SIGABRT);
568 return -1; /* this should make the free fail */
569}
570
571/** Insert memory into the context of another talloc memory chunk which
572 * causes a panic when freed.
573 *
574 * @param ctx TALLOC_CTX to monitor for frees.
575 */
576void fr_panic_on_free(TALLOC_CTX *ctx)
577{
578 char *ptr;
579
580 ptr = talloc(ctx, char);
581 talloc_set_destructor(ptr, _panic_on_free);
582}
583
584/** Set the dumpable flag, also controls whether processes can PATTACH
585 *
586 * @param dumpable whether we should allow core dumping
587 */
588#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE) && !defined(__EMSCRIPTEN__)
589static int fr_set_pr_dumpable_flag(bool dumpable)
590{
591 if (prctl(PR_SET_DUMPABLE, dumpable ? 1 : 0) < 0) {
592 fr_strerror_printf("Cannot re-enable core dumps: prctl(PR_SET_DUMPABLE) failed: %s",
593 fr_syserror(errno));
594 return -1;
595 }
596
597 return 0;
598}
599#elif defined(HAVE_SYS_PROCCTL_H)
600static int fr_set_pr_dumpable_flag(bool dumpable)
601{
602 int mode = dumpable ? PROC_TRACE_CTL_ENABLE : PROC_TRACE_CTL_DISABLE;
603
604 if (procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode) == -1) {
605 fr_strerror_printf("Cannot re-enable core dumps: procctl(PROC_TRACE_CTL) failed: %s",
606 fr_syserror(errno));
607 return -1;
608 }
609
610 return 0;
611}
612#else
613static int fr_set_pr_dumpable_flag(UNUSED bool dumpable)
614{
615 fr_strerror_const("Changing value of PR_DUMPABLE not supported on this system");
616 return -2;
617}
618#endif
619
620/** Get the processes dumpable flag
621 *
622 */
623#if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_DUMPABLE) && !defined(__EMSCRIPTEN__)
624static int fr_get_pr_dumpable_flag(void)
625{
626 int ret;
627
628 ret = prctl(PR_GET_DUMPABLE);
629 if (ret < 0) {
630 fr_strerror_printf("Cannot get dumpable flag: %s", fr_syserror(errno));
631 return -1;
632 }
633
634 /*
635 * Linux is crazy and prctl sometimes returns 2 for disabled
636 */
637 if (ret != 1) return 0;
638 return 1;
639}
640#elif defined(HAVE_SYS_PROCCTL_H)
641static int fr_get_pr_dumpable_flag(void)
642{
643 int status;
644
645 if (procctl(P_PID, getpid(), PROC_TRACE_CTL, &status) == -1) {
646 fr_strerror_printf("Cannot get dumpable flag: procctl(PROC_TRACE_CTL) failed: %s", fr_syserror(errno));
647 return -1;
648 }
649
650 /*
651 * There are a few different kinds of disabled, but only
652 * one ENABLE.
653 */
654 if (status != PROC_TRACE_CTL_ENABLE) return 0;
655
656 return 1;
657}
658#else
660{
661 fr_strerror_const("Getting value of PR_DUMPABLE not supported on this system");
662 return -2;
663}
664#endif
665
666
667/** Get the current maximum for core files
668 *
669 * Do this before anything else so as to ensure it's properly initialized.
670 */
672{
673#ifdef HAVE_SYS_RESOURCE_H
674 if (getrlimit(RLIMIT_CORE, &init_core_limit) < 0) {
675 fr_strerror_printf("Failed to get current core limit: %s", fr_syserror(errno));
676 return -1;
677 }
678#endif
679 return 0;
680}
681
682/** Enable or disable core dumps
683 *
684 * @param allow_core_dumps whether to enable or disable core dumps.
685 */
686int fr_set_dumpable(bool allow_core_dumps)
687{
688 dump_core = allow_core_dumps;
689
690#ifdef HAVE_SYS_RESOURCE_H
691 {
692 struct rlimit current;
693
694 /*
695 * Reset the core limits (or disable them)
696 */
697 if (getrlimit(RLIMIT_CORE, &current) < 0) {
698 fr_strerror_printf("Failed to get current core limit: %s", fr_syserror(errno));
699 return -1;
700 }
701
702 if (allow_core_dumps) {
703 if ((current.rlim_cur != init_core_limit.rlim_cur) ||
704 (current.rlim_max != init_core_limit.rlim_max)) {
705 if (setrlimit(RLIMIT_CORE, &init_core_limit) < 0) {
706 fr_strerror_printf("Cannot update core dump limit: %s", fr_syserror(errno));
707
708 return -1;
709 }
710 }
711 /*
712 * We've been told to disable core dumping,
713 * rlim_cur is not set to zero.
714 *
715 * Set rlim_cur to zero, but leave rlim_max
716 * set to whatever the current value is.
717 *
718 * This is because, later, we may need to
719 * re-enable core dumps to allow the debugger
720 * to attach *sigh*.
721 */
722 } else if (current.rlim_cur != 0) {
723 struct rlimit no_core;
724
725 no_core.rlim_cur = 0;
726 no_core.rlim_max = current.rlim_max;
727
728 if (setrlimit(RLIMIT_CORE, &no_core) < 0) {
729 fr_strerror_printf("Failed disabling core dumps: %s", fr_syserror(errno));
730
731 return -1;
732 }
733 }
734 }
735#endif
736 /*
737 * Macro needed so we don't emit spurious errors
738 */
739#if defined(HAVE_SYS_PROCCTL_H) || (defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE))
740 if (fr_set_pr_dumpable_flag(allow_core_dumps) < 0) return -1;
741#endif
742
743 return 0;
744}
745
746/** Reset dumpable state to previously configured value
747 *
748 * Needed after suid up/down
749 *
750 * @return
751 * - 0 on success.
752 * - -1 on failure.
753 */
755{
757}
758
759/** Check to see if panic_action file is world writable
760 *
761 * @return
762 * - 0 if file is OK.
763 * - -1 if the file is world writable.
764 */
766{
767 char const *p, *q;
768 size_t len;
769 char filename[256];
770 struct stat statbuf;
771
772 /*
773 * Try and guess which part of the command is the binary, and check to see if
774 * it's world writable, to try and save the admin from their own stupidity.
775 *
776 * @fixme we should do this properly and take into account single and double
777 * quotes.
778 */
779 if ((q = strchr(panic_action, ' '))) {
780 /*
781 * need to use a static buffer, because allocing memory in a signal handler
782 * is a bad idea and can result in deadlock.
783 */
784 len = snprintf(filename, sizeof(filename), "%.*s", (int)(q - panic_action), panic_action);
785 if (is_truncated(len, sizeof(filename))) {
786 fr_strerror_const("Failed writing panic_action to temporary buffer (truncated)");
787 return -1;
788 }
789 p = filename;
790 } else {
791 p = panic_action;
792 }
793
794 if (stat(p, &statbuf) == 0) {
795#ifdef S_IWOTH
796 if ((statbuf.st_mode & S_IWOTH) != 0) {
797 fr_strerror_printf("panic_action file \"%s\" is globally writable", p);
798 return -1;
799 }
800#endif
801 }
802
803 return 0;
804}
805
806/** Prints a simple backtrace (if execinfo is available) and calls panic_action if set.
807 *
808 * @param sig caught
809 */
811{
812 char cmd[sizeof(panic_action) + 20];
813 char *out = cmd;
814 size_t left = sizeof(cmd), ret;
815
816 char const *p = panic_action;
817 char const *q;
818
819 int code;
820
821 /*
822 * If a debugger is attached, we don't want to run the panic action,
823 * as it may interfere with the operation of the debugger.
824 * If something calls us directly we just raise the signal and let
825 * the debugger handle it how it wants.
826 */
828 FR_FAULT_LOG("RAISING SIGNAL: %s", strsignal(sig));
829 raise(sig);
830 }
831
832 /*
833 * Makes the backtraces slightly cleaner
834 */
835 memset(cmd, 0, sizeof(cmd));
836
837 FR_FAULT_LOG("CAUGHT SIGNAL: %s", strsignal(sig));
838
839 /*
840 * Run the callback if one was registered
841 */
842 if (panic_cb && (panic_cb(sig) < 0)) goto finish;
843
844 fr_backtrace();
845
846 /* No panic action set... */
847 if (panic_action[0] == '\0') {
848 FR_FAULT_LOG("No panic action set");
849 goto finish;
850 }
851
852 /*
853 * Check for administrator sanity.
854 */
855 if (fr_fault_check_permissions() < 0) {
856 FR_FAULT_LOG("Refusing to execute panic action: %s", fr_strerror());
857 goto finish;
858 }
859
860 /* Substitute %p for the current PID (useful for attaching a debugger) */
861 while ((q = strstr(p, "%p"))) {
862 out += ret = snprintf(out, left, "%.*s%d", (int) (q - p), p, (int) getpid());
863 if (left <= ret) {
864 oob:
865 FR_FAULT_LOG("Panic action too long");
866 fr_exit_now(128 + sig);
867 }
868 left -= ret;
869 p = q + 2;
870 }
871 if (strlen(p) >= left) goto oob;
872 strlcpy(out, p, left);
873
874 {
875 bool disable = false;
876
877 FR_FAULT_LOG("Calling: %s", cmd);
878
879 /*
880 * Here we temporarily enable the dumpable flag so if GBD or LLDB
881 * is called in the panic_action, they can pattach to the running
882 * process.
883 */
884 if (fr_get_pr_dumpable_flag() == 0) {
885 if ((fr_set_pr_dumpable_flag(true) < 0) || !fr_get_pr_dumpable_flag()) {
886 FR_FAULT_LOG("Failed setting dumpable flag, pattach may not work: %s", fr_strerror());
887 } else {
888 disable = true;
889 }
890 FR_FAULT_LOG("Temporarily setting PR_DUMPABLE to 1");
891 }
892
893 code = system(cmd);
894
895 /*
896 * We only want to error out here, if dumpable was originally disabled
897 * and we managed to change the value to enabled, but failed
898 * setting it back to disabled.
899 */
900 if (disable) {
901 FR_FAULT_LOG("Resetting PR_DUMPABLE to 0");
902 if (fr_set_pr_dumpable_flag(false) < 0) {
903 FR_FAULT_LOG("Failed resetting dumpable flag to off: %s", fr_strerror());
904 FR_FAULT_LOG("Exiting due to insecure process state");
905 fr_exit_now(EXIT_FAILURE);
906 }
907 }
908
909 FR_FAULT_LOG("Panic action exited with %i", code);
910
911 fr_exit_now(128 + sig);
912 }
913
914finish:
915 /*
916 * (Re-)Raise the signal, so that if we're running under
917 * a debugger.
918 *
919 * This allows debuggers to function normally and catch
920 * fatal signals.
921 */
922 fr_unset_signal(sig); /* Make sure we don't get into a loop */
923 raise(sig);
924 fr_exit_now(128 + sig); /* Function marked as noreturn */
925}
926
927/** Callback executed on fatal talloc error
928 *
929 * This is the simple version which mostly behaves the same way as the default
930 * one, and will not call panic_action.
931 *
932 * @param reason string provided by talloc.
933 */
934static void _fr_talloc_fault_simple(char const *reason) CC_HINT(noreturn);
935static void _fr_talloc_fault_simple(char const *reason)
936{
937 FR_FAULT_LOG("talloc abort: %s\n", reason);
938
939 fr_backtrace();
940 abort();
941}
942
943/** Callback executed on fatal talloc error
944 *
945 * Translates a talloc abort into a fr_fault call.
946 * Mostly to work around issues with some debuggers not being able to
947 * attach after a SIGABRT has been raised.
948 *
949 * @param reason string provided by talloc.
950 */
951static void _fr_talloc_fault(char const *reason) CC_HINT(noreturn);
952static void _fr_talloc_fault(char const *reason)
953{
954 FR_FAULT_LOG("talloc abort: %s", reason);
955#ifdef SIGABRT
956 fr_fault(SIGABRT);
957#endif
958 fr_exit_now(128 + SIGABRT);
959}
960
961/** Wrapper to pass talloc log output to our fr_fault_log function
962 *
963 */
964static void _fr_talloc_log(char const *msg)
965{
966 fr_fault_log("%s\n", msg);
967}
968
969/** Generate a talloc memory report for a context and print to stderr/stdout
970 *
971 * @param ctx to generate a report for, may be NULL in which case the root context is used.
972 */
973int fr_log_talloc_report(TALLOC_CTX const *ctx)
974{
975#define TALLOC_REPORT_MAX_DEPTH 20
976
977 FILE *log;
978 int fd;
979
980 fd = dup(fr_fault_log_fd);
981 if (fd < 0) {
982 fr_strerror_printf("Couldn't write memory report, failed to dup log fd: %s", fr_syserror(errno));
983 return -1;
984 }
985 log = fdopen(fd, "w");
986 if (!log) {
987 close(fd);
988 fr_strerror_printf("Couldn't write memory report, fdopen failed: %s", fr_syserror(errno));
989 return -1;
990 }
991
992 if (!ctx) {
993 fprintf(log, "Current state of talloced memory:\n");
994 talloc_report_full(talloc_null_ctx(), log);
995 } else {
996 int i;
997
998 fprintf(log, "Talloc chunk lineage:\n");
999 fprintf(log, "%p (%s)", ctx, talloc_get_name(ctx));
1000
1001 i = 0;
1002 while ((i < TALLOC_REPORT_MAX_DEPTH) && (ctx = talloc_parent(ctx))) {
1003 fprintf(log, " < %p (%s)", ctx, talloc_get_name(ctx));
1004 i++;
1005 }
1006 fprintf(log, "\n");
1007
1008 i = 0;
1009 do {
1010 fprintf(log, "Talloc context level %i:\n", i++);
1011 talloc_report_full(ctx, log);
1012 } while ((ctx = talloc_parent(ctx)) &&
1014 (talloc_parent(ctx) != talloc_autofree_ctx) && /* Stop before we hit the autofree ctx */
1015 (talloc_parent(ctx) != talloc_null_ctx())); /* Stop before we hit NULL ctx */
1016 }
1017
1018 fclose(log);
1019
1020 return 0;
1021}
1022
1024{
1025 talloc_disable_null_tracking();
1026 return 0;
1027}
1028
1029/** Disable the null tracking context when a talloc chunk is freed
1030 *
1031 */
1033{
1034 bool *marker;
1035
1036 /*
1037 * Disable null tracking on exit, else valgrind complains
1038 */
1039 marker = talloc(ctx, bool);
1040 talloc_set_destructor(marker, _disable_null_tracking);
1041}
1042
1043/** Register talloc fault handlers
1044 *
1045 * Just register the fault handlers we need to make talloc
1046 * produce useful debugging output.
1047 */
1049{
1050 talloc_set_log_fn(_fr_talloc_log);
1051 talloc_set_abort_fn(_fr_talloc_fault_simple);
1052}
1053
1054/** Registers signal handlers to execute panic_action on fatal signal
1055 *
1056 * May be called multiple time to change the panic_action/program.
1057 *
1058 * @param[in] ctx to allocate autofreeable resources in.
1059 * @param[in] cmd to execute on fault. If present %p will be substituted
1060 * for the parent PID before the command is executed, and %e
1061 * will be substituted for the currently running program.
1062 * @param program Name of program currently executing (argv[0]).
1063 * @return
1064 * - 0 on success.
1065 * - -1 on failure.
1066 */
1067int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
1068{
1069 static bool setup = false;
1070
1071 char *out = panic_action;
1072 size_t left = sizeof(panic_action);
1073
1074 char const *p = cmd;
1075 char const *q;
1076
1077 if (cmd) {
1078 size_t ret;
1079
1080 /* Substitute %e for the current program */
1081 while ((q = strstr(p, "%e"))) {
1082 out += ret = snprintf(out, left, "%.*s%s", (int) (q - p), p, program ? program : "");
1083 if (left <= ret) {
1084 oob:
1085 fr_strerror_const("Panic action too long");
1086 return -1;
1087 }
1088 left -= ret;
1089 p = q + 2;
1090 }
1091 if (strlen(p) >= left) goto oob;
1092 strlcpy(out, p, left);
1093 } else {
1094 *panic_action = '\0';
1095 }
1096
1097 /*
1098 * Check for administrator sanity.
1099 */
1100 if (fr_fault_check_permissions() < 0) return -1;
1101
1102 /* Unsure what the side effects of changing the signal handler mid execution might be */
1103 if (!setup) {
1104 char *env;
1105
1106 /*
1107 * Installing signal handlers interferes with some debugging
1108 * operations. Give the developer control over whether the
1109 * signal handlers are installed or not.
1110 */
1111 env = getenv("DEBUGGER_ATTACHED");
1112 if (env && (strcmp(env, "yes") == 0)) {
1113 fr_debug_state = DEBUGGER_STATE_ATTACHED; /* i.e. disable signal handlers */
1114
1115 } else if (env && (strcmp(env, "no") == 0)) {
1116 fr_debug_state = DEBUGGER_STATE_NOT_ATTACHED; /* i.e. enable signal handlers */
1117
1118 /*
1119 * Figure out if we were started under a debugger
1120 */
1121 } else {
1123 }
1124
1125 talloc_set_log_fn(_fr_talloc_log);
1126
1127 /*
1128 * These signals can't be properly dealt with in the debugger
1129 * if we set our own signal handlers.
1130 */
1131 switch (fr_debug_state) {
1132 default:
1134#ifdef SIGABRT
1135 if (fr_set_signal(SIGABRT, fr_fault) < 0) return -1;
1136
1137 /*
1138 * Use this instead of abort so we get a
1139 * full backtrace with broken versions of LLDB
1140 */
1141 talloc_set_abort_fn(_fr_talloc_fault);
1142#endif
1143#ifdef SIGILL
1144 if (fr_set_signal(SIGILL, fr_fault) < 0) return -1;
1145#endif
1146#ifdef SIGFPE
1147 if (fr_set_signal(SIGFPE, fr_fault) < 0) return -1;
1148#endif
1149#ifdef SIGSEGV
1150 if (fr_set_signal(SIGSEGV, fr_fault) < 0) return -1;
1151#endif
1152#ifdef SIGALRM
1153 /*
1154 * This is used be jlibtool to terminate
1155 * processes which have been running too
1156 * long.
1157 */
1158 if (fr_set_signal(SIGALRM, fr_fault) < 0) return -1;
1159#endif
1160 break;
1161
1163 break;
1164 }
1165
1166 /*
1167 * Needed for memory reports
1168 */
1170
1171#if defined(HAVE_MALLOPT) && !defined(NDEBUG)
1172 /*
1173 * If were using glibc malloc > 2.4 this scribbles over
1174 * uninitialised and freed memory, to make memory issues easier
1175 * to track down.
1176 */
1177# ifdef M_PERTURB
1178 if (!getenv("TALLOC_FREE_FILL")) mallopt(M_PERTURB, 0x42);
1179# endif
1180# ifdef M_CHECK_ACTION
1181 mallopt(M_CHECK_ACTION, 3);
1182# endif
1183#endif
1185 }
1186 setup = true;
1187
1188 return 0;
1189}
1190
1191/** Set a callback to be called before fr_fault()
1192 *
1193 * @param func to execute. If callback returns < 0
1194 * fr_fault will exit before running panic_action code.
1195 */
1197{
1198 panic_cb = func;
1199}
1200
1201/** Log output to the fr_fault_log_fd
1202 *
1203 * We used to support a user defined callback, which was set to a radlog
1204 * function. Unfortunately, when logging to syslog, syslog would alloc memory
1205 * which would result in a deadlock if fr_fault was triggered from within
1206 * a allocation call.
1207 *
1208 * Now we just write directly to the FD.
1209 */
1210void fr_fault_log(char const *msg, ...)
1211{
1212 va_list ap;
1213
1214 if (fr_fault_log_fd < 0) return;
1215
1216 va_start(ap, msg);
1218 va_end(ap);
1219}
1220
1221/** Print data as a hex block
1222 *
1223 */
1224void fr_fault_log_hex(uint8_t const *data, size_t data_len)
1225{
1226 size_t i, j, len;
1227 char buffer[(0x10 * 3) + 1];
1228 char *p, *end = buffer + sizeof(buffer);
1229
1230 for (i = 0; i < data_len; i += 0x10) {
1231 len = 0x10;
1232 if ((i + len) > data_len) len = data_len - i;
1233
1234 for (p = buffer, j = 0; j < len; j++, p += 3) snprintf(p, end - p, "%02x ", data[i + j]);
1235
1236 dprintf(fr_fault_log_fd, "%04x: %s\n", (unsigned int) i, buffer);
1237 }
1238}
1239
1240/** Set a file descriptor to log memory reports to.
1241 *
1242 * @param fd to write output to.
1243 */
1245{
1246 fr_fault_log_fd = fd;
1247}
1248
1249/** A soft assertion which triggers the fault handler in debug builds
1250 *
1251 * @param[in] file the assertion failed in.
1252 * @param[in] line of the assertion in the file.
1253 * @param[in] expr that was evaluated.
1254 * @param[in] msg Message to print (may be NULL).
1255 * @param[in] ... Arguments for msg string.
1256 * @return the value of cond.
1257 */
1258bool _fr_assert_fail(char const *file, int line, char const *expr, char const *msg, ...)
1259{
1260 if (msg) {
1261 char str[256]; /* Decent compilers won't allocate this unless fmt is !NULL... */
1262 va_list ap;
1263
1264 va_start(ap, msg);
1265 (void)vsnprintf(str, sizeof(str), msg, ap);
1266 va_end(ap);
1267
1268#ifndef NDEBUG
1269 FR_FAULT_LOG("ASSERT FAILED %s[%d]: %s: %s", file, line, expr, str);
1270 fr_fault(SIGABRT);
1271#else
1272 FR_FAULT_LOG("ASSERT WOULD FAIL %s[%d]: %s: %s", file, line, expr, str);
1273 return false;
1274#endif
1275 }
1276
1277#ifndef NDEBUG
1278 FR_FAULT_LOG("ASSERT FAILED %s[%d]: %s", file, line, expr);
1279 fr_fault(SIGABRT);
1280#else
1281 FR_FAULT_LOG("ASSERT WOULD FAIL %s[%d]: %s", file, line, expr);
1282 return false;
1283#endif
1284}
1285
1286/** A fatal assertion which triggers the fault handler in debug builds or exits
1287 *
1288 * @param[in] file the assertion failed in.
1289 * @param[in] line of the assertion in the file.
1290 * @param[in] expr that was evaluated.
1291 * @param[in] msg Message to print (may be NULL).
1292 * @param[in] ... Arguments for msg string.
1293 */
1294void _fr_assert_fatal(char const *file, int line, char const *expr, char const *msg, ...)
1295{
1296 if (msg) {
1297 char str[256]; /* Decent compilers won't allocate this unless fmt is !NULL... */
1298 va_list ap;
1299
1300 va_start(ap, msg);
1301 (void)vsnprintf(str, sizeof(str), msg, ap);
1302 va_end(ap);
1303
1304 FR_FAULT_LOG("FATAL ASSERT %s[%d]: %s: %s", file, line, expr, str);
1305 } else {
1306 FR_FAULT_LOG("FATAL ASSERT %s[%d]: %s", file, line, expr);
1307 }
1308
1309#ifdef NDEBUG
1310 _fr_exit(file, line, 128 + SIGABRT, true);
1311#else
1312 fr_fault(SIGABRT);
1313#endif
1314}
1315
1316/** Exit possibly printing a message about why we're exiting.
1317 *
1318 * @note Use the fr_exit(status) macro instead of calling this function directly.
1319 *
1320 * @param[in] file where fr_exit() was called.
1321 * @param[in] line where fr_exit() was called.
1322 * @param[in] status we're exiting with.
1323 * @param[in] now Exit immediately.
1324 */
1325#ifndef NDEBUG
1326NEVER_RETURNS void _fr_exit(char const *file, int line, int status, bool now)
1327{
1328 if (status != EXIT_SUCCESS) {
1329 char const *error = fr_strerror();
1330
1331 if (error && *error && (status != 0)) {
1332 FR_FAULT_LOG("%sEXIT(%i) CALLED %s[%d]. Last error was: %s", now ? "_" : "",
1333 status, file, line, error);
1334 } else {
1335 FR_FAULT_LOG("%sEXIT(%i) CALLED %s[%d]", now ? "_" : "", status, file, line);
1336 }
1337
1338 fr_debug_break(false); /* If running under GDB we'll break here */
1339 }
1340
1341 if (now) _Exit(status);
1342 exit(status);
1343}
1344#else
1345NEVER_RETURNS void _fr_exit(UNUSED char const *file, UNUSED int line, int status, bool now)
1346{
1347 if (status != EXIT_SUCCESS) fr_debug_break(false); /* If running under GDB we'll break here */
1348
1349 if (now) _Exit(status);
1350 exit(status);
1351}
1352#endif
static int const char char buffer[256]
Definition acutest.h:576
int const char * file
Definition acutest.h:702
va_end(args)
log_entry msg
Definition acutest.h:794
int const char int line
Definition acutest.h:702
va_start(args, fmt)
void fr_backtrace(void)
Definition backtrace.c:188
void fr_backtrace_init(UNUSED char const *program)
Definition backtrace.c:320
#define NEVER_RETURNS
Should be placed before the function return type.
Definition build.h:334
#define DIAG_ON(_x)
Definition build.h:487
#define UNUSED
Definition build.h:336
#define NUM_ELEMENTS(_t)
Definition build.h:358
#define DIAG_OFF(_x)
Definition build.h:486
#define CAP_PERMITTED
Definition cap.h:50
#define CAP_EFFECTIVE
Definition cap.h:48
static int fr_fault_check_permissions(void)
Check to see if panic_action file is world writable.
Definition debug.c:765
static char panic_action[512]
The command to execute when panicking.
Definition debug.c:66
char const * fr_debug_state_to_msg(fr_debug_state_t state)
Return current value of debug_state.
Definition debug.c:523
static int _disable_null_tracking(UNUSED bool *p)
Definition debug.c:1023
static int _panic_on_free(UNUSED char *foo)
Definition debug.c:565
void fr_disable_null_tracking_on_free(TALLOC_CTX *ctx)
Disable the null tracking context when a talloc chunk is freed.
Definition debug.c:1032
bool _fr_assert_fail(char const *file, int line, char const *expr, char const *msg,...)
A soft assertion which triggers the fault handler in debug builds.
Definition debug.c:1258
void fr_fault_set_log_fd(int fd)
Set a file descriptor to log memory reports to.
Definition debug.c:1244
static bool dump_core
Whether we should drop a core on fatal signals.
Definition debug.c:70
int fr_log_talloc_report(TALLOC_CTX const *ctx)
Generate a talloc memory report for a context and print to stderr/stdout.
Definition debug.c:973
int fr_set_dumpable(bool allow_core_dumps)
Enable or disable core dumps.
Definition debug.c:686
static void _fr_talloc_fault_simple(char const *reason)
Callback executed on fatal talloc error.
Definition debug.c:935
static int fr_set_pr_dumpable_flag(UNUSED bool dumpable)
Set the dumpable flag, also controls whether processes can PATTACH.
Definition debug.c:613
static fr_fault_cb_t panic_cb
Callback to execute whilst panicking, before the panic_action.
Definition debug.c:67
static TALLOC_CTX * talloc_autofree_ctx
Definition debug.c:80
int fr_fault_log_fd
Where to write debug output.
Definition debug.c:72
int fr_reset_dumpable(void)
Reset dumpable state to previously configured value.
Definition debug.c:754
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
Definition debug.c:1067
#define TALLOC_REPORT_MAX_DEPTH
NEVER_RETURNS void fr_fault(int sig)
Prints a simple backtrace (if execinfo is available) and calls panic_action if set.
Definition debug.c:810
int fr_get_lsan_state(void)
Definition debug.c:243
void fr_debug_state_store(void)
Should be run before using setuid or setgid to get useful results.
Definition debug.c:503
NEVER_RETURNS void _fr_exit(char const *file, int line, int status, bool now)
Exit possibly printing a message about why we're exiting.
Definition debug.c:1326
void fr_talloc_fault_setup(void)
Register talloc fault handlers.
Definition debug.c:1048
void fr_debug_break(bool always)
Break in debugger (if were running under a debugger)
Definition debug.c:552
void fr_fault_set_cb(fr_fault_cb_t func)
Set a callback to be called before fr_fault()
Definition debug.c:1196
void _fr_assert_fatal(char const *file, int line, char const *expr, char const *msg,...)
A fatal assertion which triggers the fault handler in debug builds or exits.
Definition debug.c:1294
void fr_fault_log_hex(uint8_t const *data, size_t data_len)
Print data as a hex block.
Definition debug.c:1224
int fr_set_dumpable_init(void)
Get the current maximum for core files.
Definition debug.c:671
void fr_panic_on_free(TALLOC_CTX *ctx)
Insert memory into the context of another talloc memory chunk which causes a panic when freed.
Definition debug.c:576
static void _fr_talloc_fault(char const *reason)
Callback executed on fatal talloc error.
Definition debug.c:952
static void _fr_talloc_log(char const *msg)
Wrapper to pass talloc log output to our fr_fault_log function.
Definition debug.c:964
static int fr_get_pr_dumpable_flag(void)
Get the processes dumpable flag.
Definition debug.c:659
fr_debug_state_t fr_debug_state
Whether we're attached to by a debugger.
Definition debug.c:74
int fr_get_debug_state(void)
Definition debug.c:491
void fr_fault_log(char const *msg,...)
Log output to the fr_fault_log_fd.
Definition debug.c:1210
fr_debug_state_t
Definition debug.h:49
@ DEBUGGER_STATE_NOT_ATTACHED
We can attach, so a debugger must not be.
Definition debug.h:53
@ DEBUGGER_STATE_UNKNOWN_NO_PTRACE
We don't have ptrace so can't check.
Definition debug.h:50
@ DEBUGGER_STATE_UNKNOWN_NO_PTRACE_CAP
CAP_SYS_PTRACE not set for the process.
Definition debug.h:51
@ DEBUGGER_STATE_UNKNOWN
Unknown, likely fr_get_debug_state() not called yet.
Definition debug.h:52
@ DEBUGGER_STATE_ATTACHED
We can't attach, it's likely a debugger is already tracing.
Definition debug.h:54
int(* fr_fault_cb_t)(int signum)
Optional callback passed to fr_fault_setup.
Definition debug.h:74
#define FR_FAULT_LOG(_fmt,...)
Definition debug.h:60
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:236
unsigned char uint8_t
static size_t used
int fr_unset_signal(int sig)
Uninstall a signal for a specific handler.
Definition misc.c:76
int fr_set_signal(int sig, sig_t func)
Sets a signal handler using sigaction if available, else signal.
Definition misc.c:47
int vdprintf(int fd, char const *format, va_list args)
Definition missing.c:214
#define is_truncated(_ret, _max)
Definition print.h:48
static char const * mib
Definition radict.c:55
static char const * program
Definition radiusd.c:79
PUBLIC int vsnprintf(char *string, size_t length, char *format, va_list args)
Definition snprintf.c:506
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition strlcpy.c:34
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
Definition talloc.c:49
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
static fr_slen_t data
Definition value.h:1340
static size_t char ** out
Definition value.h:1030