[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#12261: Followup, possible patch for second oldest bug in xterm



This bug still exists in current xterm, as far as I can tell.

The following untested patch implements Richard Braakman's suggestion from 1997,
slightly more portably.

Open questions:
(1) Where should the logging be closed?
(2) Is any additional portability goo needed to send this upstream (e.g. for 
systems without termios.h)?
(3) Is anyone interested in testing it?

I assign these changes to the public domain, since they're trivial.

--- main.c	2007-04-10 04:39:13.000000000 -0400
+++ main.c.new	2007-04-10 04:56:45.000000000 -0400
@@ -4613,11 +4613,9 @@
 #endif /* USE_SYSV_UTMP */
 #endif /* HAVE_UTMP */
 
-    close(screen->respond);	/* close explicitly to avoid race with slave side */
-#ifdef ALLOWLOGGING
-    if (screen->logging)
-	CloseLog(screen);
-#endif
+    /* Flush pending data before releasing ownership, so nobody else can
+       grab it */
+    tcflush(screen->respond, TCOFLUSH);
 
     if (am_slave < 0) {
 	/* restore ownership of tty and pty */
@@ -4625,6 +4623,16 @@
 #if (defined(USE_PTY_DEVICE) && !defined(__sgi) && !defined(__hpux))
 	set_owner(ptydev, 0, 0, 0666U);
 #endif
+
+   /* Close after releasing ownership to avoid race condition: other programs 
+      grabbing it, and *then* having us release ownership... */
+
+    close(screen->respond);	/* close explicitly to avoid race with slave side */
+#ifdef ALLOWLOGGING
+    if (screen->logging)
+	CloseLog(screen);
+#endif
+
     }
 #ifdef NO_LEAKS
     if (n == 0) {

-- 
Nathanael Nerode  <neroden@fastmail.fm>

This space intentionally left blank.




Reply to: