mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
move signal initialisation to utils
This commit is contained in:
parent
c56caf3b73
commit
d9bd8cf64f
4 changed files with 18 additions and 36 deletions
16
lib/utils.c
16
lib/utils.c
|
@ -11,7 +11,6 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
@ -337,4 +336,19 @@ void rdtsc_sleep(uint64_t nanosecs, uint64_t start)
|
|||
do {
|
||||
__asm__("nop");
|
||||
} while (rdtsc() - start < cycles);
|
||||
}
|
||||
|
||||
/* Setup exit handler */
|
||||
void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx))
|
||||
{
|
||||
info("Initialize signals");
|
||||
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = cb
|
||||
};
|
||||
|
||||
sigemptyset(&sa_quit.sa_mask);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
}
|
16
src/node.c
16
src/node.c
|
@ -5,7 +5,6 @@
|
|||
*********************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <villas/utils.h>
|
||||
|
@ -27,7 +26,7 @@
|
|||
|
||||
struct cfg cfg;
|
||||
|
||||
static void quit()
|
||||
static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
||||
{
|
||||
info("Stopping paths");
|
||||
list_foreach(struct path *p, &cfg.paths) { INDENT
|
||||
|
@ -47,19 +46,6 @@ static void quit()
|
|||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* Setup exit handler */
|
||||
static void signals_init()
|
||||
{ INDENT
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = quit
|
||||
};
|
||||
|
||||
sigemptyset(&sa_quit.sa_mask);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
}
|
||||
|
||||
static void usage()
|
||||
{
|
||||
printf("Usage: villas-node [CONFIG]\n");
|
||||
|
|
10
src/pipe.c
10
src/pipe.c
|
@ -201,15 +201,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
log_init(&cfg.log, cfg.log.level, LOG_ALL);
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = quit
|
||||
};
|
||||
|
||||
sigemptyset(&sa_quit.sa_mask);
|
||||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
signals_init(quit);
|
||||
|
||||
/* Initialize log, configuration.. */
|
||||
cfg_parse(&cfg, argv[1]);
|
||||
|
|
12
src/test.c
12
src/test.c
|
@ -46,7 +46,7 @@ static double res = 1e-5; /**< Histogram resolution. */
|
|||
/* Prototypes */
|
||||
void test_rtt();
|
||||
|
||||
void quit()
|
||||
void quit(int signal, siginfo_t *sinfo, void *ctx)
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
|
@ -68,16 +68,6 @@ int main(int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = quit
|
||||
};
|
||||
|
||||
sigemptyset(&sa_quit.sa_mask);
|
||||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
|
||||
log_init(&cfg.log, V, LOG_ALL);
|
||||
cfg_parse(&cfg, argv[1]);
|
||||
signals_init(quit);
|
||||
|
|
Loading…
Add table
Reference in a new issue