[PATCH 52/65] cleanup master channel on quit or exit

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sun, 9 Nov 2014 16:27:06 +0000

---
 ii.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/ii.c b/ii.c
index a7b9495..26f7bec 100644
--- a/ii.c
+++ b/ii.c
_AT_@ -60,10 +60,13 @@ static void      proc_channels_input(int, Channel *, char *);
 static void      proc_server_cmd(int, char *);
 static int       read_line(int, char *, size_t);
 static void      run(int, const char *);
+static void      setup(void);
+static void      sighandler(int);
 static int       tcpopen(const char *, const char *);
 static size_t    tokenize(char **, size_t, char *, int);
 static void      usage(void);
 
+static int      isrunning = 1;
 static time_t   last_response = 0;
 static Channel *channels = NULL;
 static Channel *channelmaster = NULL;
_AT_@ -473,6 +476,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf)
 				snprintf(msg, sizeof(msg),
 				         "QUIT %s\r\n", "bye");
 			ewritestr(ircfd, msg);
+			isrunning = 0;
 			return;
 			break;
 		default: /* raw IRC command */
_AT_@ -657,6 +661,24 @@ handle_server_output(int ircfd)
 }
 
 static void
+sighandler(int sig)
+{
+	if(sig == SIGTERM || sig == SIGINT)
+		isrunning = 0;
+}
+
+static void
+setup(void)
+{
+	struct sigaction sa;
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sighandler;
+	sigaction(SIGTERM, &sa, NULL);
+	sigaction(SIGINT, &sa, NULL);
+}
+
+static void
 run(int ircfd, const char *host)
 {
 	Channel *c;
_AT_@ -666,7 +688,7 @@ run(int ircfd, const char *host)
 	int r, maxfd;
 
 	snprintf(ping_msg, sizeof(ping_msg), "PING %s\r\n", host);
-	for(;;) {
+	while(isrunning) {
 		maxfd = ircfd;
 		FD_ZERO(&rdset);
 		FD_SET(ircfd, &rdset);
_AT_@ -751,7 +773,10 @@ main(int argc, char *argv[])
 	if(key)
 		loginkey(ircfd, key);
 	loginuser(ircfd, host, fullname && *fullname ? fullname : nick);
+	setup();
 	run(ircfd, host);
+	if(channelmaster)
+		channel_leave(channelmaster);
 
 	return EXIT_SUCCESS;
 }
-- 
2.4.10
--Multipart=_Mon__9_May_2016_17_21_10_+0200_I.6cpFVydhq75aaE
Content-Type: text/x-diff;
 name="0053-close-all-channels-on-exit-removes-in-files.patch"
Content-Disposition: attachment;
 filename="0053-close-all-channels-on-exit-removes-in-files.patch"
Content-Transfer-Encoding: 7bit
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon May 09 2016 - 17:24:22 CEST