aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 00:57:53 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 00:57:53 +0200
commit867e590dfd0ac2b9e73773da96ca75113bdbeaa9 (patch)
treec99309459af9d2ad93a649fd693d20ae0505d871
parent7160b701f0e930c807179306c147fd786775ec76 (diff)
downloadmarkov-k-ram-867e590dfd0ac2b9e73773da96ca75113bdbeaa9.zip
markov-k-ram-867e590dfd0ac2b9e73773da96ca75113bdbeaa9.tar.bz2
Starts signal handling, adds forgotten free.
-rw-r--r--src/server/server_finalize.c2
-rw-r--r--src/server/server_initialize.c9
-rw-r--r--src/server/server_signal.c68
3 files changed, 71 insertions, 8 deletions
diff --git a/src/server/server_finalize.c b/src/server/server_finalize.c
index 25ea672..869091d 100644
--- a/src/server/server_finalize.c
+++ b/src/server/server_finalize.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <unistd.h>
+#include "../knowledge/knowledge.h"
#include "../parameters/parameters.h"
#include "server.h"
@@ -37,6 +38,7 @@ void JH_server_finalize
struct JH_server server [const restrict static 1]
)
{
+ JH_knowledge_finalize(&(server->k));
finalize_thread_collection(&(server->workers));
finalize_socket(&(server->socket));
}
diff --git a/src/server/server_initialize.c b/src/server/server_initialize.c
index 32a9f52..be1341e 100644
--- a/src/server/server_initialize.c
+++ b/src/server/server_initialize.c
@@ -79,6 +79,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;
@@ -86,6 +91,7 @@ int JH_server_initialize
if (JH_knowledge_initialize(&(server->k)) < 0)
{
+ /* TODO: finalize "server->workers" */
return -1;
}
@@ -98,6 +104,9 @@ int JH_server_initialize
) < 0
)
{
+ /* TODO: finalize "server->workers" */
+ JH_knowledge_finalize(&(server->k));
+
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;
}