summary refs log tree commit diff
path: root/chat.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-08 17:22:51 -0500
committerJune McEnroe <june@causal.agency>2020-02-08 17:22:51 -0500
commit8128edc7eb1e7a86e82d5936ec1100e1f9912f54 (patch)
tree71092d53dfeba8ed6e4330705b4f0b9abee68180 /chat.c
parentCheck signals after file descriptors (diff)
downloadcatgirl-8128edc7eb1e7a86e82d5936ec1100e1f9912f54.tar.gz
catgirl-8128edc7eb1e7a86e82d5936ec1100e1f9912f54.zip
Handle SIGCHLD
Diffstat (limited to 'chat.c')
-rw-r--r--chat.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/chat.c b/chat.c
index b3e6825..372cbbd 100644
--- a/chat.c
+++ b/chat.c
@@ -22,6 +22,8 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
 #include <sysexits.h>
 #include <unistd.h>
 
@@ -141,6 +143,7 @@ int main(int argc, char *argv[]) {
 	signal(SIGHUP, signalHandler);
 	signal(SIGINT, signalHandler);
 	signal(SIGTERM, signalHandler);
+	signal(SIGCHLD, signalHandler);
 	sig_t cursesWinch = signal(SIGWINCH, signalHandler);
 
 	struct pollfd fds[2] = {
@@ -155,6 +158,25 @@ int main(int argc, char *argv[]) {
 
 		if (signals[SIGHUP]) self.quit = "zzz";
 		if (signals[SIGINT] || signals[SIGTERM]) break;
+
+		if (signals[SIGCHLD]) {
+			int status;
+			while (0 < waitpid(-1, &status, WNOHANG)) {
+				if (WIFEXITED(status) && WEXITSTATUS(status)) {
+					uiFormat(
+						Network, Warm, NULL,
+						"Process exits with status %d", WEXITSTATUS(status)
+					);
+				} else if (WIFSIGNALED(status)) {
+					uiFormat(
+						Network, Warm, NULL,
+						"Process terminates from %s",
+						strsignal(WTERMSIG(status))
+					);
+				}
+			}
+		}
+
 		if (signals[SIGWINCH]) {
 			signals[SIGWINCH] = 0;
 			cursesWinch(SIGWINCH);
td> 2018-11-13Add gzgets.3June McEnroe 2018-11-13Add gzputs.3June McEnroe 2018-11-13Add gzprintf.3June McEnroe 2018-11-13Add gzfwrite.3June McEnroe 2018-11-13Add gzwrite.3June McEnroe 2018-11-12Add gzfread.3June McEnroe 2018-11-12Add gzread.3June McEnroe 2018-11-12Add gzsetparams.3June McEnroe 2018-11-12Add gzbuffer.3June McEnroe 2018-11-12Add gzdopen to gzopen.3June McEnroe 2018-11-12Add gzopen.3June McEnroe 2018-11-12Add inflateBackEnd.3June McEnroe 2018-11-12Add inflateBack.3June McEnroe 2018-11-12Add inflateBackInit.3June McEnroe 2018-11-11Add inflateGetHeader.3June McEnroe 2018-11-11Add inflateMark.3June McEnroe 2018-11-11Add inflatePrime.3June McEnroe 2018-11-11Add inflateReset.3June McEnroe 2018-11-11Add inflateCopy.3June McEnroe 2018-11-11Add inflateSync.3June McEnroe 2018-11-11Add inflateGetDictionary.3June McEnroe 2018-11-11Add inflateSetDictionary.3June McEnroe 2018-11-11Add inflateInit2.3June McEnroe