X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fsignal%2Fraise.c;fp=src%2Fsignal%2Fraise.c;h=f437d23f2b4d2a311efb0d96b3ada00373a8a780;hb=370f78f2c80c64b7b0780a01e672494a26b5678e;hp=52f8b428c3bfbdf1c1f3c741fc44be8def8c772f;hpb=91f7db26212714254e35f3060c22bb1ea20f04fd;p=musl 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 +#include #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; }