[Patches] openpty() and forkpty()

Andrew M. Kuchling akuchlin@mems-exchange.org
Fri, 9 Jun 2000 11:18:43 -0400


On Sun, Jun 04, 2000 at 02:09:46AM +0200, Thomas Wouters wrote:
>Attached is a patch to add openpty() and forkpty() functions to the posix
>module, if the target platform supports them.

The patch is actually quite small, though it looks large because the
patches to the generated configure script are included.  If the
patches are accepted, we'll regenerate the configure-related files and
check them in.

Anyway, the patch basically boils down to the following, which looks
good.  With the addition of a patch to libposix.tex documenting the
two new functions, I'd suggest checking it in.

--amk


>Index: configure.in
>===================================================================
>RCS file: /cvsroot/python/python/dist/src/configure.in,v
>retrieving revision 1.124
>diff -c -r1.124 configure.in
>*** configure.in	2000/05/26 12:22:54	1.124
>--- configure.in	2000/06/03 23:37:06
>***************
>*** 770,775 ****
>--- 770,780 ----
>   tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
>   truncate uname waitpid)
>  
>+ # check for openpty and forkpty
>+ 
>+ AC_CHECK_FUNCS(openpty,, AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY)] [LIBS="$LIBS -lutil"]))
>+ AC_CHECK_FUNCS(forkpty,, AC_CHECK_LIB(util,forkpty, [AC_DEFINE(HAVE_FORKPTY)] [LIBS="$LIBS -lutil"]))
>+ 
>  # check for long file support functions
>  AC_CHECK_FUNCS(fseek64 fseeko fstatvfs ftell64 ftello statvfs)
>  
>Index: Modules/posixmodule.c
>===================================================================
>RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
>retrieving revision 2.135
>diff -c -r2.135 posixmodule.c
>*** Modules/posixmodule.c	2000/06/01 02:02:46	2.135
>--- Modules/posixmodule.c	2000/06/03 23:37:08
>***************
>*** 1731,1737 ****
>--- 1731,1779 ----
>  }
>  #endif
>  
>+ #ifdef HAVE_OPENPTY
>+ static char posix_openpty__doc__[] =
>+ "openpty() -> (master_fd, slave_fd)\n\
>+ Open a pseudo-terminal, returning open fd's for both master and slave end.\n";
>  
>+ static PyObject *
>+ posix_openpty(self, args)
>+ 	PyObject *self;
>+ 	PyObject *args;
>+ {
>+ 	int master_fd, slave_fd;
>+ 	if (!PyArg_ParseTuple(args, ":openpty"))
>+ 		return NULL;
>+ 	if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
>+ 		return posix_error();
>+ 	return Py_BuildValue("(ii)", master_fd, slave_fd);
>+ }
>+ #endif
>+ 
>+ #ifdef HAVE_FORKPTY
>+ static char posix_forkpty__doc__[] =
>+ "forkpty() -> (pid, master_fd)\n\
>+ Fork a new process with a new pseudo-terminal as controlling tty.\n\n\
>+ Like fork(), return 0 as pid to child process, and PID of child to parent.\n\
>+ To both, return fd of newly opened pseudo-terminal.\n";
>+ 
>+ static PyObject *
>+ posix_forkpty(self, args)
>+ 	PyObject *self;
>+ 	PyObject *args;
>+ {
>+ 	int master_fd, pid;
>+ 	
>+ 	if (!PyArg_ParseTuple(args, ":forkpty"))
>+ 		return NULL;
>+ 	pid = forkpty(&master_fd, NULL, NULL, NULL);
>+ 	if (pid == -1)
>+ 		return posix_error();
>+ 	PyOS_AfterFork();
>+ 	return Py_BuildValue("(ii)", pid, master_fd);
>+ }
>+ #endif
>+ 
>  #ifdef HAVE_GETEGID
>  static char posix_getegid__doc__[] =
>  "getegid() -> egid\n\
>***************
>*** 4514,4519 ****
>--- 4556,4567 ----
>  #ifdef HAVE_FORK
>  	{"fork",	posix_fork, METH_VARARGS, posix_fork__doc__},
>  #endif /* HAVE_FORK */
>+ #ifdef HAVE_OPENPTY
>+ 	{"openpty",	posix_openpty, METH_VARARGS, posix_openpty__doc__},
>+ #endif /* HAVE_OPENPTY */
>+ #ifdef HAVE_FORKPTY
>+ 	{"forkpty",	posix_forkpty, METH_VARARGS, posix_forkpty__doc__},
>+ #endif /* HAVE_FORKPTY */
>  #ifdef HAVE_GETEGID
>  	{"getegid",	posix_getegid, METH_VARARGS, posix_getegid__doc__},
>  #endif /* HAVE_GETEGID */