summaryrefslogtreecommitdiff
path: root/lib/sigevent.c
AgeCommit message (Collapse)Author
2024-10-17lib: do not log_memstats() in crash handlerDavid Lamparter
`log_memstats()` is not AS-safe. It can hang the crash handler (or set your PC on fire, or cause the sun to go supernova - according to POSIX specs, anyway.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-03-15lib: Prevent crash then another crash from happeningDonald Sharp
When a memory operation (malloc/free/... ) causes a crash and the call to core_handler causes another crash then instead of actually writing a core dump the alarm is hit and the daemon in trouble will not cause a core dump. Modify the shutdown code to just try to dump the buffers and leave instead of cleaning up after itself. Back Trace: (gdb) bt 0 0x00007f17082ec056 in __lll_lock_wait_private () from /lib/x86_64-linux-gnu/libc.so.6 1 0x00007f17082fc8bd in ?? () from /lib/x86_64-linux-gnu/libc.so.6 2 0x00007f17082fee8f in free () from /lib/x86_64-linux-gnu/libc.so.6 3 0x00007f170866c2ea in qfree (mt=<optimized out>, ptr=<optimized out>) at lib/memory.c:141 4 0x00007f17086c156a in zlog_tls_free (arg=0x55584f816fb0) at lib/zlog.c:390 5 zlog_tls_buffer_fini () at lib/zlog.c:346 6 0x00007f1708695e5f in core_handler (signo=11, siginfo=0x7ffd173229f0, context=<optimized out>) at lib/sigevent.c:264 7 <signal handler called> 8 0x00007f17082fd7bc in ?? () from /lib/x86_64-linux-gnu/libc.so.6 9 0x00007f17082ff6e2 in calloc () from /lib/x86_64-linux-gnu/libc.so.6 10 0x00007f1708451e78 in lh_table_new () from /lib/x86_64-linux-gnu/libjson-c.so.5 11 0x00007f170844c979 in json_object_new_object () from /lib/x86_64-linux-gnu/libjson-c.so.5 12 0x000055584e002fd9 in evpn_show_all_routes (vty=vty@entry=0x55584fb5ea00, bgp=bgp@entry=0x55584f82c600, type=<optimized out>, json=json@entry=0x55584f998130, detail=<optimized out>, self_orig=<optimized out>) at bgpd/bgp_evpn_vty.c:3192 13 0x000055584e009ed6 in show_bgp_l2vpn_evpn_route (self=<optimized out>, vty=0x55584fb5ea00, argc=6, argv=0x55584f998970) at bgpd/bgp_evpn_vty.c:5048 14 0x00007f170863af60 in cmd_execute_command_real (vline=vline@entry=0x55584fa87cb0, vty=vty@entry=0x55584fb5ea00, cmd=cmd@entry=0x0, up_level=up_level@entry=0, filter=FILTER_RELAXED) at lib/command.c:1030 15 0x00007f170863b2be in cmd_execute_command (vline=vline@entry=0x55584fa87cb0, vty=vty@entry=0x55584fb5ea00, cmd=cmd@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1089 16 0x00007f170863b550 in cmd_execute (vty=vty@entry=0x55584fb5ea00, cmd=cmd@entry=0x55584fb65160 "sh bgp l2vpn evpn route json", matched=matched@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1257 17 0x00007f17086acc77 in vty_command (vty=vty@entry=0x55584fb5ea00, buf=0x55584fb65160 "sh bgp l2vpn evpn route json") at lib/vty.c:503 18 0x00007f17086ad444 in vty_execute (vty=vty@entry=0x55584fb5ea00) at lib/vty.c:1266 19 0x00007f17086b06c8 in vtysh_read (thread=<optimized out>) at lib/vty.c:2165 20 0x00007f17086a798d in thread_call (thread=thread@entry=0x7ffd17325ce0) at lib/thread.c:2008 21 0x00007f1708660568 in frr_run (master=0x55584f22a120) at lib/libfrr.c:1223 22 0x000055584dfc8c96 in main (argc=<optimized out>, argv=<optimized out>) at bgpd/bgp_main.c:555 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09lib: zebra.h is not using signal.hDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert `struct event_master` to `struct event_loop`Donald Sharp
Let's find a better name for it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert THREAD_XXX macros to EVENT_XXX macrosDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert struct thread_master to struct event_master and it's ilkDonald Sharp
Convert the `struct thread_master` to `struct event_master` across the code base. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_add_XXX functions to event_add_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename `struct thread` to `struct event`Donald Sharp
Effectively a massive search and replace of `struct thread` to `struct event`. Using the term `thread` gives people the thought that this event system is a pthread when it is not Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-08-25lib: Fix extra semicolon after ifWeiguo Li
Signed-off-by: Weiguo Li <liwg06@foxmail.com>
2022-02-23*: Change thread->func to return void instead of intDonald Sharp
The int return value is never used. Modify the code base to just return a void instead. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11*: Convert quagga_signal_X to frr_signal_XDonald Sharp
Naming functions/data structures more appropriately for the project we are actually in. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-05lib: fix spelling nits in more lib filesewlumpkin
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-04-19lib: don't print 2 backtraces for crashesDavid Lamparter
abort() raises SIGABRT, which would confusingly cause a 2nd backtrace to be printed after the first one... Signed-off-by: David Lamparter <equinox@diac24.net>
2021-01-21lib: Allow us to catch abort and do some small cleanupDonald Sharp
When FRR intentionally asserts currently, the assertion stops program execution and any debug logs currently in play may just be lost completely. Attempt to grab the abort and cleanup the log file, maybe we'll have something useful. New behavior: zebra: lib/plist.c:562: void trie_install_fn(struct prefix_list_entry *, struct prefix_list_entry **): Assertion `object->next_best == *updptr || !*updptr' failed. ZEBRA: Received signal 6 at 1611269027 (si_addr 0x7700138569, PC 0x7fdb210cec81); aborting... ZEBRA: zlog_signal+0xb3 7fdb2140aa73 7ffdd8f67c90 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: core_handler+0xd8 7fdb21433e38 7ffdd8f67d90 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: funlockfile+0x50 7fdb2126c140 7ffdd8f67f00 /lib/x86_64-linux-gnu/libpthread.so.0 (mapped at 0x7fdb21258000) ZEBRA: ---- signal ---- ZEBRA: gsignal+0x141 7fdb210cec81 7ffdd8f684b0 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x7fdb21093000) ZEBRA: abort+0x123 7fdb210b8537 7ffdd8f685d0 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x7fdb21093000) ZEBRA: ? 7fdb210b840f 7ffdd8f68700 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x7fdb21093000) ZEBRA: __assert_fail+0x42 7fdb210c7602 7ffdd8f68750 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x7fdb21093000) ZEBRA: trie_install_fn+0x131 7fdb214200c1 7ffdd8f68780 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: trie_walk_affected+0x44 7fdb2141fe14 7ffdd8f687a0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: prefix_list_trie_add+0x12f 7fdb2141e8ff 7ffdd8f687e0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: prefix_list_entry_update_finish+0x192 7fdb2141e752 7ffdd8f68830 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: lib_prefix_list_entry_prefix_modify+0xa4 7fdb213faea4 7ffdd8f68860 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: lib_prefix_list_entry_ipv4_prefix_modify+0xf 7fdb213fa6af 7ffdd8f688c0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: nb_callback_configuration+0x422 7fdb214175c2 7ffdd8f688d0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: nb_candidate_commit_apply+0x66 7fdb21414d86 7ffdd8f68d60 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: nb_candidate_commit+0x66 7fdb21415146 7ffdd8f691f0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: nb_cli_classic_commit+0x5f 7fdb2141784f 7ffdd8f69230 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: nb_cli_apply_changes+0x4ec 7fdb21417e8c 7ffdd8f6b270 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: ip_prefix_list+0x552 7fdb213f7bb2 7ffdd8f6d780 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: cmd_execute_command_real+0x14c 7fdb213e554c 7ffdd8f6e0f0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: cmd_execute_command+0x5d 7fdb213e52bd 7ffdd8f6e130 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: cmd_execute+0xa1 7fdb213e5651 7ffdd8f6e180 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: vty_execute+0x253 7fdb2144b643 7ffdd8f6e1d0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: vtysh_read+0xf9 7fdb214494d9 7ffdd8f70210 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: thread_call+0x8f 7fdb214419ef 7ffdd8f70450 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: frr_run+0x298 7fdb214091a8 7ffdd8f705d0 /lib/libfrr.so.0 (mapped at 0x7fdb213af000) ZEBRA: main+0x300 42e760 7ffdd8f70740 /usr/lib/frr/zebra (mapped at 0x400000) ZEBRA: __libc_start_main+0xea 7fdb210b9d0a 7ffdd8f70820 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x7fdb21093000) ZEBRA: _start+0x2a 42022a 7ffdd8f708f0 /usr/lib/frr/zebra (mapped at 0x400000) ZEBRA: in thread vtysh_read scheduled from lib/vty.c:2688 core_handler: showing active allocations in memory group libfrr core_handler: memstats: Buffer : 2 * 24 core_handler: memstats: Host config : 3 * (variably sized) core_handler: memstats: Command Tokens : 4117 * 72 core_handler: memstats: Command Token Text : 2964 * (variably sized) core_handler: memstats: Command Token Help : 2964 * (variably sized) core_handler: memstats: Command Argument : 7 * (variably sized) core_handler: memstats: Command Argument Name : 1083 * (variably sized) core_handler: memstats: RCU thread : 2 * 128 core_handler: memstats: FRR POSIX Thread : 4 * (variably sized) core_handler: memstats: POSIX sync primitives : 4 * (variably sized) core_handler: memstats: Graph : 25 * 8 core_handler: memstats: Graph Node : 4795 * 32 core_handler: memstats: Hash : 104 * (variably sized) core_handler: memstats: Hash Bucket : 33272 * 32 core_handler: memstats: Hash Index : 52 * (variably sized) core_handler: memstats: Interface : 11 * 272 core_handler: memstats: Connected : 28 * 48 core_handler: memstats: Link List : 83 * 40 core_handler: memstats: Link Node : 127 * 24 core_handler: memstats: Temporary memory : 36903 * (variably sized) core_handler: memstats: Module loading name : 1 * 13 core_handler: memstats: Nexthop : 9 * 136 core_handler: memstats: NetNS Context : 2 * (variably sized) core_handler: memstats: NetNS Name : 1 * 18 core_handler: memstats: Northbound Node : 640 * 1168 core_handler: memstats: Northbound Configuration : 2 * 16 core_handler: memstats: Northbound Configuration Entry: 32398 * 1032 core_handler: memstats: Prefix List : 1 * 80 core_handler: memstats: Prefix List Str : 1 * 26 core_handler: memstats: Prefix List Entry : 32397 * 128 core_handler: memstats: Prefix List Trie Table : 196 * 4096 core_handler: memstats: Prefix : 28 * 48 core_handler: memstats: Privilege information : 3 * (variably sized) core_handler: memstats: Stream FIFO : 1 * 64 core_handler: memstats: Route table : 22 * 56 core_handler: memstats: Route node : 54 * (variably sized) core_handler: memstats: Thread : 25 * 168 core_handler: memstats: Thread master : 12 * (variably sized) core_handler: memstats: Thread Poll Info : 6 * 8192 core_handler: memstats: Thread stats : 16 * 72 core_handler: memstats: Typed-hash bucket : 15 * (variably sized) core_handler: memstats: Typed-heap array : 1 * 576 core_handler: memstats: Vector : 9646 * 16 core_handler: memstats: Vector index : 9646 * (variably sized) core_handler: memstats: VRF : 1 * 200 core_handler: memstats: VTY : 2 * (variably sized) core_handler: memstats: Work queue : 3 * (variably sized) core_handler: memstats: Work queue name string : 2 * (variably sized) core_handler: memstats: YANG module : 6 * 48 core_handler: memstats: log thread-local buffer : 3 * 9752 core_handler: showing active allocations in memory group logging subsystem core_handler: memstats: log file target : 1 * 88 core_handler: showing active allocations in memory group Label Manager core_handler: showing active allocations in memory group Table Manager core_handler: showing active allocations in memory group zebra core_handler: memstats: Zebra Interface Information : 11 * 488 core_handler: memstats: Router Advertisement Prefix : 2 * 48 core_handler: memstats: Zebra DPlane Provider : 1 * 232 core_handler: memstats: Route Entry : 24 * 88 core_handler: memstats: RIB destination : 20 * 88 core_handler: memstats: Nexthop Group Entry : 9 * 88 core_handler: memstats: Nexthop Group Connected : 9 * 40 core_handler: memstats: Zebra Name Space : 5 * (variably sized) core_handler: memstats: RIB table info : 4 * 16 core_handler: memstats: ZEBRA VRF : 1 * 4744 core_handler: memstats: MH global info : 1 * 128 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b4ea0 *updptr: 0x11b5e10 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11b62b0 updptr: 0x11b4eb0 *updptr: 0x0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b5818 *updptr: 0x11b7090 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b5888 *updptr: 0x0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b5910 *updptr: 0x0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b59a0 *updptr: 0x11b87b0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b7100 *updptr: 0x11b87b0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b75a0 *updptr: 0x11b87b0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b7a40 *updptr: 0x11b87b0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x0 updptr: 0x11b7ee0 *updptr: 0x11b87b0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11b8c50 updptr: 0x11b8380 *updptr: 0x11b8c50 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11b90f0 updptr: 0x11b8820 *updptr: 0x11b90f0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11b9590 updptr: 0x11b8cc0 *updptr: 0x11b9590 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11b9a30 updptr: 0x11b9160 *updptr: 0x11b9a30 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11b9ed0 updptr: 0x11b9600 *updptr: 0x11b9ed0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11ba370 updptr: 0x11b9aa0 *updptr: 0x11ba370 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11ba810 updptr: 0x11b9f40 *updptr: 0x11ba810 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11bacb0 updptr: 0x11ba3e0 *updptr: 0x11bacb0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11bb150 updptr: 0x11b4e20 *updptr: 0x0 2021/01/21 17:43:47 ZEBRA: object->next_best: 0x11bb5f0 updptr: 0x11c2560 *updptr: 0x11c1710 fish: Job 2, “sudo /usr/lib/frr/zebra --log s…” terminated by signal SIGABRT (Abort) Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-16lib: When aborting log dataDonald Sharp
When a FRR process dies due to SIGILL/SIGABORT/etc attempt to drain the log buffer. This code change is capturing some missing logs that were not part of the log file on a crash. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-10-26lib: add sigevent_check apiMark Stapp
Add an api that blocks application-handled signals (SIGINT, SIGTERM, e.g.) then tests whether any signals have been received. This helps to manage a race between signal reception and the poll call in the main event loop. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-09-21*: Remove solaris from FRRDonald Sharp
The Solaris code has gone through a deprecation cycle. No-one has said anything to us and worse of all we don't have any test systems running Solaris to know if we are making changes that are breaking on Solaris. Remove it from the system so we can clean up a bit. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2019-07-31lib: make SA_SIGINFO use unconditionalDavid Lamparter
This has been in POSIX for ages & there's no OS left that doesn't support this. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-03lib: simplify SEGV handlerDavid Lamparter
printfrr is AS-Safe, let's simplify the SEGV handler quite a bit by relying on that. Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-03lib: reduce exported var symbolsQuentin Young
Don't need these in our DSO tables Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13*: LIB_[ERR|WARN] -> EC_LIBQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-06lib: Convert sigevent.c to use new error-code-subsystemDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-14*: rename ferr_zlog -> flog_err_sysQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14*: rename zlog_fer -> flog_errQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14lib: Add LIB_ERR_SYSTEM_CALL and convert VRF_SOCKET to SOCKETDonald Sharp
Add a new error code LIB_ERR_SYSTEM_CALL to the ferr subsystem. Additionally convert LIB_ERR_VRF_SOCKET to a more generic LIB_ERR_SOCKET. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-06-18eigrpd, lib, vtysh: unused vars (cppcheck)paco
Signed-off-by: F. Aragon <paco@voltanet.io>
2018-03-27*: use C99 standard fixed-width integer typesQuentin Young
The following types are nonstandard: - u_char - u_short - u_int - u_long - u_int8_t - u_int16_t - u_int32_t Replace them with the C99 standard types: - uint8_t - unsigned short - unsigned int - unsigned long - uint8_t - uint16_t - uint32_t Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-24lib: centralized memstats-at-exitDavid Lamparter
adds a new all-daemon "debug memstats-at-exit" command. Also saves memstats to a file in /tmp, useful if a long-running daemon is having weird issues (e.g. in a user install). Fixes: #437 Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-22Revert "*: reindent pt. 2"David Lamparter
This reverts commit c14777c6bfd0a446c85243d3a9835054a259c276. clang 5 is not widely available enough for people to indent with. This is particularly problematic when rebasing/adjusting branches. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17*: reindent pt. 2whitespace / reindent
w/ clang 5 * reflow comments * struct members go 1 per line * binpack algo was adjusted
2017-07-17*: reindentreindent-master-afterwhitespace / reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'` Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15*: make consistent & update GPLv2 file headersDavid Lamparter
The FSF's address changed, and we had a mixture of comment styles for the GPL file header. (The style with * at the beginning won out with 580 to 141 in existing files.) Note: I've intentionally left intact other "variations" of the copyright header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-09*: update thread_add_* callsQuentin Young
Pass pointer to pointer instead of assigning by return value. See previous commit message. To ensure that the behavior stays functionally correct, any assignments with the result of a thread_add* function have been transformed to set the pointer to null before passing it. These can be removed wherever the pointer is known to already be null. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-09*: remove THREAD_ON macros, add nullity checkQuentin Young
The way thread.c is written, a caller who wishes to be able to cancel a thread or avoid scheduling it twice must keep a reference to the thread. Typically this is done with a long lived pointer whose value is checked for null in order to know if the thread is currently scheduled. The check-and-schedule idiom is so common that several wrapper macros in thread.h existed solely to provide it. This patch removes those macros and adds a new parameter to all thread_add_* functions which is a pointer to the struct thread * to store the result of a scheduling call. If the value passed is non-null, the thread will only be scheduled if the value is null. This helps with consistency. A Coccinelle spatch has been used to transform code of the form: if (t == NULL) t = thread_add_* (...) to the form thread_add_* (..., &t) The THREAD_ON macros have also been transformed to the underlying thread.c calls. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-03-31lib: make sure SEGV handler cannot lock upDavid Lamparter
Just adding -pthread to gcc options changes libc's behaviour, e.g. making malloc() use proper locking. This means a SEGV inside malloc() (e.g. because malloc bookkeeping structures have been damaged by writing to a broken pointer) can lead to a lockup by the following chain: - random_function() - malloc() --- SEGV - core_handler() - zlog_backtrace_sigsafe() - backtrace() - malloc() This will hang forever waiting for the malloc() lock to be released. Another failure mode is dynamic linking with lazy binding (-z lazy, default). Since backtrace() is seldomly used, this means the call to backtrace() in the core handler can in fact result in the dynamic linker trying to resolve the "backtrace" symbol, which can also deadlock. Add several safeguards to prevent any of this from happening. (Unfortunately, these are not theoretical issues - I found them by running into them headfirst.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-03-27ldpd: ignore the SIGHUP signal in the child processesRenato Westphal
Only the parent process should handle the SIGHUP signal, but we need to make sure that this signal is ignored in the child processes so a command like "killall -SIGHUP ldpd" won't kill ldpd. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-09-03lib: dump memory stats on coreLou Berger
2016-05-26[lib] Add support for backtrace on more platformsJoakim Tjernlund
* lib/sigevent.c: (program_counter) extend to support more platforms. Joint effort with Paul Jakma. (cherry picked from commit b166ea2dda9f04a8b75e0bf5adb7064580695f22)
2012-10-25*: use array_size() helper macroBalaji.G
Use the array_size() helper macro. Replaces several instances of local macros with the same definition. Reviewed-by: Scott Feldman <sfeldma@cumulusnetworks.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2005-05-062005-05-06 Paul Jakma <paul@dishone.st>paul
* (general) extern and static'ification of functions in code and header. Cleanup any definitions with unspecified arguments. Add casts for callback assignments where the callback is defined, typically, as passing void *, but the function being assigned has some other pointer type defined as its argument, as gcc complains about casts from void * to X* via function arguments. Fix some old K&R style function argument definitions. Add noreturn gcc attribute to some functions, as appropriate. Add unused gcc attribute to some functions (eg ones meant to help while debugging) Add guard defines to headers which were missing them. * command.c: (install_node) add const qualifier, still doesnt shut up the warning though, because of the double pointer. (cmp_node) ditto * keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived fromn vty.h ones to fix some of the (long) < 0 warnings. * thread.c: (various) use thread_empty (cpu_record_hash_key) should cast to uintptr_t, a stdint.h type * vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they removed from ospfd/ospf_vty.h * zebra.h: Move definition of ZEBRA_PORT to here, to remove dependence of lib on zebra/zserv.h
2005-04-082005-04-08 Andrew J. Schorr <ajschorr@alumni.princeton.edu>ajs
* sigevent.c: On GNU_LINUX, check whether __USE_GNU is already defined.
2005-01-182005-01-18 Andrew J. Schorr <ajschorr@alumni.princeton.edu>ajs
* log.h: Test for SA_SIGINFO to see whether zlog_signal takes final two args (siginfo and program_counter). * log.c: (hex_append) Include this function only if SA_SIGINFO or HAVE_GLIBC_BACKTRACE is defined. (zlog_signal) Final two args (siginfo and program_counter) now depend on whether SA_SIGINFO is defined on this platform. * sigevent.c: (program_counter) Do not include this function if SA_SIGINFO is not defined on this platform. (exit_handler,core_handler) Test for SA_SIGINFO to decide whether 2nd & 3rd arguments are present and to decide how to invoke zlog_signal. (trap_default_signals) Test for SA_SIGINFO and invoke sigaction appropriately.
2005-01-122005-01-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>ajs
* configure.ac: Test for header file <ucontext.h> (for use in signal processing). * sigevent.c: (trap_default_signals) Use the SA_SIGINFO flag to pass additional siginfo_t and ucontext_t arguments to core_handler and exit_handler. (core_handler,exit_handler) Now invoked with 3 arguments (using SA_SIGINFO). Pass additional info to zlog_signal. (program_counter) New function to find program counter in ucontext_t, needs to be enhanced to support more platforms (currently works only on Linux/x86). * log.h: Change the zlog_signal prototype to add new arguments siginfo_t * and program_counter. * log.c: (zlog_signal) Add new arguments siginfo and program_counter. Include si_addr and program counter (if non-NULL) in message. And remove #ifdef HAVE_GLIBC_BACKTRACE around hex_append, since that is now used to render the si_addr and PC pointers.
2004-12-152004-12-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>ajs
* sigevent.c: (trap_default_signals) Ignore SIGPIPE instead of exiting.
2004-11-232004-11-23 Andrew J. Schorr <ajschorr@alumni.princeton.edu>ajs
* sigevent.c: (signal_init) Set up some default signal handlers so that processes will issue an error message before terminating or dumping core. (trap_default_signals) New function to set up signal handlers for various signals that may kill the process. (exit_handler) Call zlog_signal, then _exit. (core_handler) Call zlog_signal, then abort. * log.h: Declare new function zlog_signal. * log.c: (zlog_signal) New function to log information about a received signal before the process dies. Try to log a backtrace also. (quagga_signal_handler,signal_set) Should be static.
2004-07-222004-07-14 Paul Jakma <paul@dishone.st>paul
* sigevent.c: (quagga_signal_handler) add a global caught flag, set the flags to a constant rather increment to be kinder. (quagga_sigevent_process) new function, to do core of what quagga_signal_timer did. dont block signals at all as sig->caught is volatile sig_atomic_t and should be safe to access from signal and normal contexts. The signal blocking is unneeded paranoia, but is left intact under an ifdef, should some platform require it. Check global caught flag before iterating through array. (quagga_signal_timer) nearly everything moved to quagga_sigevent_process. Left in under ifdef, in case some platform could use a regular timer check for signals. * sigevent.h: quagga_sigevent_process declaration. * thread.c: (thread_fetch) check for signals at beginning of scheduler loop, check for signals if select returns EINTR.
2004-07-132004-07-13 Greg Troxel <gdt@poblano.ir.bbn.com>gdt
* sigevent.c: Don't block SIGTRAP and SIGKILL. Blocking SIGTRAP confuses gdb, at least on NetBSD 2.0_BETA, where the block succeeds.
2004-01-192004-01-19 Paul Jakma <paul@dishone.st>paul
* sigevent.{c,h}: New files, implement event handled signals. see signal_init() in sigevent.h.