From: Alberto Leiva Popper Date: Wed, 28 Dec 2022 22:12:45 +0000 (-0600) Subject: Compile backtrace out if unavailable on system X-Git-Tag: 1.5.4~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77d73e6d01c009ae2a342ae4b2c6abf311ae263b;p=thirdparty%2FFORT-validator.git Compile backtrace out if unavailable on system backtrace() is a glibc-only feature. Some systems, such as Alpine, do not support glibc. It seems one solution is to rely on community ports, but I imagine it'd be best to offload such a decision to the user. Not the safest. Instead, if backtrace() is not available, just delete stack traces from the binary. It's going to be a pain to debug, but that's the world we live in, I guess. Turns libexec into an optional dependency. Fixes #87. Also, the commit contains a review and update of the documentation's Alpine dependency list. There was a lot of fat in there. --- diff --git a/configure.ac b/configure.ac index 3d9e0e8d..c7e7870c 100644 --- a/configure.ac +++ b/configure.ac @@ -29,9 +29,12 @@ AC_SEARCH_LIBS([pthread_create], [pthread], [], AC_SEARCH_LIBS([X509_get_version], [crypto], [], [AC_MSG_ERROR([unable to find the X509_get_version() function])] ) -AC_SEARCH_LIBS([backtrace],[execinfo],[], - [AC_MSG_ERROR([unable to find backtrace() function])] + +AC_SEARCH_LIBS([backtrace],[execinfo], + [have_backtrace="yes"], + [have_backtrace="no"] ) +AM_CONDITIONAL([BACKTRACE_ENABLED], [test "x$have_backtrace" != "xno"]) # Dependencies managed by pkg-config # By the way: Apparently PKG_CHECK_MODULES is poor practice now. I can't tell; diff --git a/docs/installation.md b/docs/installation.md index f3c137cf..9407ec35 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -407,7 +407,7 @@ The following steps are for Alpine Linux 3.12.0 {% highlight bash %} su -apk add build-base autoconf automake pkgconfig openssl openssl-dev jansson jansson-dev bsd-compat-headers rsync libexecinfo libexecinfo-dev libxml2 libxml2-dev libcurl curl-dev +apk add build-base autoconf automake pkgconfig openssl-dev jansson-dev curl-dev libxml2-dev bsd-compat-headers rsync exit wget https://github.com/NICMx/FORT-validator/releases/download/{{ site.fort-latest-version }}/fort-{{ site.fort-latest-version }}.tar.gz diff --git a/src/Makefile.am b/src/Makefile.am index f323d665..ad6c8f78 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -132,6 +132,9 @@ fort_CFLAGS = -Wall -Wno-cpp -Wpedantic # Feel free to temporarily remove this one if you're not using gcc 7.3.0. #fort_CFLAGS += $(GCC_WARNS) fort_CFLAGS += -std=gnu11 -O2 -g $(FORT_FLAGS) ${XML2_CFLAGS} +if BACKTRACE_ENABLED +fort_CFLAGS += -DBACKTRACE_ENABLED +endif fort_LDFLAGS = $(LDFLAGS_DEBUG) fort_LDADD = ${JANSSON_LIBS} ${CURL_LIBS} ${XML2_LIBS} diff --git a/src/log.c b/src/log.c index 7ed560bd..2d28bb98 100644 --- a/src/log.c +++ b/src/log.c @@ -1,6 +1,9 @@ #include "log.h" +#ifdef BACKTRACE_ENABLED #include +#endif + #include #include #include @@ -66,6 +69,7 @@ static pthread_mutex_t logck; void print_stack_trace(char const *title) { +#ifdef BACKTRACE_ENABLED #define STACK_SIZE 64 void *array[STACK_SIZE]; @@ -97,6 +101,7 @@ print_stack_trace(char const *title) } free(strings); +#endif /* BACKTRACE_ENABLED */ } static void init_config(struct log_config *cfg, bool unit_tests) @@ -109,6 +114,8 @@ static void init_config(struct log_config *cfg, bool unit_tests) cfg->facility = LOG_DAEMON; } +#ifdef BACKTRACE_ENABLED + static void sigsegv_handler(int signum) { @@ -135,6 +142,8 @@ sigsegv_handler(int signum) kill(getpid(), signum); } +#endif + /* * Register better handlers for some signals. * @@ -143,6 +152,7 @@ sigsegv_handler(int signum) static void register_signal_handlers(void) { +#ifdef BACKTRACE_ENABLED struct sigaction action; void* dummy; @@ -166,6 +176,7 @@ register_signal_handlers(void) pr_op_err("SIGSEGV handler registration failure: %s", strerror(errno)); } +#endif /* * SIGPIPE can be triggered by any I/O function. libcurl is particularly