[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pty.h replacement
From: |
Simon Josefsson |
Subject: |
Re: pty.h replacement |
Date: |
Tue, 08 Dec 2009 18:23:03 +0100 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.1 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Hi Simon,
>
>> > Darwin has forkpty in util.h instead of the glibc name of pty.h. I'm
>> > working on a gnulib module to provide compatibility mappings... stay
>> > tuned.
>>
>> Here it is. Tested on glibc debian and Mac OS X 10.5.
>
> As far as I can see the portability situation of openpty and forkpty
> is like this:
>
> Platform Header Library
>
> Cygwin <pty.h> libc
> Interix <pty.h> libc
> OSF/1 4 and 5 <pty.h> libc
> glibc <pty.h> libutil
> MacOS X <util.h> libc
> OpenBSD, NetBSD <util.h> libutil
> FreeBSD <libutil.h> libutil
Thanks. Fixing this was easier than I thought, although of course I
haven't yet tested it on all those systems.
> HP has a 10-page document "Implementing openpty and forkpty on HP-UX" [1].
> See also [2].
>
> [1] http://h30097.www3.hp.com/docs/transition/openpty.pdf
> [2] http://forums.sun.com/thread.jspa?threadID=5084907
And my patch does nothing to fix the problem on these systems -- that is
for future work. I may look into fixing this for Solaris eventually,
but I'd like to push the patch below first so that Mac OS X works.
>> +2009-12-07 Simon Josefsson <address@hidden>
>> +
>> + * modules/pty: New file.
>> + * modules/pty-tests: New file.
>> + * doc/glibc-headers/pty.texi: New file.
>
> Your patch modifies pty.texi; it doesn't create it.
Fixed below.
>> diff --git a/doc/glibc-headers/pty.texi b/doc/glibc-headers/pty.texi
>> index 26d7764..ec0d7fa 100644
>> --- a/doc/glibc-headers/pty.texi
>> +++ b/doc/glibc-headers/pty.texi
>
> Actually, since openpty and forkpty are glibc function, therefore two files
> doc/glibc-functions/openpty.texi
> doc/glibc-functions/forkpty.texi
> should be created. They escaped me when I created the hundreds of *.texi
> files.
Already taken care of with my earlier patch.
>> Portability problems fixed by Gnulib:
>> @itemize
>> address@hidden
>> +This header file is missing on Mac OS X where the functions are
>> +declared by util.h instead, and there is no requirement to link with
>> address@hidden
>> @end itemize
>
> Should also mention the other platforms (FreeBSD, NetBSD, OpenBSD).
It has been rewritten, see below.
>> +# gl_PTY
>> +# --------------------
>
> 20 dashes to underline 6 characters?
Cut'n'paste problem, fixed below.
>> +# Test whether forkpty is provided by pty.h and -lutil. When forkpty
>> +# is declared by util.h and available without -lutil instead (as it is
>> +# on Mac OS X), provide a pty.h replacement. Always define $(PTY_LIB)
>> +# to the library.
>> +AC_DEFUN([gl_PTY],
>> +[
>> + PTY_H=''
>> + PTY_LIB='-lutil'
>> + AC_CHECK_HEADERS_ONCE([pty.h])
>> + if test $ac_cv_header_pty_h != yes; then
>
> This code assumes that if <pty.h> exists, -lutil is needed, and vice
> versa. But actually the issue of the header file and the issue of the
> library are independent (see the table above).
>
> Also there is the case of <libutil.h> instead of <util.h> (FreeBSD).
Yep, this was the new complexity. I think it actually made the code a
bit cleaner to read.
>> +# We need the following in order to create <pty.h> when the system
>> +# doesn't have one that works with the given compiler.
>> +pty.h:
>> + echo '#include <util.h>' > address@hidden && \
>> + mv address@hidden $@
>
> By convention, we put a line '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'
> at the beginning of every autogenerated .h file. That was the outcome of a
> discussion: people should be warned when attempting to edit such a file.
Good point, also fixed below.
/Simon
>From 3b2d749ef288cb9841c5965b98cd86cd5b9ee012 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Tue, 8 Dec 2009 18:18:56 +0100
Subject: [PATCH] Add pty module for forkpty and openpty.
---
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 ++++++++++++++++++++++++++++++++++++++
7 files changed, 159 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/doc/glibc-functions/forkpty.texi b/doc/glibc-functions/forkpty.texi
index 2ea9b22..7701a38 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
address@hidden itemize
-
-Portability problems not fixed by Gnulib:
address@hidden
@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:
address@hidden
+On some systems (at least including Solaris and HP-UX) the function is
+missing.
address@hidden itemize
diff --git a/doc/glibc-functions/openpty.texi b/doc/glibc-functions/openpty.texi
index 79b6b33..83975a9 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
address@hidden itemize
-
-Portability problems not fixed by Gnulib:
address@hidden
@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:
address@hidden
address@hidden
+On some systems (at least including Solaris and HP-UX) the function is
+missing.
address@hidden itemize
diff --git a/doc/glibc-headers/pty.texi b/doc/glibc-headers/pty.texi
index 26d7764..4e6884b 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
address@hidden
+This header file is missing on some platforms that declare the
address@hidden and @code{openpty} functions in @code{util.h} or
address@hidden 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 0000000..ba6a8c0
--- /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 <util.h>]])
+ if test $ac_cv_have_decl_forkpty = no; then
+ AC_CHECK_DECL([forkpty],,, [[#include <libutil.h>]])
+ 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 0000000..66cecef
--- /dev/null
+++ b/modules/pty
@@ -0,0 +1,33 @@
+Description:
+A <pty.h> 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 <pty.h> when the system
+# doesn't have one that works with the given compiler.
+pty.h:
+ $(AM_V_GEN)rm -f address@hidden $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ echo '#include <'$(PTY_HEADER)'>'; \
+ } > address@hidden && \
+ mv -f address@hidden $@
+MOSTLYCLEANFILES += pty.h pty.h-t
+
+Include:
+<pty.h>
+
+Link:
+$(PTY_LIB)
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson
diff --git a/modules/pty-tests b/modules/pty-tests
new file mode 100644
index 0000000..2d8b9c3
--- /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 0000000..cd24f0d
--- /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 <http://www.gnu.org/licenses/>. */
+
+/* Written by Simon Josefsson <address@hidden>, 2009. */
+
+#include <config.h>
+
+#include <pty.h>
+
+#include <stdio.h>
+
+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;
+}
--
1.6.5.3