shithub: qk1

Download patch

ref: a358b6be9f633e4c95205f67bed0cbdf80ce7164
parent: c59890019f2b2822fd4fd02bade798d63a6d1e29
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Dec 31 18:34:29 EST 2023

pthread signal handler

--- a/sys_unix.c
+++ b/sys_unix.c
@@ -4,6 +4,7 @@
 #include <errno.h>
 #include <fenv.h>
 #include <signal.h>
+#include <pthread.h>
 
 char *game;
 int debug;
@@ -113,6 +114,18 @@
 	exit(0);
 }
 
+static void *
+sighandler(void *ss)
+{
+	int s;
+
+	for(;;){
+		if(sigwait(ss, &s) != 0)
+			break;
+	}
+	return nil;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -124,7 +137,14 @@
 		nil,
 		nil,
 	};
+	sigset_t ss;
+	pthread_t tid;
 
+	sigemptyset(&ss);
+	sigaddset(&ss, SIGPIPE);
+	pthread_sigmask(SIG_BLOCK, &ss, NULL);
+	pthread_create(&tid, nil, sighandler, &ss);
+
 	parg_init(&ps);
 	nargs = 0;
 	while((c = parg_getopt(&ps, argc, argv, "Ddg:N:")) >= 0){
@@ -161,8 +181,6 @@
 	}
 
 	srand(nanosec() + time(nil));
-
-	signal(SIGPIPE, SIG_IGN);
 
 	paths[1] = strdup(va("%s/.quake", getenv("HOME")));
 	Host_Init(nargs, argv, paths);