Skip to content

Commit

Permalink
server UPDATE optional signal support
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed May 10, 2024
1 parent a2009a9 commit c291c9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
Expand Down
13 changes: 12 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -48,6 +47,10 @@
#include "netconf_nmda.h"
#include "netconf_subscribed_notifications.h"

#ifdef HAVE_SIGACTION
# include <signal.h>
#endif

#ifdef NP2SRV_HAVE_SYSTEMD
# include <systemd/sd-daemon.h>
#endif
Expand All @@ -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
*/
Expand Down Expand Up @@ -86,6 +91,8 @@ signal_handler(int sig)
}
}

#endif

/**
* @brief Callback for deleting NC sessions.
*
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit c291c9e

Please sign in to comment.