about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-09 19:42:06 -0500
committerRich Felker <dalias@aerifal.cx>2011-03-09 19:42:06 -0500
commit370f78f2c80c64b7b0780a01e672494a26b5678e (patch)
tree749b912fa92c4f513e8770e3dca091780a4d2317 /src
parent91f7db26212714254e35f3060c22bb1ea20f04fd (diff)
downloadmusl-370f78f2c80c64b7b0780a01e672494a26b5678e.tar.gz
musl-370f78f2c80c64b7b0780a01e672494a26b5678e.tar.xz
musl-370f78f2c80c64b7b0780a01e672494a26b5678e.zip
fix raise semantics with threads.
Diffstat (limited to 'src')
-rw-r--r--src/signal/raise.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/signal/raise.c b/src/signal/raise.c
index 52f8b428..f437d23f 100644
--- a/src/signal/raise.c
+++ b/src/signal/raise.c
@@ -1,7 +1,18 @@
 #include <signal.h>
+#include <errno.h>
 #include "syscall.h"
 
 int raise(int sig)
 {
-	return __syscall_kill(__syscall_getpid(), sig);
+	int pid, tid, ret;
+	/* Getting the pid/tid pair is not atomic, and could give wrong
+	 * result if a fork occurs in a signal handler between the two
+	 * syscalls. Use the tgkill syscall's ESRCH semantics to detect
+	 * this condition and retry. */
+	do {
+		tid = syscall0(__NR_gettid);
+		pid = syscall0(__NR_getpid);
+		ret = syscall3(__NR_tgkill, pid, tid, sig);
+	} while (ret<0 && errno == ESRCH);
+	return ret;
 }