From: Mark Wooding Date: Mon, 17 Apr 2017 23:39:24 +0000 (+0100) Subject: uslip/uslip.c: Shut the server down on `SIGTERM'. X-Git-Tag: 1.0.0pre19~21 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/aec8bcc80d152089426e63cacf455cd456787036?hp=1b7185f555d06faa9831c3b2345ddd9e88f03edf uslip/uslip.c: Shut the server down on `SIGTERM'. 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. --- 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++;