fix raise semantics with threads.
[musl] / src / signal / raise.c
1 #include <signal.h>
2 #include <errno.h>
3 #include "syscall.h"
4
5 int raise(int sig)
6 {
7         int pid, tid, ret;
8         /* Getting the pid/tid pair is not atomic, and could give wrong
9          * result if a fork occurs in a signal handler between the two
10          * syscalls. Use the tgkill syscall's ESRCH semantics to detect
11          * this condition and retry. */
12         do {
13                 tid = syscall0(__NR_gettid);
14                 pid = syscall0(__NR_getpid);
15                 ret = syscall3(__NR_tgkill, pid, tid, sig);
16         } while (ret<0 && errno == ESRCH);
17         return ret;
18 }