chiark / gitweb /
uslip/uslip.c: Shut the server down on `SIGTERM'.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 17 Apr 2017 23:39:24 +0000 (00:39 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 17:19:08 +0000 (18:19 +0100)
The tripe(8) server sends `SIGTERM' to its SLIP tunnel helpers when it
shuts down interfaces.  This causes us to leave behind dead Unix-domain
sockets, which is bad.  Catch `SIGTERM' so that we can clean up
properly -- and so that we can let clients pick up any remaining packets
we might still have queued.

uslip/uslip.c

index 853df5b2233ea853bc3a851d3373462432436240..0ed9e70e59b8da707b681dcc203d810758ce0ef7 100644 (file)
@@ -55,6 +55,7 @@
 #include <mLib/quis.h>
 #include <mLib/report.h>
 #include <mLib/sel.h>
+#include <mLib/sig.h>
 #include <mLib/sub.h>
 #include <mLib/tv.h>
 
@@ -570,11 +571,15 @@ static void do_slip_in(int fd, unsigned mode, void *hunoz)
   }
 }
 
+static void slip_term(int n, void *fdp)
+  { close_slip(*(int *)fdp); }
+
 static void slipif(void)
 {
   int fd;
   dstr d = DSTR_INIT;
   struct sockaddr_un sun;
+  sig term;
   size_t sz;
 
   /* --- Make the socket --- */
@@ -599,6 +604,10 @@ static void slipif(void)
   dribble_out = make_dribbler(STDOUT_FILENO, done_slip_dribble, 0);
   sel_addfile(&slip_in);
 
+  sig_init(&sel);
+  sig_add(&term, SIGTERM, slip_term, &fd);
+  sig_add(&term, SIGINT, slip_term, &fd);
+
   initqueue(&q_in);
   reasons++;