From 63983c0aac914c1a585cb6a7d0b16dc170b6ee3e Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Thu, 10 Dec 2009 14:14:13 +0100 Subject: [PATCH] Add pty module for forkpty and openpty. --- ChangeLog | 10 ++++++++ doc/glibc-functions/forkpty.texi | 12 +++++---- doc/glibc-functions/openpty.texi | 13 ++++++---- doc/glibc-headers/pty.texi | 9 +++++-- m4/pty.m4 | 42 ++++++++++++++++++++++++++++++ modules/pty | 33 ++++++++++++++++++++++++ modules/pty-tests | 7 +++++ tests/test-pty.c | 55 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 169 insertions(+), 12 deletions(-) create mode 100644 m4/pty.m4 create mode 100644 modules/pty create mode 100644 modules/pty-tests create mode 100644 tests/test-pty.c diff --git a/ChangeLog b/ChangeLog index 1af09830c..48019d0d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-12-07 Simon Josefsson + + * modules/pty: New file. + * modules/pty-tests: New file. + * m4/pty.m4: New file. + * tests/test-pty.c: New file. + * doc/glibc-headers/pty.texi: Modified. + * doc/glibc-functions/forkpty.texi: Modified. + * doc/glibc-functions/openpty.texi: Modified. + 2009-12-09 Bruno Haible Avoid syntax error in C++ mode. diff --git a/doc/glibc-functions/forkpty.texi b/doc/glibc-functions/forkpty.texi index 2ea9b2287..7701a3826 100644 --- a/doc/glibc-functions/forkpty.texi +++ b/doc/glibc-functions/forkpty.texi @@ -2,14 +2,10 @@ @subsection @code{forkpty} @findex forkpty -Gnulib module: --- +Gnulib module: pty Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item One some systems (at least including Cygwin, Interix, OSF/1 4 and 5, and Mac OS X) linking with @code{-lutil} is not required. @@ -21,3 +17,9 @@ The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5, and glibc. It is declared in util.h on Mac OS X, OpenBSD and NetBSD. It is declared in libutil.h on FreeBSD. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +On some systems (at least including Solaris and HP-UX) the function is +missing. +@end itemize diff --git a/doc/glibc-functions/openpty.texi b/doc/glibc-functions/openpty.texi index 79b6b33bc..83975a96a 100644 --- a/doc/glibc-functions/openpty.texi +++ b/doc/glibc-functions/openpty.texi @@ -2,14 +2,10 @@ @subsection @code{openpty} @findex openpty -Gnulib module: --- +Gnulib module: pty Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item One some systems (at least including Cygwin, Interix, OSF/1 4 and 5, and Mac OS X) linking with @code{-lutil} is not required. @@ -21,3 +17,10 @@ The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5, and glibc. It is declared in util.h on Mac OS X, OpenBSD and NetBSD. It is declared in libutil.h on FreeBSD. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@item +On some systems (at least including Solaris and HP-UX) the function is +missing. +@end itemize diff --git a/doc/glibc-headers/pty.texi b/doc/glibc-headers/pty.texi index 26d77647f..4e6884b93 100644 --- a/doc/glibc-headers/pty.texi +++ b/doc/glibc-headers/pty.texi @@ -16,15 +16,20 @@ Documentation: @uref{http://www.kernel.org/doc/man-pages/online/pages/man3/openpty.3.html,,man openpty}. @end itemize -Gnulib module: --- +Gnulib module: pty Portability problems fixed by Gnulib: @itemize +@item +This header file is missing on some platforms that declare the +@code{forkpty} and @code{openpty} functions in @code{util.h} or +@code{libutil.h} instead: MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, +OpenBSD 3.8. @end itemize Portability problems not fixed by Gnulib: @itemize @item This header file is missing on some platforms: -MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw, BeOS. +AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw, BeOS. @end itemize diff --git a/m4/pty.m4 b/m4/pty.m4 new file mode 100644 index 000000000..ba6a8c02a --- /dev/null +++ b/m4/pty.m4 @@ -0,0 +1,42 @@ +# pty.m4 serial 1 +dnl Copyright (C) 2009 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# gl_PTY +# ------ +# Make sure that pty.h provides forkpty, or sets up a replacement header. +# Also define automake variable PTY_LIB to the library needed (if any). +AC_DEFUN([gl_PTY], +[ + PTY_H='' + PTY_LIB='' + # First make sure that pty.h provides forkpty, or setup the replacement. + AC_CHECK_HEADERS_ONCE([pty.h]) + if test $ac_cv_header_pty_h != yes; then + AC_CHECK_DECL([forkpty],,, [[#include ]]) + if test $ac_cv_have_decl_forkpty = no; then + AC_CHECK_DECL([forkpty],,, [[#include ]]) + if test $ac_cv_have_decl_forkpty = no; then + AC_MSG_WARN([[Cannot find forkpty, build will likely fail]]) + else + PTY_H='pty.h' + PTY_HEADER='libutil.h' + fi + else + PTY_H='pty.h' + PTY_HEADER='util.h' + fi + fi + # Second check for the library required for forkpty. + save_LIBS="$LIBS" + AC_SEARCH_LIBS([forkpty], [util], + [if test "$ac_cv_search_forkpty" != "none required"; then + PTY_LIB="$ac_cv_search_forkpty" + fi]) + LIBS="$save_LIBS" + AC_SUBST([PTY_H]) + AC_SUBST([PTY_LIB]) + AC_SUBST([PTY_HEADER]) +]) diff --git a/modules/pty b/modules/pty new file mode 100644 index 000000000..66cecefb2 --- /dev/null +++ b/modules/pty @@ -0,0 +1,33 @@ +Description: +A for systems that lacks it. + +Files: +m4/pty.m4 + +configure.ac: +gl_PTY + +Makefile.am: +BUILT_SOURCES += $(PTY_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +pty.h: + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '#include <'$(PTY_HEADER)'>'; \ + } > $@-t && \ + mv -f $@-t $@ +MOSTLYCLEANFILES += pty.h pty.h-t + +Include: + + +Link: +$(PTY_LIB) + +License: +LGPL + +Maintainer: +Simon Josefsson diff --git a/modules/pty-tests b/modules/pty-tests new file mode 100644 index 000000000..2d8b9c33d --- /dev/null +++ b/modules/pty-tests @@ -0,0 +1,7 @@ +Files: +tests/test-pty.c + +Makefile.am: +TESTS += test-pty +check_PROGRAMS += test-pty +test_pty_LDADD = $(PTY_LIB) diff --git a/tests/test-pty.c b/tests/test-pty.c new file mode 100644 index 000000000..cd24f0d5e --- /dev/null +++ b/tests/test-pty.c @@ -0,0 +1,55 @@ +/* Test of pty.h and openpty/forkpty functions. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Simon Josefsson , 2009. */ + +#include + +#include + +#include + +int +main () +{ + int res; + int amaster; + int aslave; + + res = openpty (&amaster, &aslave, NULL, NULL, NULL); + if (res != 0) + { + printf ("openpty returned %d\n", res); + return 1; + } + + res = forkpty (&amaster, NULL, NULL, NULL); + if (res == 0) + { + /* child process */ + } + else if (res > 0) + { + /* parent */ + } + else + { + printf ("forkpty returned %d\n", res); + return 1; + } + + return 0; +} -- 2.11.0