Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 2003d1abfa0c20ee77815f0da33e2c1c > files > 107

glibc-2.5-49.el5_5.5.src.rpm

2007-10-04  Ulrich Drepper  <drepper@redhat.com>

	* login/login_tty.c (login_tty): The Linux kernel can return EBUSY
	for dup2 in case another thread races with the current one.  Retry
	in this case.

--- libc/login/login_tty.c	24 Oct 2004 21:20:21 -0000	1.4
+++ libc/login/login_tty.c	4 Oct 2007 21:51:34 -0000	1.5
@@ -31,6 +31,7 @@
 static char sccsid[] = "@(#)login_tty.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 
+#include <errno.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
@@ -63,9 +64,12 @@ login_tty(fd)
 	    }
 	}
 #endif
-	(void) dup2(fd, 0);
-	(void) dup2(fd, 1);
-	(void) dup2(fd, 2);
+	while (dup2(fd, 0) == -1 && errno == EBUSY)
+	  ;
+	while (dup2(fd, 1) == -1 && errno == EBUSY)
+	  ;
+	while (dup2(fd, 2) == -1 && errno == EBUSY)
+	  ;
 	if (fd > 2)
 		(void) close(fd);
 	return (0);