aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 01:02:05 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-18 01:02:05 +0200
commitbf8606c7fc9720afe04eb403d967a352fa92bd0f (patch)
treeb5c9696d5a8fd321d6ca25213da383a3027e01b8
parent9ef9f01ce425ff82b6e5f87643dfe624dc56a4a2 (diff)
downloadstorage-bf8606c7fc9720afe04eb403d967a352fa92bd0f.zip
storage-bf8606c7fc9720afe04eb403d967a352fa92bd0f.tar.bz2
Starts signal handling.
-rw-r--r--src/server/server_initialize.c7
-rw-r--r--src/server/server_signal.c68
-rw-r--r--src/server/server_worker_data_merger.c22
3 files changed, 84 insertions, 13 deletions
diff --git a/src/server/server_initialize.c b/src/server/server_initialize.c
index 93a3b02..895a833 100644
--- a/src/server/server_initialize.c
+++ b/src/server/server_initialize.c
@@ -159,6 +159,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;
@@ -173,6 +178,8 @@ int JH_server_initialize
) < 0
)
{
+ /* TODO: free "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;
}
diff --git a/src/server/server_worker_data_merger.c b/src/server/server_worker_data_merger.c
index 79638db..a5f5bdf 100644
--- a/src/server/server_worker_data_merger.c
+++ b/src/server/server_worker_data_merger.c
@@ -143,8 +143,13 @@ static void merge_thread_data
void * JH_server_worker_data_merger_main (void * input)
{
+ int err;
JH_index i;
struct JH_server_worker worker;
+ struct timespec abstime;
+
+ memset((void *) &abstime, 0, sizeof(struct timespec));
+ abstime.tv_sec = 5;
initialize(&worker, input);
@@ -152,11 +157,18 @@ void * JH_server_worker_data_merger_main (void * input)
while (JH_server_is_running())
{
- pthread_cond_wait
- (
- &(worker.params.thread_collection->merger_condition),
- &(worker.params.thread_collection->merger_mutex)
- );
+ err =
+ pthread_cond_timedwait
+ (
+ &(worker.params.thread_collection->merger_condition),
+ &(worker.params.thread_collection->merger_mutex),
+ &abstime
+ );
+
+ if (err == ETIMEDOUT)
+ {
+ continue;
+ }
pthread_mutex_lock(&(worker.params.thread_collection->mutex));