summaryrefslogtreecommitdiff
path: root/src/shared/missing.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-16 23:53:23 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-18 00:52:41 -0500
commitee05e7795bb9ad7d1212dd49ad362f3e9603c4fd (patch)
tree54b417af3285979aef08af98d50e81b851c9b256 /src/shared/missing.h
parent503dbda6d94c16161762b7b489677a377f235590 (diff)
core: use raw_clone instead of fork in signal handler
fork() is not async-signal-safe and calling it from the signal handler could result in a deadlock when at_fork() handlers are called. Using the raw clone() syscall sidesteps that problem. The tricky part is that raise() does not work, since getpid() does not work. Add raw_getpid() to get the real pid, and use kill() instead of raise(). https://bugs.freedesktop.org/show_bug.cgi?id=86604
Diffstat (limited to 'src/shared/missing.h')
-rw-r--r--src/shared/missing.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/shared/missing.h b/src/shared/missing.h
index bea1254369..91a6215226 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -636,12 +636,16 @@ static inline int setns(int fd, int nstype) {
#define CAP_AUDIT_READ 37
#endif
-static inline long raw_clone(unsigned long flags, void *child_stack) {
+static inline int raw_clone(unsigned long flags, void *child_stack) {
#if defined(__s390__) || defined(__CRIS__)
/* On s390 and cris the order of the first and second arguments
* of the raw clone() system call is reversed. */
- return syscall(__NR_clone, child_stack, flags);
+ return (int) syscall(__NR_clone, child_stack, flags);
#else
- return syscall(__NR_clone, flags, child_stack);
+ return (int) syscall(__NR_clone, flags, child_stack);
#endif
}
+
+static inline pid_t raw_getpid(void) {
+ return (pid_t) syscall(__NR_getpid);
+}