summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-04 19:02:54 -0500
committerJune McEnroe <june@causal.agency>2020-02-04 19:02:54 -0500
commit5e9863fa82f674ad8eb05148eade5c859a32c7ba (patch)
treea17d52cafc58a2365a3b9dbf58647f4d61eae26f
parentSwitch windows with M-0 through M-9 (diff)
downloadcatgirl-5e9863fa82f674ad8eb05148eade5c859a32c7ba.tar.gz
catgirl-5e9863fa82f674ad8eb05148eade5c859a32c7ba.zip
Handle signals in poll loop
Diffstat (limited to '')
-rw-r--r--chat.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/chat.c b/chat.c
index 3402621..3aa4ad2 100644
--- a/chat.c
+++ b/chat.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <locale.h>
 #include <poll.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,7 +35,7 @@ char *idNames[IDCap] = {
 
 enum Color idColors[IDCap] = {
 	[None] = Black,
-	[Debug] = Red,
+	[Debug] = Green,
 	[Network] = Gray,
 };
 
@@ -42,6 +43,11 @@ size_t idNext = Network + 1;
 
 struct Self self;
 
+static volatile sig_atomic_t signals[NSIG];
+static void signalHandler(int signal) {
+	signals[signal] = 1;
+}
+
 int main(int argc, char *argv[]) {
 	setlocale(LC_CTYPE, "");
 
@@ -100,6 +106,11 @@ int main(int argc, char *argv[]) {
 	ircFormat("NICK :%s\r\n", nick);
 	ircFormat("USER %s 0 * :%s\r\n", user, real);
 
+	signal(SIGHUP, signalHandler);
+	signal(SIGINT, signalHandler);
+	signal(SIGTERM, signalHandler);
+	sig_t cursesWinch = signal(SIGWINCH, signalHandler);
+
 	struct pollfd fds[2] = {
 		{ .events = POLLIN, .fd = STDIN_FILENO },
 		{ .events = POLLIN, .fd = irc },
@@ -108,8 +119,20 @@ int main(int argc, char *argv[]) {
 		int nfds = poll(fds, 2, -1);
 		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
 
+		if (signals[SIGHUP] || signals[SIGINT] || signals[SIGTERM]) {
+			break;
+		}
+		if (signals[SIGWINCH]) {
+			signals[SIGWINCH] = 0;
+			cursesWinch(SIGWINCH);
+			fds[0].revents = POLLIN;
+		}
+
 		if (fds[0].revents) uiRead();
 		if (fds[1].revents) ircRecv();
 		uiDraw();
 	}
+
+	ircFormat("QUIT\r\n");
+	uiHide();
 }
bdee1f228f6fed3e4a2c324376caef1&follow=1'>Add Conversations With FriendsJune McEnroe The better of the two, but largely the same. I feel like these books are a bit too autobiographical, but I don't know if I'm allowed to accuse an author of that. My real problem is that I read these books as largely uncritical of their characters. They behave in nonsense ways, are mostly uncritical of their own behaviour, and don't really have arcs of growth or change. I suppose this book had a bit of one, but only in the last two chapters. 2022-07-30Add Normal PeopleJune McEnroe Unbearably straight. Eyerolls and sighs per page off the charts. Shout out to Joanna, I guess. I kinda like the lack of quotation marks though to be honest. After half of the Ruth Ozeki novel and now this, I need to get back to some genre fiction. 2022-07-26Rewrite glitch from new pngoJune McEnroe 2022-07-26Update Care with time-to-ID and piercingsJune McEnroe 2022-07-26Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe There is not that much distinct stuff here anymore. 2022-07-03Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe