--- xterm-297.orig/main.c	2013-05-28 00:11:11.000000000 +0200
+++ xterm-297/main.c	2013-10-31 12:24:52.000000000 +0100
@@ -2583,7 +2583,7 @@ main(int argc, char *argv[]ENVP_ARG)
     }
 }
 
-#if defined(__osf__) || (defined(__GLIBC__) && !defined(USE_USG_PTYS)) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#if defined(__osf__) || (defined(__linux__) && !defined(USE_USG_PTYS)) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
 #define USE_OPENPTY 1
 static int opened_tty = -1;
 #endif
@@ -3134,7 +3134,7 @@ find_utmp(struct UTMP_STR *tofind)
 
 #define close_fd(fd) close(fd), fd = -1
 
-#if defined(TIOCNOTTY) && (!defined(__GLIBC__) || (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
+#if defined(TIOCNOTTY) && defined(__linux__)
 #define USE_NO_DEV_TTY 1
 #else
 #define USE_NO_DEV_TTY 0
@@ -3378,7 +3378,8 @@ spawnXTerm(XtermWidget xw)
 	    }
 #endif /* __MVS__ */
 
-	    close_fd(ttyfd);
+	    // do not close it here
+	    // close_fd(ttyfd);
 	}
 
 	if (get_pty(&screen->respond, XDisplayString(screen->display))) {
@@ -3807,8 +3808,9 @@ spawnXTerm(XtermWidget xw)
 		   eg. by lineedit in the shell, or emacs, etc. then tio
 		   will have bad values.  Let's just get termio from the
 		   new tty and tailor it.  */
-		if (ttyGetAttr(ttyfd, &tio) == -1)
+		if (ttyGetAttr(ttyfd, &tio) == -1) {
 		    SysError(ERROR_TIOCGETP);
+		}
 		tio.c_lflag |= ECHOE;
 #endif /* umips */
 		/* Now is also the time to change the modes of the
