aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 01:00:56 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 01:00:56 +0200
commitd582b266356b79e6879d7ae30b8defe3a565ee03 (patch)
tree0c2ba5c65b94677a075a5609dbffe339ac6496e3
parent52d894c670cf9b9ae5c5276acfa7938fb4fbacd3 (diff)
downloadlowercase-d582b266356b79e6879d7ae30b8defe3a565ee03.zip
lowercase-d582b266356b79e6879d7ae30b8defe3a565ee03.tar.bz2
Starts signal handling.
-rw-r--r--src/server/server_initialize.c7
-rw-r--r--src/server/server_signal.c68
2 files changed, 67 insertions, 8 deletions
diff --git a/src/server/server_initialize.c b/src/server/server_initialize.c
index 4b94fc6..75b3c4e 100644
--- a/src/server/server_initialize.c
+++ b/src/server/server_initialize.c
@@ -83,6 +83,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), params) < 0)
{
return -1;
@@ -97,6 +102,8 @@ int JH_server_initialize
) < 0
)
{
+ /* TODO: finalize "server->workers" */
+
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;
}