1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2025-08-17 12:41:05 +03:00

forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.

This commit is contained in:
Bruno Haible
2010-03-22 02:46:57 +01:00
parent e665e401dc
commit eb8d73f910
9 changed files with 107 additions and 32 deletions

View File

@@ -1,3 +1,17 @@
2010-03-21 Bruno Haible <bruno@clisp.org>
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
* lib/forkpty.c (forkpty): New replacement function, from glibc with
modifications.
* lib/pty.in.h (forkpty): Update declaration. Add comments.
* m4/pty.m4 (gl_FORKPTY): If forkpty is not declared, arrange to
provide the replacement.
* modules/forkpty (Depends-on): Add openpty, login_tty.
* m4/pty_h.m4 (gl_PTY_H_DEFAULTS): Initialize HAVE_FORKPTY.
* modules/pty (Makefile.am): Substitute HAVE_FORKPTY.
* doc/glibc-functions/forkpty.texi: More supported platforms.
* config/srclist.txt: Add forkpty.c (commented).
2010-03-21 Bruno Haible <bruno@clisp.org> 2010-03-21 Bruno Haible <bruno@clisp.org>
* modules/forkpty-tests: Use the common TEMPLATE-TESTS. * modules/forkpty-tests: Use the common TEMPLATE-TESTS.

View File

@@ -174,6 +174,7 @@ $LIBCSRC/stdlib/strtoul.c lib gpl
#$LIBCSRC/locale/programs/xmalloc.c lib gpl #$LIBCSRC/locale/programs/xmalloc.c lib gpl
#$LIBCSRC/locale/programs/xstrdup.c lib gpl #$LIBCSRC/locale/programs/xstrdup.c lib gpl
# #
#$LIBCSRC/login/forkpty.c lib gpl
#$LIBCSRC/login/programs/pt_chown.c lib gpl #$LIBCSRC/login/programs/pt_chown.c lib gpl
# #
# http://sources.redhat.com/bugzilla/show_bug.cgi?id=321 # http://sources.redhat.com/bugzilla/show_bug.cgi?id=321

View File

@@ -7,6 +7,9 @@ Gnulib module: forkpty
Portability problems fixed by Gnulib: Portability problems fixed by Gnulib:
@itemize @itemize
@item @item
This function is missing on some platforms:
AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw.
@item
One some systems (at least including Cygwin, Interix, OSF/1 4 and 5, One some systems (at least including Cygwin, Interix, OSF/1 4 and 5,
and Mac OS X) linking with @code{-lutil} is not required. and Mac OS X) linking with @code{-lutil} is not required.
@item @item
@@ -24,6 +27,4 @@ FreeBSD, Cygwin 1.7.1.
Portability problems not fixed by Gnulib: Portability problems not fixed by Gnulib:
@itemize @itemize
On some systems (at least including Solaris and HP-UX) the function is
missing.
@end itemize @end itemize

View File

@@ -1,4 +1,4 @@
/* Fork a child attached to a pseudo-terminal descriptor. /* Fork a child process attached to the slave of a pseudo-terminal.
Copyright (C) 2010 Free Software Foundation, Inc. Copyright (C) 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@@ -19,7 +19,9 @@
/* Specification. */ /* Specification. */
#include <pty.h> #include <pty.h>
#if HAVE_DECL_FORKPTY #if HAVE_FORKPTY
/* Provider a wrapper with the precise POSIX prototype. */
# undef forkpty # undef forkpty
int int
rpl_forkpty (int *amaster, char *name, struct termios const *termp, rpl_forkpty (int *amaster, char *name, struct termios const *termp,
@@ -29,7 +31,43 @@ rpl_forkpty (int *amaster, char *name, struct termios const *termp,
return forkpty (amaster, name, (struct termios *) termp, return forkpty (amaster, name, (struct termios *) termp,
(struct winsize *) winp); (struct winsize *) winp);
} }
#else
# error forkpty has not been ported to your system; \ #else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw */
report this to bug-gnulib@gnu.org for help
# include <pty.h>
# include <unistd.h>
extern int login_tty (int slave_fd);
int
forkpty (int *amaster, char *name,
const struct termios *termp, const struct winsize *winp)
{
int master, slave, pid;
if (openpty (&master, &slave, name, termp, winp) == -1)
return -1;
switch (pid = fork ())
{
case -1:
close (master);
close (slave);
return -1;
case 0:
/* Child. */
close (master);
if (login_tty (slave))
_exit (1);
return 0;
default:
/* Parent. */
*amaster = master;
close (slave);
return pid;
}
}
#endif #endif

View File

@@ -48,21 +48,30 @@
/* Declare overridden functions. */ /* Declare overridden functions. */
#if @GNULIB_FORKPTY@ #if @GNULIB_FORKPTY@
/* Create pseudo tty master slave pair and set terminal attributes
according to TERMP and WINP. Fork a child process attached to the
slave end. Return a handle for the master end in *AMASTER, and
return the name of the slave end in NAME. */
# if @REPLACE_FORKPTY@ # if @REPLACE_FORKPTY@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef forkpty # undef forkpty
# define forkpty rpl_forkpty # define forkpty rpl_forkpty
# endif # endif
_GL_FUNCDECL_RPL (forkpty, int, _GL_FUNCDECL_RPL (forkpty, int,
(int *, char *, struct termios const *, (int *amaster, char *name,
struct winsize const *)); struct termios const *termp, struct winsize const *winp));
_GL_CXXALIAS_RPL (forkpty, int, _GL_CXXALIAS_RPL (forkpty, int,
(int *, char *, struct termios const *, (int *amaster, char *name,
struct winsize const *)); struct termios const *termp, struct winsize const *winp));
# else # else
# if !@HAVE_FORKPTY@
_GL_FUNCDECL_SYS (forkpty, int,
(int *amaster, char *name,
struct termios const *termp, struct winsize const *winp));
# endif
_GL_CXXALIAS_SYS (forkpty, int, _GL_CXXALIAS_SYS (forkpty, int,
(int *, char *, struct termios const *, (int *amaster, char *name,
struct winsize const *)); struct termios const *termp, struct winsize const *winp));
# endif # endif
_GL_CXXALIASWARN (forkpty); _GL_CXXALIASWARN (forkpty);
#elif defined GNULIB_POSIXCHECK #elif defined GNULIB_POSIXCHECK

View File

@@ -1,4 +1,4 @@
# pty.m4 serial 4 # pty.m4 serial 5
dnl Copyright (C) 2010 Free Software Foundation, Inc. dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
@@ -25,6 +25,8 @@ AC_DEFUN([gl_FORKPTY],
AC_REQUIRE([gl_PTY_LIB]) AC_REQUIRE([gl_PTY_LIB])
AC_REQUIRE([gl_PTY_H]) AC_REQUIRE([gl_PTY_H])
dnl We assume that forkpty exists (possibly in libc, possibly in libutil)
dnl if and only if it is declared.
AC_CHECK_DECLS([forkpty],,, [[ AC_CHECK_DECLS([forkpty],,, [[
#if HAVE_PTY_H #if HAVE_PTY_H
# include <pty.h> # include <pty.h>
@@ -36,15 +38,13 @@ AC_DEFUN([gl_FORKPTY],
# include <libutil.h> # include <libutil.h>
#endif #endif
]]) ]])
if test $ac_cv_have_decl_forkpty = no; then if test $ac_cv_have_decl_forkpty = yes; then
AC_MSG_WARN([[Cannot find forkpty, build will likely fail]]) dnl The system has forkpty.
fi dnl Prefer glibc's const-safe prototype, if available.
AC_CACHE_CHECK([for const-safe forkpty signature],
dnl Prefer glibc's const-safe prototype, if available. [gl_cv_func_forkpty_const],
AC_CACHE_CHECK([for const-safe forkpty signature], [AC_COMPILE_IFELSE(
[gl_cv_func_forkpty_const], [AC_LANG_PROGRAM([[
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#if HAVE_PTY_H #if HAVE_PTY_H
# include <pty.h> # include <pty.h>
#endif #endif
@@ -54,13 +54,20 @@ AC_DEFUN([gl_FORKPTY],
#if HAVE_LIBUTIL_H #if HAVE_LIBUTIL_H
# include <libutil.h> # include <libutil.h>
#endif #endif
]], [[ ]], [[
int forkpty (int *, char *, struct termios const *, int forkpty (int *, char *, struct termios const *,
struct winsize const *); struct winsize const *);
]])], ]])
[gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])]) ],
if test $gl_cv_func_forkpty_const != yes; then [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])
REPLACE_FORKPTY=1 ])
if test $gl_cv_func_forkpty_const != yes; then
REPLACE_FORKPTY=1
AC_LIBOBJ([forkpty])
fi
else
dnl The system does not have forkpty.
HAVE_FORKPTY=0
AC_LIBOBJ([forkpty]) AC_LIBOBJ([forkpty])
fi fi
]) ])

View File

@@ -1,4 +1,4 @@
# pty_h.m4 serial 7 # pty_h.m4 serial 8
dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc. dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
@@ -60,6 +60,7 @@ AC_DEFUN([gl_PTY_H_DEFAULTS],
dnl Assume proper GNU behavior unless another module says otherwise. dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_UTIL_H=0; AC_SUBST([HAVE_UTIL_H]) HAVE_UTIL_H=0; AC_SUBST([HAVE_UTIL_H])
HAVE_LIBUTIL_H=0; AC_SUBST([HAVE_LIBUTIL_H]) HAVE_LIBUTIL_H=0; AC_SUBST([HAVE_LIBUTIL_H])
HAVE_FORKPTY=1; AC_SUBST([HAVE_FORKPTY])
HAVE_OPENPTY=1; AC_SUBST([HAVE_OPENPTY]) HAVE_OPENPTY=1; AC_SUBST([HAVE_OPENPTY])
REPLACE_FORKPTY=0; AC_SUBST([REPLACE_FORKPTY]) REPLACE_FORKPTY=0; AC_SUBST([REPLACE_FORKPTY])
REPLACE_OPENPTY=0; AC_SUBST([REPLACE_OPENPTY]) REPLACE_OPENPTY=0; AC_SUBST([REPLACE_OPENPTY])

View File

@@ -1,5 +1,6 @@
Description: Description:
Provide the forkpty() function. forkpty() function: Open a pseudo-terminal, fork, and connect the child process
to the pseudo-terminal's slave.
Files: Files:
lib/forkpty.c lib/forkpty.c
@@ -7,6 +8,8 @@ m4/pty.m4
Depends-on: Depends-on:
pty pty
openpty
login_tty
configure.ac: configure.ac:
gl_FORKPTY gl_FORKPTY

View File

@@ -29,6 +29,7 @@ pty.h: pty.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_OPENPTY''@|$(GNULIB_OPENPTY)|g' \ -e 's|@''GNULIB_OPENPTY''@|$(GNULIB_OPENPTY)|g' \
-e 's|@''HAVE_UTIL_H''@|$(HAVE_UTIL_H)|g' \ -e 's|@''HAVE_UTIL_H''@|$(HAVE_UTIL_H)|g' \
-e 's|@''HAVE_LIBUTIL_H''@|$(HAVE_LIBUTIL_H)|g' \ -e 's|@''HAVE_LIBUTIL_H''@|$(HAVE_LIBUTIL_H)|g' \
-e 's|@''HAVE_FORKPTY''@|$(HAVE_FORKPTY)|g' \
-e 's|@''HAVE_OPENPTY''@|$(HAVE_OPENPTY)|g' \ -e 's|@''HAVE_OPENPTY''@|$(HAVE_OPENPTY)|g' \
-e 's|@''REPLACE_FORKPTY''@|$(REPLACE_FORKPTY)|g' \ -e 's|@''REPLACE_FORKPTY''@|$(REPLACE_FORKPTY)|g' \
-e 's|@''REPLACE_OPENPTY''@|$(REPLACE_OPENPTY)|g' \ -e 's|@''REPLACE_OPENPTY''@|$(REPLACE_OPENPTY)|g' \