From a5a320cf94414a209e4d31d9ebf44e3f84a03c9b Mon Sep 17 00:00:00 2001 From: emanuel Date: Fri, 6 Nov 2020 14:18:16 +0000 Subject: [PATCH] Added .service --- src/config.c | 16 ++++++++-------- src/facilities.c | 19 +++++++++++++------ systemd/it2s-itss-facilities.service | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 systemd/it2s-itss-facilities.service diff --git a/src/config.c b/src/config.c index 39fc15d..0198a20 100644 --- a/src/config.c +++ b/src/config.c @@ -19,12 +19,12 @@ static int extract_val_string(char ** output, toml_table_t *table, char* name) { toml_raw_t raw; if (0 == (raw = toml_raw_in(table, name))) { - syslog_err("[itss] [config] error extracting %s from file", name); + syslog_err("[facilities] [config] error extracting %s from file", name); return 1; } if (toml_rtos(raw, (char**) output)) { - syslog_err("[itss] [config] error extracting %s to string", name); + syslog_err("[facilities] [config] error extracting %s to string", name); return 1; } @@ -34,12 +34,12 @@ static int extract_val_string(char ** output, toml_table_t *table, char* name) { static int extract_val_bool(int * output, toml_table_t *table, char* name) { toml_raw_t raw; if (0 == (raw = toml_raw_in(table, name))) { - syslog_err("[itss] [config] error extracting %s from file", name); + syslog_err("[facilities] [config] error extracting %s from file", name); return 1; } if (toml_rtob(raw, output)) { - syslog_err("[itss] [config] error extracting %s to bool", name); + syslog_err("[facilities] [config] error extracting %s to bool", name); return 1; } @@ -49,12 +49,12 @@ static int extract_val_bool(int * output, toml_table_t *table, char* name) { static int extract_val_int(int64_t * output, toml_table_t *table, char* name) { toml_raw_t raw; if (0 == (raw = toml_raw_in(table, name))) { - syslog_err("[itss] [config] error extracting %s from file", name); + syslog_err("[facilities] [config] error extracting %s from file", name); return 1; } if (toml_rtoi(raw, output)) { - syslog_err("[itss] [config] error extracting %s to int", name); + syslog_err("[facilities] [config] error extracting %s to int", name); return 1; } @@ -88,7 +88,7 @@ int itss_config(void* facilities_s, char* config_file) { // Tables toml_table_t *general, *general_station_id; - if (0 == (general = toml_table_in(conf, "general"))) {syslog_err("[itss] [config] failed locating [general] table"); return 1;} + if (0 == (general = toml_table_in(conf, "general"))) {syslog_err("[facilities] [config] failed locating [general] table"); return 1;} if (0 == (general_station_id = toml_table_in(general, "station-id"))) {syslog_err("CONFIG: Failed locating [general] station-id table"); return 1;} // Values @@ -100,7 +100,7 @@ int itss_config(void* facilities_s, char* config_file) { } else if (strcmp("rsu", itss_type) == 0) { facilities->station_type = 15; } else { - syslog_err("[itss] [config] Unrecognized ITSS type, running as unkown"); + syslog_err("[facilities] [config] Unrecognized ITSS type, running as unkown"); facilities->station_type = 0; } free(itss_type); diff --git a/src/facilities.c b/src/facilities.c index b471c5f..7e505db 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -16,9 +16,11 @@ #include #include -#include #include #include +#include +#include +#include #define syslog_info(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__) #define syslog_emerg(msg, ...) syslog(LOG_EMERG, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__) @@ -258,7 +260,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t transmission_duration = valid_to - valid_from; } - // Respond to [itss] + // Respond to [applications] fdres->code = FacilitiesResultCode_accepted; fdres_oer = malloc(16); enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 16); @@ -433,8 +435,8 @@ void* tx(void* fc) { uint8_t code; - void* application_socket = zmq_socket(facilities->ctx, ZMQ_REQ); - zmq_connect(application_socket, APPLICATION_ADDRESS); + void* applications_socket = zmq_socket(facilities->ctx, ZMQ_REQ); + zmq_connect(applications_socket, APPLICATION_ADDRESS); void* transport_socket = zmq_socket(facilities->ctx, ZMQ_REQ); zmq_connect(transport_socket, TRANSPORT_ADDRESS); @@ -465,8 +467,8 @@ void* tx(void* fc) { break; case 5: syslog_debug("[facilities]-> sending FDI to ->[application] (%dB)", stream->packet_len[i]); - zmq_send(application_socket, stream->packet[i], stream->packet_len[i], 0); - zmq_recv(application_socket, &code, 1, 0); + zmq_send(applications_socket, stream->packet[i], stream->packet_len[i], 0); + zmq_recv(applications_socket, &code, 1, 0); break; } } @@ -481,6 +483,11 @@ int main() { facilities_t facilities; facilities.exit = false; + struct stat st = {0}; + if (stat("/tmp/itss", &st) == -1) { + mkdir("/tmp/itss", 0777); + } + time_t t; srand((unsigned) time(&t)); diff --git a/systemd/it2s-itss-facilities.service b/systemd/it2s-itss-facilities.service new file mode 100644 index 0000000..9a44584 --- /dev/null +++ b/systemd/it2s-itss-facilities.service @@ -0,0 +1,19 @@ +[Unit] +Description=it2s-itss-facilities service + +[Service] +UMask=0000 +Type=simple +ExecStart=/usr/bin/it2s-itss-facilities +KillMode=mixed +SuccessExitStatus=0 SIGKILL SIGHUP KILL +KillSignal=SIGINT +TimeoutStopSec=5 +ExecStopPost=/usr/bin/systemctl daemon-reload +ExecStopPost=/usr/bin/systemctl reset-failed +SendSIGHUP=yes +SendSIGKILL=yes + +[Install] +WantedBy=multi-user.target +