瀏覽代碼

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
Rich Felker 14 年之前
父節點
當前提交
f9a6372a98
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      src/unistd/dup2.c

+ 4 - 1
src/unistd/dup2.c

@@ -1,7 +1,10 @@
 #include <unistd.h>
 #include <unistd.h>
+#include <errno.h>
 #include "syscall.h"
 #include "syscall.h"
 
 
 int dup2(int old, int new)
 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);
 }
 }