]> granicus.if.org Git - python/commitdiff
Patch #656590: /dev/ptmx support for ptys.
authorMartin v. Löwis <martin@v.loewis.de>
Tue, 31 Dec 2002 12:55:15 +0000 (12:55 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Tue, 31 Dec 2002 12:55:15 +0000 (12:55 +0000)
Misc/ACKS
Misc/NEWS
Modules/posixmodule.c
configure
configure.in
pyconfig.h.in

index d5b1f25c6c969540cd8e79de2550f64fb11725fe..839f8ed14ca75c234d42256a188da7b4a5498727 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -512,6 +512,7 @@ Casper Stoel
 Peter Stoehr
 Ken Stox
 Daniel Stutzbach
+Paul Swartz
 William Tanksley
 Christian Tanzer
 Amy Taylor
index 9ffc915fc60c294497a9361ce8b921756ad6778b..a5dbd94930f91f7217f18f3ce21d1ea0cc713859 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -359,6 +359,8 @@ Core and builtins
 Extension modules
 -----------------
 
+- posix.openpty now works on all systems that have /dev/ptmx.
+
 - A module zipimport exists to support importing code from zip
   archives.
 
index 1d8697e50396c4f5c1b202ef957a6aac2e6a9356..646229e0b3bbed7ae081b70dcf9df31e550c01e6 100644 (file)
@@ -2718,7 +2718,7 @@ posix_fork(PyObject *self, PyObject *args)
 }
 #endif
 
-#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
+#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)
 #ifdef HAVE_PTY_H
 #include <pty.h>
 #else
@@ -2726,9 +2726,12 @@ posix_fork(PyObject *self, PyObject *args)
 #include <libutil.h>
 #endif /* HAVE_LIBUTIL_H */
 #endif /* HAVE_PTY_H */
-#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
+#ifdef sun
+#include <sys/stropts.h>
+#endif
+#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */
 
-#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY)
+#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
 PyDoc_STRVAR(posix_openpty__doc__,
 "openpty() -> (master_fd, slave_fd)\n\n\
 Open a pseudo-terminal, returning open fd's for both master and slave end.\n");
@@ -2739,6 +2742,12 @@ posix_openpty(PyObject *self, PyObject *args)
        int master_fd, slave_fd;
 #ifndef HAVE_OPENPTY
        char * slave_name;
+#endif
+#if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY)
+       void *sig_saved;
+#ifdef sun
+       extern char *ptsname();
+#endif
 #endif
 
        if (!PyArg_ParseTuple(args, ":openpty"))
@@ -2747,7 +2756,7 @@ posix_openpty(PyObject *self, PyObject *args)
 #ifdef HAVE_OPENPTY
        if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
                return posix_error();
-#else
+#elif HAVE__GETPTY
        slave_name = _getpty(&master_fd, O_RDWR, 0666, 0);
        if (slave_name == NULL)
                return posix_error();
@@ -2755,12 +2764,35 @@ posix_openpty(PyObject *self, PyObject *args)
        slave_fd = open(slave_name, O_RDWR);
        if (slave_fd < 0)
                return posix_error();
+#else
+       master_fd = open("/dev/ptmx", O_RDWR | O_NOCTTY); /* open master */
+       if (master_fd < 0)
+               return posix_error();
+       sig_saved = signal(SIGCHLD, SIG_DFL);
+       if (grantpt(master_fd) < 0) /* change permission of slave */
+               return posix_error();
+       if (unlockpt(master_fd) < 0) /* unlock slave */
+               return posix_error();
+       signal(SIGCHLD, sig_saved);
+       slave_name = ptsname(master_fd); /* get name of slave */
+       if (slave_name == NULL)
+               return posix_error();
+       slave_fd = open(slave_name, O_RDWR | O_NOCTTY); /* open slave */
+       if (slave_fd < 0)
+               return posix_error();
+#ifndef __CYGWIN__ 
+       ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */
+       ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */
+#ifndef _hpux
+       ioctl(slave_fd, I_PUSH, "ttcompat"); /* push ttcompat */
+#endif /* _hpux */
+#endif /* HAVE_CYGWIN */
 #endif /* HAVE_OPENPTY */
 
        return Py_BuildValue("(ii)", master_fd, slave_fd);
 
 }
-#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) */
+#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */
 
 #ifdef HAVE_FORKPTY
 PyDoc_STRVAR(posix_forkpty__doc__,
@@ -7229,9 +7261,9 @@ static PyMethodDef posix_methods[] = {
 #ifdef HAVE_FORK
        {"fork",        posix_fork, METH_VARARGS, posix_fork__doc__},
 #endif /* HAVE_FORK */
-#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY)
+#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
        {"openpty",     posix_openpty, METH_VARARGS, posix_openpty__doc__},
-#endif /* HAVE_OPENPTY || HAVE__GETPTY */
+#endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */
 #ifdef HAVE_FORKPTY
        {"forkpty",     posix_forkpty, METH_VARARGS, posix_forkpty__doc__},
 #endif /* HAVE_FORKPTY */
index 5ef2ea21cc942f0144aac7c6468a03ec91991b60..86d9578918987a4de7b1e26371cf497f550bee7a 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 1.380 .
+# From configure.in Revision: 1.381 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.53 for python 2.3.
 #
@@ -908,7 +908,7 @@ esac
 # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
 # absolute.
 ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
-ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd`
+ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
 ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
 ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
 
@@ -16657,6 +16657,23 @@ _ACEOF
 
 fi
 
+echo "$as_me:$LINENO: checking for /dev/ptmx" >&5
+echo $ECHO_N "checking for /dev/ptmx... $ECHO_C" >&6
+
+if test -e /dev/ptmx
+then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_DEV_PTMX 1
+_ACEOF
+
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
 echo "$as_me:$LINENO: checking for socklen_t" >&5
 echo $ECHO_N "checking for socklen_t... $ECHO_C" >&6
 if test "${ac_cv_type_socklen_t+set}" = set; then
@@ -17483,7 +17500,7 @@ esac
 # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
 # absolute.
 ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
-ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd`
+ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
 ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
 ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
 
index e461658877dddce3e0ba82bec6511f5bf3b1ad3d..48fa694bd44d46267c58f53c1e5bb8532e248cfe 100644 (file)
@@ -2486,6 +2486,17 @@ then
   [Define if WINDOW in curses.h offers a field _flags.])
 fi
 
+AC_MSG_CHECKING(for /dev/ptmx)
+
+if test -e /dev/ptmx
+then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_DEV_PTMX, 1,
+  [Define if we have /dev/ptmx.])
+else
+  AC_MSG_RESULT(no)
+fi
+
 AC_CHECK_TYPE(socklen_t,,
   AC_DEFINE(socklen_t,int,
             Define to `int' if <sys/socket.h> does not define.),[
index 922147e339603c17de75cc73e2fbf72dc2f8b815..56a5c75d25eb3de0e37780125ac856d6008dfd57 100644 (file)
@@ -65,6 +65,9 @@
 /* Define to 1 if you have the device macros. */
 #undef HAVE_DEVICE_MACROS
 
+/* Define if we have /dev/ptmx. */
+#undef HAVE_DEV_PTMX
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #undef HAVE_DIRENT_H