From edd7aa7ffe95105f82688057ded753c8f7f66728 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sun, 26 Feb 2012 00:33:59 -0800 Subject: [PATCH] Fix broken pty support on Mac OS X 10.7. --- src/microcode/configure.ac | 5 +++-- src/microcode/ux.h | 4 ++++ src/microcode/uxterm.c | 39 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/microcode/configure.ac b/src/microcode/configure.ac index 2a032eec0..146cb32a1 100644 --- a/src/microcode/configure.ac +++ b/src/microcode/configure.ac @@ -219,7 +219,7 @@ AC_CHECK_HEADERS([stropts.h time.h]) AC_CHECK_HEADERS([sys/file.h sys/ioctl.h sys/mount.h sys/param.h sys/poll.h]) AC_CHECK_HEADERS([sys/ptyio.h sys/socket.h sys/time.h sys/timex.h sys/un.h]) AC_CHECK_HEADERS([sys/vfs.h]) -AC_CHECK_HEADERS([termio.h termios.h unistd.h utime.h]) +AC_CHECK_HEADERS([termio.h termios.h unistd.h util.h utime.h]) AC_CHECK_HEADERS([dlfcn.h netdb.h signal.h]) AC_CHECK_HEADERS([sys/mman.h float.h assert.h stdint.h]) @@ -527,7 +527,8 @@ AC_CHECK_FUNCS([kill]) AC_CHECK_FUNCS([lockf log1p]) AC_CHECK_FUNCS([madvise memcpy mkdir mktime modf]) AC_CHECK_FUNCS([nice ntp_adjtime ntp_gettime]) -AC_CHECK_FUNCS([poll posix_madvise prealloc]) +AC_CHECK_FUNCS([openpty]) +AC_CHECK_FUNCS([poll posix_madvise posix_openpt prealloc]) AC_CHECK_FUNCS([rename rmdir]) AC_CHECK_FUNCS([select setitimer setpgrp setpgrp2 shmat sigaction]) AC_CHECK_FUNCS([sighold socket statfs strchr strerror strstr strtol]) diff --git a/src/microcode/ux.h b/src/microcode/ux.h index afd1cdf87..fe61928e5 100644 --- a/src/microcode/ux.h +++ b/src/microcode/ux.h @@ -296,6 +296,10 @@ USA. #include #endif +#ifdef HAVE_UTIL_H +# include +#endif + #include "intext.h" #include "dstack.h" #include "osscheme.h" diff --git a/src/microcode/uxterm.c b/src/microcode/uxterm.c index 8dcda5039..2f0f45099 100644 --- a/src/microcode/uxterm.c +++ b/src/microcode/uxterm.c @@ -51,6 +51,12 @@ extern int UX_terminal_control_ok (int fd); # endif # endif /* HAVE_SGTTY_H */ #endif /* not HAVE_TERMIOS_H nor HAVE_TERMIO_H */ + +#if defined(HAVE_POSIX_OPENPT) || defined(HAVE_OPENPTY) +# undef TRY_OPEN_PTY_MASTER_BSD +#else +# define TRY_OPEN_PTY_MASTER_BSD 1 +#endif struct terminal_state { @@ -732,6 +738,8 @@ OS_have_ptys_p (void) #endif } +#ifdef TRY_OPEN_PTY_MASTER_BSD + static const char * open_pty_master_bsd (Tchannel * master_fd, const char ** master_fname) { @@ -770,11 +778,18 @@ open_pty_master_bsd (Tchannel * master_fd, const char ** master_fname) return (0); } +#endif /* not TRY_OPEN_PTY_MASTER_BSD */ + #ifndef O_NOCTTY # define O_NOCTTY 0 #endif -/* Open an available pty, putting channel in (*ptyv), +/* Don't use posix_openpt in Mac OS X; openpty works properly. */ +#ifdef __APPLE__ +# undef HAVE_POSIX_OPENPT +#endif + +/* Open an available pty, putting channel in (*master_fd), and return the file name of the pty. Signal error if none available. */ @@ -785,11 +800,27 @@ OS_open_pty_master (Tchannel * master_fd, const char ** master_fname) while (1) { static char slave_name [24]; +#ifdef HAVE_POSIX_OPENPT + int fd = (posix_openpt (O_RDWR | O_NOCTTY)); +#else +#ifdef HAVE_OPENPTY + int fd; + { + int slave_fd; + int rc = (openpty ((&fd), (&slave_fd), slave_name, 0, 0)); + if (rc < 0) + fd = -1; + else + (void) UX_close(slave_fd); + } +#else #ifdef HAVE_GETPT int fd = (getpt ()); #else int fd = (UX_open ("/dev/ptmx", (O_RDWR | O_NOCTTY), 0)); -#endif +#endif /* not HAVE_GETPT */ +#endif /* not HAVE_OPENPTY */ +#endif /* not HAVE_POSIX_OPENPT */ if (fd < 0) { if (errno == EINTR) @@ -797,9 +828,13 @@ OS_open_pty_master (Tchannel * master_fd, const char ** master_fname) deliver_pending_interrupts (); continue; } +#ifdef TRY_OPEN_PTY_MASTER_BSD /* Try BSD open. This is needed for Linux which might have Unix98 support in the library but not the kernel. */ return (open_pty_master_bsd (master_fd, master_fname)); +#else + return (0); +#endif } #ifdef sonyrisc sony_block_sigchld (); -- 2.25.1