]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Add a bodge to make pty masters nonblocking on OS X.
authorSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 12:00:19 +0000 (13:00 +0100)
committerSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 12:21:50 +0000 (13:21 +0100)
OS X for some reason doesn't let my usual fcntl approach (wrapped in
nonblock()) work on pty masters - the fcntl(F_SETFL) fails, with the
(in this context) hilariously inappropriate error code ENOTTY. Work
around it by instead passing O_NONBLOCK to posix_openpt.

unix/uxpty.c

index 1d803ab13c47c02888498c3fb5631175e421b2c1..b67a6dad37f5fc633031d02017ce612463ae626b 100644 (file)
@@ -344,7 +344,18 @@ static void pty_open_master(Pty pty)
         ;
 
 #ifdef HAVE_POSIX_OPENPT
+#ifdef SET_NONBLOCK_VIA_OPENPT
+    /*
+     * OS X, as of 10.10 at least, doesn't permit me to set O_NONBLOCK
+     * on pty master fds via the usual fcntl mechanism. Fortunately,
+     * it does let me work around this by adding O_NONBLOCK to the
+     * posix_openpt flags parameter, which isn't a documented use of
+     * the API but seems to work. So we'll do that for now.
+     */
+    pty->master_fd = posix_openpt(flags | O_NONBLOCK);
+#else
     pty->master_fd = posix_openpt(flags);
+#endif
 
     if (pty->master_fd < 0) {
        perror("posix_openpt");
@@ -375,7 +386,9 @@ static void pty_open_master(Pty pty)
     strncpy(pty->name, ptsname(pty->master_fd), FILENAME_MAX-1);
 #endif
 
+#ifndef SET_NONBLOCK_VIA_OPENPT
     nonblock(pty->master_fd);
+#endif
 
     if (!ptys_by_fd)
        ptys_by_fd = newtree234(pty_compare_by_fd);