diff --git a/src/main.c b/src/main.c index b714080..93c27c1 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ #include "pipeline.h" #include "threadpool.h" #include "util.h" +#include #include #include #include @@ -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); diff --git a/src/pipeline.c b/src/pipeline.c index eb5284f..dbd41bb 100644 --- a/src/pipeline.c +++ b/src/pipeline.c @@ -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);