aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-02-24 20:04:43 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-02-24 20:04:43 +0200
commit8ac571387454ab8c728402ccf7ebd1f166204fe6 (patch)
tree339017e3d477ea435608f348ce9c24bbb59fc47e
parent877ff28bc9e221a3bcb85d57a1674920211de64b (diff)
downloadping903-8ac571387454ab8c728402ccf7ebd1f166204fe6.tar.gz
ping903-8ac571387454ab8c728402ccf7ebd1f166204fe6.tar.bz2
Save mutable IP list on exit.
* src/ping903.c (ping903): Save mutable IP list on exit. * src/ping903.h (p903_saver): New proto. * src/pinger.c (p903_saver): New function.
-rw-r--r--src/ping903.c19
-rw-r--r--src/ping903.h1
-rw-r--r--src/pinger.c11
3 files changed, 30 insertions, 1 deletions
diff --git a/src/ping903.c b/src/ping903.c
index 47456a7..287b46b 100644
--- a/src/ping903.c
+++ b/src/ping903.c
@@ -638,6 +638,11 @@ p903_httpd_handler(void *cls,
return handler(conn, url, method, suffix, NULL);
}
+static void
+sigign(int sig)
+{
+}
+
void
ping903(void)
{
@@ -647,15 +652,24 @@ ping903(void)
pthread_t tid;
int fd = -1;
struct sockaddr *server_addr;
+ void *p;
+ struct sigaction act;
p903_init();
fd = open_listener(httpd_addr, &server_addr);
+ act.sa_flags = 0;
+ sigemptyset(&act.sa_mask);
+ act.sa_handler = sigign;
+
/* Block the 'fatal signals' and SIGPIPE in the handling thread */
sigemptyset(&sigs);
- for (i = 0; fatal_signals[i]; i++)
+ for (i = 0; fatal_signals[i]; i++) {
sigaddset(&sigs, fatal_signals[i]);
+ sigaction(fatal_signals[i], &act, NULL);
+ }
+
sigaddset(&sigs, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
@@ -681,5 +695,8 @@ ping903(void)
/* Wait for signal to arrive */
sigwait(&sigs, &i);
+ info("shutting down on signal %s", strsignal(i));
MHD_stop_daemon(mhd);
+ pthread_create(&tid, NULL, p903_saver, NULL);
+ pthread_join(tid, &p);
}
diff --git a/src/ping903.h b/src/ping903.h
index 0b3c7b2..62bd054 100644
--- a/src/ping903.h
+++ b/src/ping903.h
@@ -143,4 +143,5 @@ void p903_init(void);
void *p903_sender(void *p);
void *p903_receiver(void *p);
void *p903_scheduler(void *p);
+void *p903_saver(void *p);
diff --git a/src/pinger.c b/src/pinger.c
index 0103e1b..029a63e 100644
--- a/src/pinger.c
+++ b/src/pinger.c
@@ -1223,6 +1223,7 @@ save_local_ip_list(void)
if (!hostlist_updated)
return;
+ info("saving mutable IP address list");
fp = fopen(LOCAL_IP_LIST_FILE, "w");
if (!fp) {
if (errno == ENOENT) {
@@ -1266,3 +1267,13 @@ p903_scheduler(void *p)
xmit_total = recv_total = 0;
}
}
+
+void *
+p903_saver(void *p)
+{
+ pthread_rwlock_rdlock(&hostlist_rwlock);
+ save_local_ip_list();
+ pthread_rwlock_unlock(&hostlist_rwlock);
+ return NULL;
+}
+

Return to:

Send suggestions and report system problems to the System administrator.