Skip to content

Commit f06154a

Browse files
kgiustiganeshmurthy
authored andcommitted
ISSUE-1083: panic handler for router crashes (#1084)
Very basic stack unwind + register dump to stderr on crash (cherry picked from commit fcee563)
1 parent b90de0e commit f06154a

File tree

12 files changed

+511
-11
lines changed

12 files changed

+511
-11
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ jobs:
834834
dnf config-manager --set-enabled powertools
835835
dnf install --setopt=tsflags=nodocs --setopt=install_weak_deps=False -y epel-release 'dnf-command(copr)' 'dnf-command(builddep)'
836836
dnf copr enable -y clime/rpkg-util
837-
dnf install --setopt=tsflags=nodocs --setopt=install_weak_deps=False -y git rpkg
837+
dnf install --setopt=tsflags=nodocs --setopt=install_weak_deps=False -y git rpkg libunwind-devel
838838
839839
- uses: actions/checkout@v3
840840

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ find_package(LibWebSockets 4.0.1 REQUIRED)
151151
##
152152

153153
find_library(dw_lib dw DOC "libdw used to symbolize QD_MEMORY_DEBUG backtraces")
154+
find_package(libunwind)
154155

155156
# google benchmark tests are disabled by default
156157
OPTION(BUILD_BENCHMARKS "Enable building and running benchmarks with Google Benchmark" OFF)

Containerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest as builder
2121

22-
RUN microdnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \
22+
RUN rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
23+
&& microdnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \
2324
rpm-build \
2425
gcc gcc-c++ make cmake \
2526
cyrus-sasl-devel openssl-devel libuuid-devel \
2627
python3-devel python3-pip \
27-
libnghttp2-devel \
28+
libnghttp2-devel libunwind-devel \
2829
wget tar patch findutils git libasan libubsan libtsan \
2930
&& microdnf clean all -y
3031

@@ -43,11 +44,12 @@ RUN tar zxpf /qpid-proton-image.tar.gz --one-top-level=/image && tar zxpf /skupp
4344
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
4445

4546
# gdb and sanitizers are part of final image as they can be used as debug options for Skupper
46-
RUN microdnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \
47+
RUN rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
48+
&& microdnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \
4749
glibc \
4850
cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl-gssapi openssl \
4951
python3 \
50-
libnghttp2 \
52+
libnghttp2 libunwind \
5153
gdb libasan libubsan libtsan \
5254
gettext hostname iputils \
5355
shadow-utils \

cmake/Findlibunwind.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# Sets LIBUNWIND_LIBRARY to libunwind if it exists
21+
# Sets LIBUNWIND_INCLUDE_DIRS to directory containing libunwind.h header
22+
23+
find_library(LIBUNWIND_LIBRARY unwind DOC "libunwind is used to dump the stack on crash")
24+
25+
find_path(LIBUNWIND_INCLUDE_DIRS libunwind.h
26+
HINTS "${CMAKE_INSTALL_PREFIX}/include"
27+
PATHS "/usr/include")
28+
29+
if (NOT (LIBUNWIND_INCLUDE_DIRS AND LIBUNWIND_LIBRARY))
30+
message(STATUS "libunwind library not found: stack dump on crash disabled")
31+
endif()

include/qpid/dispatch/threading.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ sys_thread_t *sys_thread(const char *thread_name, void *(*run_function) (void *)
6565
void sys_thread_free(sys_thread_t *thread);
6666
void sys_thread_join(sys_thread_t *thread);
6767
sys_thread_t *sys_thread_self(void);
68+
const char *sys_thread_name(sys_thread_t *thread); // use self if thread == 0
6869

6970
#endif

packaging/skupper-router.spec.rpkg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
%global proton_minimum_version 0.34.0
4343
%global libwebsockets_minimum_version 3.0.1
4444
%global libnghttp2_minimum_version 1.33.0
45+
%global libunwind_minimum_version 1.3.1
4546

4647
Name: skupper-router
4748
Version: {{{ git_dir_version }}}
@@ -57,6 +58,7 @@ Requires: libwebsockets >= %{libwebsockets_minimum_version}
5758
Requires: libnghttp2 >= %{libnghttp2_minimum_version}
5859
Requires: cyrus-sasl-plain
5960
Requires: cyrus-sasl-gssapi
61+
Requires: libunwind >= %{libunwind_minimum_version}
6062

6163
BuildRequires: gcc
6264
BuildRequires: gcc-c++
@@ -67,6 +69,7 @@ BuildRequires: python3-devel
6769
BuildRequires: python3-setuptools
6870
BuildRequires: libwebsockets-devel >= %{libwebsockets_minimum_version}
6971
BuildRequires: libnghttp2-devel >= %{libnghttp2_minimum_version}
72+
BuildRequires: libunwind-devel >= %{libunwind_minimum_version}
7073
# man pages --help
7174
BuildRequires: asciidoc
7275
BuildRequires: python3-qpid-proton >= %{proton_minimum_version}

router/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
3030
##
3131
set(router_SOURCES
3232
src/main.c
33+
src/panic.c
3334
)
3435

3536
add_executable(skrouterd ${router_SOURCES})
3637
target_link_libraries(skrouterd skupper-router)
38+
target_link_options(skrouterd PUBLIC LINKER:-Map=skrouterd.map)
3739

3840
install(TARGETS skrouterd RUNTIME DESTINATION sbin)

router/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ static qd_dispatch_t *dispatch = 0;
3939
static qd_log_source_t *log_source = 0;
4040
static const char* argv0 = 0;
4141

42+
// Install the panic handler for fatal signals. see panic.c
43+
extern void panic_handler_init(void);
44+
4245
/**
4346
* Configures the handler function. Specify SIG_IGN to ignore incoming signals.
4447
*/
@@ -91,6 +94,7 @@ static void check(int fd) {
9194

9295
static void main_process(const char *config_path, const char *python_pkgdir, bool test_hooks, int fd)
9396
{
97+
panic_handler_init();
9498
dispatch = qd_dispatch(python_pkgdir, test_hooks);
9599
check(fd);
96100
log_source = qd_log_source("MAIN"); /* Logging is initialized by qd_dispatch. */

0 commit comments

Comments
 (0)