From aec8bcc80d152089426e63cacf455cd456787036 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Tue, 18 Apr 2017 00:39:24 +0100 Subject: [PATCH 1/1] uslip/uslip.c: Shut the server down on `SIGTERM'. Organization: Straylight/Edgeware From: Mark Wooding 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/uslip/uslip.c b/uslip/uslip.c index 853df5b2..0ed9e70e 100644 --- a/uslip/uslip.c +++ b/uslip/uslip.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -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++; -- [mdw]