]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Compile backtrace out if unavailable on system
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 28 Dec 2022 22:12:45 +0000 (16:12 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 28 Dec 2022 22:38:00 +0000 (16:38 -0600)
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.

configure.ac
docs/installation.md
src/Makefile.am
src/log.c

index 3d9e0e8d9150b42924befd8a19523a9e657721d0..c7e7870c167ff35b55e9b1e72029a371bf236585 100644 (file)
@@ -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;
index f3c137cfab94e752099d213e33542babb8f4ce11..9407ec35fbaf93a5445314e8b4e787f6bec66906 100644 (file)
@@ -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
index f323d665d507b04c2dbf033a63d604bfc4566bbc..ad6c8f78e1f38999a49f0470f845885324e256cb 100644 (file)
@@ -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}
 
index 7ed560bd52c2e8dcb11febb4feb48fba6dc2de46..2d28bb98f857b53805d961e877c9680ccf27495b 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1,6 +1,9 @@
 #include "log.h"
 
+#ifdef BACKTRACE_ENABLED
 #include <execinfo.h>
+#endif
+
 #include <openssl/bio.h>
 #include <openssl/err.h>
 #include <pthread.h>
@@ -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