aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-01-07 11:06:51 +0100
committernsensfel <SpamShield0@noot-noot.org>2020-01-07 11:06:51 +0100
commit99fc3898606bf9bc2a732facffc1a6fe6bfcf3a2 (patch)
tree7ca296de2a78a500b838d9a5d5a5fa3c0523fa18
parent11138ae4e8e3ed2f01156189923f7904c8f21591 (diff)
downloadrelabsd-99fc3898606bf9bc2a732facffc1a6fe6bfcf3a2.zip
relabsd-99fc3898606bf9bc2a732facffc1a6fe6bfcf3a2.tar.bz2
...
-rw-r--r--include/relabsd/config/parameters.h7
-rw-r--r--include/relabsd/device/axis.h5
-rw-r--r--include/relabsd/server.h6
-rw-r--r--src/config/parameters/parameters.c10
-rw-r--r--src/config/parameters/parameters_accessors.c9
-rw-r--r--src/device/axis/axis_option.c8
-rw-r--r--src/device/physical/physical_device.c7
-rw-r--r--src/server/communication_node.c33
-rw-r--r--src/server/communication_thread.c40
-rw-r--r--src/server/handle_client.c7
-rw-r--r--src/server/interruption.c4
-rw-r--r--src/server/server.c3
12 files changed, 126 insertions, 13 deletions
diff --git a/include/relabsd/config/parameters.h b/include/relabsd/config/parameters.h
index 215f61c..3290c56 100644
--- a/include/relabsd/config/parameters.h
+++ b/include/relabsd/config/parameters.h
@@ -41,6 +41,13 @@ int relabsd_parameters_are_compatible_with
const struct relabsd_parameters parameters [const restrict static 1]
);
+
+int relabsd_parameters_parse_config_file
+(
+ const char filename [const restrict static 1],
+ struct relabsd_parameters parameters [const restrict static 1]
+);
+
/**** Accessors ***************************************************************/
void relabsd_parameters_initialize_options
(
diff --git a/include/relabsd/device/axis.h b/include/relabsd/device/axis.h
index 1638b80..833a31f 100644
--- a/include/relabsd/device/axis.h
+++ b/include/relabsd/device/axis.h
@@ -88,3 +88,8 @@ int relabsd_axis_filter_new_value
struct relabsd_axis axis [const restrict static 1],
int value [const restrict static 1]
);
+
+void relabsd_axis_initialize
+(
+ struct relabsd_axis axis [const restrict static 1]
+);
diff --git a/include/relabsd/server.h b/include/relabsd/server.h
index d5d36a6..c5ef9ca 100644
--- a/include/relabsd/server.h
+++ b/include/relabsd/server.h
@@ -43,3 +43,9 @@ int relabsd_server_handle_client
const int socket,
struct relabsd_server server [const static 1]
);
+
+void relabsd_server_destroy_communication_node
+(
+ const char socket_name [const restrict static 1],
+ const int socket
+);
diff --git a/src/config/parameters/parameters.c b/src/config/parameters/parameters.c
index e3328ca..bff7642 100644
--- a/src/config/parameters/parameters.c
+++ b/src/config/parameters/parameters.c
@@ -103,6 +103,8 @@ int relabsd_parameters_parse_execution_mode
return -1;
}
+ relabsd_parameters_initialize_options(parameters);
+
if
(
RELABSD_STRING_EQUALS("-?", argv[1])
@@ -169,8 +171,6 @@ int relabsd_parameters_parse_options
RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Parsing options...");
- relabsd_parameters_initialize_options(parameters);
-
/*
* i = (parameters->read_argc + 1) because reading 2 params is actually
* reaching the [2] element of the array, since the [0] element is the
@@ -283,7 +283,11 @@ int relabsd_parameters_parse_options
}
++i;
- parameters->configuration_file = argv[i];
+
+ if (relabsd_parameters_parse_config_file(argv[i], parameters) < 0)
+ {
+ return -1;
+ }
}
else
{
diff --git a/src/config/parameters/parameters_accessors.c b/src/config/parameters/parameters_accessors.c
index 71c2482..f47ff63 100644
--- a/src/config/parameters/parameters_accessors.c
+++ b/src/config/parameters/parameters_accessors.c
@@ -5,6 +5,8 @@
/**** RELABSD *****************************************************************/
#include <relabsd/config/parameters.h>
+#include <relabsd/device/axis.h>
+
/******************************************************************************/
/**** LOCAL FUNCTIONS *********************************************************/
/******************************************************************************/
@@ -17,11 +19,18 @@ void relabsd_parameters_initialize_options
struct relabsd_parameters parameters [const restrict static 1]
)
{
+ int i;
+
parameters->run_as_daemon = 0;
parameters->communication_node_name = (const char *) NULL;
parameters->device_name = (const char *) NULL;
parameters->physical_device_file_name = (const char *) NULL;
parameters->configuration_file = (const char *) NULL;
+
+ for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i)
+ {
+ relabsd_axis_initialize(parameters->axes + i);
+ }
}
int relabsd_parameters_get_run_as_daemon
diff --git a/src/device/axis/axis_option.c b/src/device/axis/axis_option.c
index fd1cb9c..1d68b78 100644
--- a/src/device/axis/axis_option.c
+++ b/src/device/axis/axis_option.c
@@ -4,6 +4,8 @@
/**** RELABSD *****************************************************************/
#include <relabsd/debug.h>
+#include <relabsd/util/string.h>
+
#include <relabsd/device/axis.h>
/******************************************************************************/
@@ -25,7 +27,7 @@ int relabsd_axis_enable_option_from_name
)
{
- if (strcmp(option_name, "direct") == 0)
+ if (RELABSD_IS_PREFIX("direct", option_name))
{
axis->flags[RELABSD_DIRECT] = 1;
@@ -38,11 +40,11 @@ int relabsd_axis_enable_option_from_name
);
}
}
- else if (strcmp(option_name, "real_fuzz") == 0)
+ else if (RELABSD_IS_PREFIX("real_fuzz", option_name))
{
axis->flags[RELABSD_REAL_FUZZ] = 1;
}
- else if (strcmp(option_name, "framed") == 0)
+ else if (RELABSD_IS_PREFIX("framed", option_name))
{
axis->flags[RELABSD_FRAMED] = 1;
diff --git a/src/device/physical/physical_device.c b/src/device/physical/physical_device.c
index ca6f595..1bf3326 100644
--- a/src/device/physical/physical_device.c
+++ b/src/device/physical/physical_device.c
@@ -60,7 +60,12 @@ int relabsd_physical_device_open
{
int err;
- RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Opening physical device...");
+ RELABSD_DEBUG
+ (
+ RELABSD_DEBUG_PROGRAM_FLOW,
+ "Opening physical device %s...",
+ filename
+ );
errno = 0;
device->file = open(filename, O_RDONLY);
diff --git a/src/server/communication_node.c b/src/server/communication_node.c
index c621f06..46b5f08 100644
--- a/src/server/communication_node.c
+++ b/src/server/communication_node.c
@@ -164,3 +164,36 @@ int relabsd_server_create_communication_node
return 0;
}
+
+void relabsd_server_destroy_communication_node
+(
+ const char socket_name [const restrict static 1],
+ const int socket
+)
+{
+ errno = 0;
+
+ if (close(socket) == -1)
+ {
+ RELABSD_WARNING
+ (
+ "Could not properly close the communication socket: %s.",
+ strerror(errno)
+ );
+ }
+
+ errno = 0;
+
+ if (remove(socket_name) == -1)
+ {
+ RELABSD_ERROR
+ (
+ "Could not remove communication node %s. Please delete it manually."
+ " Error: %s.",
+ socket_name,
+ strerror(errno)
+ );
+ }
+
+ RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Destroyed communication node.");
+}
diff --git a/src/server/communication_thread.c b/src/server/communication_thread.c
index cc91065..fd8f5cf 100644
--- a/src/server/communication_thread.c
+++ b/src/server/communication_thread.c
@@ -1,4 +1,8 @@
/**** POSIX *******************************************************************/
+#include <sys/select.h>
+#include <sys/socket.h>
+
+#include <errno.h>
#include <pthread.h>
#include <string.h>
@@ -6,6 +10,8 @@
#include <relabsd/debug.h>
#include <relabsd/server.h>
+#include <relabsd/config/parameters.h>
+
/******************************************************************************/
/**** LOCAL FUNCTIONS *********************************************************/
/******************************************************************************/
@@ -48,6 +54,8 @@ static void main_loop (struct relabsd_server server [const static 1])
FD_SET(communication_socket, &ready_to_read);
FD_SET(interrupt_fd, &ready_to_read);
+ errno = 0;
+
ready_fds =
select
(
@@ -58,10 +66,30 @@ static void main_loop (struct relabsd_server server [const static 1])
(struct timeval *) NULL
);
+ if (ready_fds == -1)
+ {
+ RELABSD_ERROR
+ (
+ "Unable to select on the server's socket: %s.",
+ strerror(errno)
+ );
+
+ relabsd_server_interrupt();
+ }
+
/* TODO: select error handling. */
if (!relabsd_server_keep_running())
{
+ relabsd_server_destroy_communication_node
+ (
+ relabsd_parameters_get_communication_node_name
+ (
+ &(server->parameters)
+ ),
+ communication_socket
+ );
+
return;
}
@@ -83,7 +111,17 @@ static void main_loop (struct relabsd_server server [const static 1])
strerror(errno)
);
- return -1;
+ relabsd_server_interrupt();
+ relabsd_server_destroy_communication_node
+ (
+ relabsd_parameters_get_communication_node_name
+ (
+ &(server->parameters)
+ ),
+ communication_socket
+ );
+
+ return;
}
(void) relabsd_server_handle_client(current_client_socket, server);
diff --git a/src/server/handle_client.c b/src/server/handle_client.c
index 696725b..a5eb7f7 100644
--- a/src/server/handle_client.c
+++ b/src/server/handle_client.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
/**** RELABSD *****************************************************************/
#include <relabsd/debug.h>
@@ -19,9 +20,9 @@
/******************************************************************************/
static void handle_input
(
- const ssize_t input_size,
- const char input [const static 1],
- struct relabsd_server server [const static 1]
+ const ssize_t input_size __attribute__((unused)),
+ const char input [const static 1] __attribute__((unused)),
+ struct relabsd_server server [const static 1] __attribute__((unused))
)
{
}
diff --git a/src/server/interruption.c b/src/server/interruption.c
index 32cda53..7dabd3d 100644
--- a/src/server/interruption.c
+++ b/src/server/interruption.c
@@ -19,7 +19,7 @@ static void interrupt (int unused_mandatory_parameter __attribute__((unused)))
errno = 0;
- if (write(RELABSD_INTERRUPTION_PIPES[0], (void *) "!", (size_t) 1) == -1)
+ if (write(RELABSD_INTERRUPTION_PIPES[1], (void *) "!", (size_t) 1) == -1)
{
RELABSD_ERROR
(
@@ -82,5 +82,5 @@ void relabsd_server_finalize_signal_handlers (void)
int relabsd_server_get_interruption_file_descriptor (void)
{
- return RELABSD_INTERRUPTION_PIPES[1];
+ return RELABSD_INTERRUPTION_PIPES[0];
}
diff --git a/src/server/server.c b/src/server/server.c
index 1b17d12..223e57a 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -21,6 +21,8 @@ static int initialize
{
int err;
+ relabsd_server_initialize_signal_handlers();
+
if
(
relabsd_physical_device_open
@@ -97,6 +99,7 @@ static void finalize (struct relabsd_server server [const static 1])
relabsd_physical_device_close(&(server->physical_device));
(void) pthread_mutex_destroy(&(server->mutex));
+ relabsd_server_finalize_signal_handlers();
}
/******************************************************************************/