feat: handle sigint properly
This commit is contained in:
parent
bdf3a54ba0
commit
99174939f5
@ -22,6 +22,7 @@
|
||||
#include "pipeline.h"
|
||||
#include "threadpool.h"
|
||||
#include "util.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
@ -86,6 +87,12 @@ void* listen_for_config_changes_thread(void* data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void signal_handler(int signal) {
|
||||
log_info("signal retrieved");
|
||||
if(signal == SIGINT)
|
||||
pipeline_cancel();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
cli_options args = parse(argc, argv);
|
||||
log_settings settings;
|
||||
@ -94,6 +101,8 @@ int main(int argc, char** argv) {
|
||||
settings.out_file = args.log_file.has_value ? fopen(args.log_file.value, "w+") : stdout;
|
||||
log_init(settings);
|
||||
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
if(args.help) {
|
||||
print_help(stdout, argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -26,6 +26,7 @@
|
||||
pthread_list_node* root = NULL;
|
||||
|
||||
optional_pipeline_conf pipeline_create(const char* config_line) {
|
||||
log_trace("pipeline create");
|
||||
optional_pipeline_conf result;
|
||||
result.has_value = false;
|
||||
const char* pattern = "[^[:blank:]]+|\"[^\"]*\"";
|
||||
@ -72,6 +73,7 @@ optional_pipeline_conf pipeline_create(const char* config_line) {
|
||||
}
|
||||
|
||||
void pipeline_destroy(pipeline_conf* conf) {
|
||||
log_trace("pipeline destroy");
|
||||
free(conf->name);
|
||||
free(conf->url);
|
||||
free(conf->trigger);
|
||||
@ -80,6 +82,7 @@ void pipeline_destroy(pipeline_conf* conf) {
|
||||
}
|
||||
|
||||
void pipeline_register(pthread_t thread) {
|
||||
log_trace("pipeline register thread");
|
||||
if(root == NULL) {
|
||||
root = create_thread_node(thread);
|
||||
return;
|
||||
@ -88,11 +91,13 @@ void pipeline_register(pthread_t thread) {
|
||||
}
|
||||
|
||||
void pipeline_loop() {
|
||||
log_trace("pipeline loop");
|
||||
clear_thread_list(root);
|
||||
root = NULL;
|
||||
}
|
||||
|
||||
void pipeline_cancel() {
|
||||
log_trace("cancelling pipeline");
|
||||
pthread_list_node* cursor = root;
|
||||
while(cursor != NULL) {
|
||||
pthread_cancel(cursor->thread);
|
||||
@ -101,6 +106,7 @@ void pipeline_cancel() {
|
||||
}
|
||||
|
||||
void pipeline_event_destroy(pipeline_event* ev) {
|
||||
log_trace("pipeline event destroy");
|
||||
free(ev->name);
|
||||
free(ev->trigger);
|
||||
free(ev->url);
|
||||
|
Loading…
x
Reference in New Issue
Block a user