ref: 91f426bd7c4eacd1656ae8da651eb9deb93d5763
parent: 041d3c9d8de4ed92c5cafc3c12c5170113e55677
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Aug 17 13:24:00 EDT 2023
sigaction: do not crash
--- a/libnpe/sigaction.c
+++ b/libnpe/sigaction.c
@@ -4,8 +4,19 @@
/* FIXME this only supports a single handler */
static sa_handler last;
-sa_handler SIG_DFL = (void*)1, SIG_IGN = nil;
+static void
+_SIG_DFL(int)
+{
+}
+
+static void
+_SIG_IGN(int)
+{
+}
+
+sa_handler SIG_DFL = _SIG_DFL, SIG_IGN = _SIG_IGN;
+
static int
handler(void*, char *s)
{
@@ -12,7 +23,8 @@
/* kill is kill */
if(strcmp(s, "kill") != 0 && strcmp(s, "threadint") != 0){
fprint(2, "%s: %s\n", threadgetname(), s);
- last(SIGSEGV);
+ if(last != nil)
+ last(SIGTERM);
}
return 0;
}
@@ -20,7 +32,7 @@
void
sigaction(int, struct sigaction *act, struct sigaction *)
{
- if(act != nil && last == nil){
+ if(act != nil && act->sa_handler != nil && last == nil){
last = act->sa_handler;
atnotify(handler, 1);
}else if(act == nil){