diff --git a/include/villas/utils.h b/include/villas/utils.h index 39c7e7031..838cb73df 100644 --- a/include/villas/utils.h +++ b/include/villas/utils.h @@ -244,4 +244,7 @@ void rdtsc_sleep(uint64_t nanosecs, uint64_t start); /** Register a exit callback for program termination (SIGINT / SIGKILL). */ void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx)); +/** Send signal \p sig to main thread. */ +void killme(int sig); + pid_t spawn(const char* name, char *const argv[]); diff --git a/lib/nodes/file.c b/lib/nodes/file.c index eaa73e791..617656f9e 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -335,8 +335,8 @@ retry: values = sample_io_villas_fscan(f->read.handle->file, s, &flags); /* Get goto retry; case FILE_EOF_EXIT: - info("Reached end-of-file"); - exit(EXIT_SUCCESS); + info("Reached end-of-file of node %s", node_name(n)); + killme(SIGTERM); } } diff --git a/lib/utils.c b/lib/utils.c index 08e451f51..16789dce0 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -34,6 +34,8 @@ #include "config.h" #include "utils.h" +pthread_t main_thread; + void print_copyright() { printf("VILLASnode %s (built on %s %s)\n", @@ -305,6 +307,8 @@ void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx)) .sa_flags = SA_SIGINFO, .sa_sigaction = cb }; + + main_thread = pthread_self(); sigemptyset(&sa_quit.sa_mask); sigaction(SIGINT, &sa_quit, NULL); @@ -319,6 +323,11 @@ void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx)) sigaction(SIGCHLD, &sa_chld, NULL); } +void killme(int sig) +{ + pthread_kill(main_thread, sig); +} + pid_t spawn(const char* name, char *const argv[]) { pid_t pid; diff --git a/src/pipe.c b/src/pipe.c index b199e09d6..7ffc34619 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -54,8 +54,6 @@ struct dir { struct node *node; -pthread_t ptid; /**< Parent thread id */ - static void quit(int signal, siginfo_t *sinfo, void *ctx) { if (signal == SIGALRM) @@ -140,14 +138,14 @@ retry: reason = sample_io_villas_fscan(stdin, s, NULL); } leave2: info("Reached send limit. Terminating..."); - pthread_kill(ptid, SIGINT); + killme(SIGTERM); return NULL; /* We reached EOF on stdin here. Lets kill the process */ leave: if (recvv.limit < 0) { info("Reached end-of-file. Terminating..."); - pthread_kill(ptid, SIGINT); + killme(SIGTERM); } return NULL; @@ -193,7 +191,7 @@ static void * recv_loop(void *ctx) } leave: info("Reached receive limit. Terminating..."); - pthread_kill(ptid, SIGINT); + killme(SIGTERM); return NULL; return NULL; @@ -208,8 +206,6 @@ int main(int argc, char *argv[]) .enabled = true, .limit = -1 }; - - ptid = pthread_self(); char c, *endptr; while ((c = getopt(argc, argv, "hxrsd:l:L:t:")) != -1) {