From a97ddc8cb955eb518f1864ccc2ee86b08010a347 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 29 Aug 2011 10:12:06 +0200 Subject: test/run_ntp_server: quit on SIGINT or SIGTERM Clean up the process before exiting. --- test/run_ntp_server.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test/run_ntp_server.c') diff --git a/test/run_ntp_server.c b/test/run_ntp_server.c index bdee1fdcb..7268fa94c 100644 --- a/test/run_ntp_server.c +++ b/test/run_ntp_server.c @@ -19,6 +19,7 @@ #include "config.h" #include "ntp_server.h" +#include "signals.h" #include @@ -38,6 +39,14 @@ #include #endif +static bool quit = false; + +void +on_quit(void) +{ + quit = true; +} + static int bind_host(int sd, char *hostname, unsigned long ulAddr, unsigned short *port) { @@ -113,6 +122,8 @@ open_udp_socket(char *hostname, unsigned short *port) int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) { + signals_init(); + struct ntp_server ntp; ntp_server_init(&ntp); @@ -123,7 +134,7 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) return EXIT_FAILURE; } - while (true) { + while (!quit) { struct timeval tv = { .tv_sec = 1, .tv_usec = 0, -- cgit v1.2.3