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