mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
adding function killme() to gracefully shutdown
This commit is contained in:
parent
b123e91189
commit
a057c0c513
4 changed files with 17 additions and 9 deletions
|
@ -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[]);
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
10
src/pipe.c
10
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue