diff --git a/CMakeLists.txt b/CMakeLists.txt index d7ed8f99..3ce8fc36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(NETOPEER2_DESC "NETCONF tools suite including a server and command-line clie set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/") include(GNUInstallDirs) -include(CheckFunctionExists) +include(CheckSymbolExists) include(CheckIncludeFile) include(UseCompat) include(SourceFormat) @@ -248,6 +248,11 @@ endif() # dependencies # +# sigaction +list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=199309L) +check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION) +list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=199309L) + # librt (not required on OSX or QNX) find_library(LIBRT rt) if(LIBRT) diff --git a/src/config.h.in b/src/config.h.in index 9aafcaa3..50c7a757 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -82,6 +82,10 @@ */ #cmakedefine NP2SRV_HAVE_SYSTEMD +/** @brief Whether sigaction and signals are supported + */ +#cmakedefine HAVE_SIGACTION + /** @brief sshd-like pattern for path to the authorized_keys file */ #define NP2SRV_SSH_AUTHORIZED_KEYS_FORMAT "@SSH_AUTHORIZED_KEYS_FORMAT@" diff --git a/src/main.c b/src/main.c index e84fee8a..52ae3aa5 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,10 @@ #include "netconf_nmda.h" #include "netconf_subscribed_notifications.h" +#ifdef HAVE_SIGACTION +# include +#endif + #ifdef NP2SRV_HAVE_SYSTEMD # include #endif @@ -57,6 +60,8 @@ ATOMIC_T loop_continue = 1; static void *worker_thread(void *arg); +#ifdef HAVE_SIGACTION + /** * @brief Signal handler to control the process */ @@ -86,6 +91,8 @@ signal_handler(int sig) } } +#endif + /** * @brief Callback for deleting NC sessions. * @@ -1086,13 +1093,16 @@ main(int argc, char *argv[]) char *ptr; struct passwd *pwd; struct group *grp; +#ifdef HAVE_SIGACTION struct sigaction action; sigset_t block_mask; +#endif /* until daemonized, write messages to both syslog and stderr */ openlog("netopeer2-server", LOG_PID, LOG_DAEMON); np2_stderr_log = 1; +#ifdef HAVE_SIGACTION /* set the signal handler */ sigfillset(&block_mask); action.sa_handler = signal_handler; @@ -1107,6 +1117,7 @@ main(int argc, char *argv[]) /* ignore SIGPIPE */ action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &action, NULL); +#endif /* default value */ np2srv.server_dir = SERVER_DIR;