aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 01:01:40 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 01:01:40 +0200
commiteef1934af8e38f91fb96ca922f6f52fa7d8d2a9a (patch)
tree17b0414c1ede95c679c7761bbe8a2538f175b2b8
parent43cb5ee34be31874442cbcb7e96b2c0b609a97c1 (diff)
downloadlimiter-eef1934af8e38f91fb96ca922f6f52fa7d8d2a9a.zip
limiter-eef1934af8e38f91fb96ca922f6f52fa7d8d2a9a.tar.bz2
Starts signal handling.
-rw-r--r--src/server/server_initialize.c6
-rw-r--r--src/server/server_signal.c68
2 files changed, 66 insertions, 8 deletions
diff --git a/src/server/server_initialize.c b/src/server/server_initialize.c
index a125046..1c302ac 100644
--- a/src/server/server_initialize.c
+++ b/src/server/server_initialize.c
@@ -76,6 +76,11 @@ int JH_server_initialize
const struct JH_parameters params [const restrict static 1]
)
{
+ if (JH_server_set_signal_handlers() < 0)
+ {
+ return -1;
+ }
+
if (initialize_worker_collection(&(server->workers)) < 0)
{
return -1;
@@ -90,6 +95,7 @@ int JH_server_initialize
) < 0
)
{
+ /* TODO: free worker_collection */
return -2;
}
diff --git a/src/server/server_signal.c b/src/server/server_signal.c
index 9361382..06a15bf 100644
--- a/src/server/server_signal.c
+++ b/src/server/server_signal.c
@@ -1,7 +1,10 @@
#include <signal.h>
+#include <errno.h>
#include <string.h>
#include <stdio.h>
+#include "../error/error.h"
+
#include "server.h"
static volatile char JH_SERVER_IS_RUNNING = (char) 1;
@@ -26,16 +29,65 @@ int JH_server_is_running (void)
int JH_server_set_signal_handlers (void)
{
- /*
struct sigaction act;
+ const int old_errno = errno;
+
+ memset((void *) &act, 0, sizeof(struct sigaction));
+
+ act.sa_handler = request_termination;
+
+ errno = 0;
+
+ if (sigaction(SIGHUP, &act, (struct sigaction * restrict) NULL) == -1)
+ {
+ JH_FATAL
+ (
+ stderr,
+ "Could not set sigaction for SIGHUP (errno: %d): %s",
+ errno,
+ strerror(errno)
+ );
+
+ errno = old_errno;
+
+ return -1;
+ }
+
+ errno = 0;
- act.sa_handler = request_termination;
- act.sa_mask =
- act.sa_flags =
- act.sa_restorer =
- */
+ if (sigaction(SIGINT, &act, (struct sigaction * restrict) NULL) == -1)
+ {
+ JH_FATAL
+ (
+ stderr,
+ "Could not set sigaction for SIGINT (errno: %d): %s",
+ errno,
+ strerror(errno)
+ );
+
+ errno = old_errno;
+
+ return -1;
+ }
+
+ act.sa_handler = SIG_IGN;
+
+ if (sigaction(SIGPIPE, &act, (struct sigaction * restrict) NULL) == -1)
+ {
+ JH_FATAL
+ (
+ stderr,
+ "Could not set sigaction for SIGPIPE (errno: %d): %s",
+ errno,
+ strerror(errno)
+ );
+
+ errno = old_errno;
+
+ return -1;
+ }
- /* TODO */
+ errno = old_errno;
- return -1;
+ return 0;
}