about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-20 21:05:10 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-20 21:05:10 -0400
commitf9a6372a98cc4d1b70400b2e7238e1f9eae50558 (patch)
tree7eb3280e965e29b80d4a331980bc80c6bb7ed7e7 /src
parent10d7561db5d51231939fa0b42d17eaac2bff6938 (diff)
downloadmusl-f9a6372a98cc4d1b70400b2e7238e1f9eae50558.tar.gz
musl-f9a6372a98cc4d1b70400b2e7238e1f9eae50558.tar.xz
musl-f9a6372a98cc4d1b70400b2e7238e1f9eae50558.zip
workaround bug in linux dup2
the linux documentation for dup2 says it can fail with EBUSY due to a
race condition with open and dup in the kernel. shield applications
(and the rest of libc) from this nonsense by looping until it succeeds
Diffstat (limited to 'src')
-rw-r--r--src/unistd/dup2.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/unistd/dup2.c b/src/unistd/dup2.c
index 7945f853..87a0d445 100644
--- a/src/unistd/dup2.c
+++ b/src/unistd/dup2.c
@@ -1,7 +1,10 @@
 #include <unistd.h>
+#include <errno.h>
 #include "syscall.h"
 
 int dup2(int old, int new)
 {
-	return syscall(SYS_dup2, old, new);
+	int r;
+	while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
+	return __syscall_ret(r);
 }