From: Bruno Haible Date: Sun, 21 Mar 2010 19:16:38 +0000 (+0100) Subject: New module 'grantpt'. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeca137662d6d2a7eaade72667ace75322872254;p=pspp New module 'grantpt'. --- diff --git a/ChangeLog b/ChangeLog index a1db0b37c9..a5acf2faaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-03-21 Bruno Haible + + New module 'grantpt'. + * lib/grantpt.c: New file, from glibc with modifications. + * m4/grantpt.m4: New file. + * modules/grantpt: New file. + * lib/stdlib.in.h (grantpt): New declaration. + * m4/stdlib_h.m4 (gl_STDLIB_H): Check whether grantpt is declared. + (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_GRANTPT, HAVE_GRANTPT. + * modules/stdlib (Makefile.am): Substitute GNULIB_GRANTPT, + HAVE_GRANTPT. + * doc/posix-functions/grantpt.texi: Mention the new module. + * tests/test-stdlib-c++.cc: Check GNULIB_NAMESPACE::grantpt. + * config/srclist.txt: Add grantpt.c (commented). + 2010-03-21 Bruno Haible New module 'pt_chown'. diff --git a/config/srclist.txt b/config/srclist.txt index c7e41ef647..31e7a01baa 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -218,6 +218,7 @@ $LIBCSRC/stdlib/strtoul.c lib gpl #$LIBCSRC/sysdeps/unix/bsd/poll.c lib gpl #$LIBCSRC/sysdeps/unix/bsd/ptsname.c lib gpl #$LIBCSRC/sysdeps/unix/dirfd.c lib gpl +#$LIBCSRC/sysdeps/unix/grantpt.c lib gpl #$LIBCSRC/sysdeps/unix/rmdir.c lib gpl #$LIBCSRC/time/strftime.c lib gpl # These are close, but we are using the gettext versions. diff --git a/doc/posix-functions/grantpt.texi b/doc/posix-functions/grantpt.texi index ff2a706fd8..beaf9510a3 100644 --- a/doc/posix-functions/grantpt.texi +++ b/doc/posix-functions/grantpt.texi @@ -4,15 +4,15 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/grantpt.html} -Gnulib module: --- +Gnulib module: grantpt Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +MacOS X 10.3, OpenBSD 3.8, mingw, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -MacOS X 10.3, OpenBSD 3.8, mingw, BeOS. @end itemize diff --git a/lib/grantpt.c b/lib/grantpt.c new file mode 100644 index 0000000000..25bd0a6514 --- /dev/null +++ b/lib/grantpt.c @@ -0,0 +1,114 @@ +/* Acquire ownership of the slave side of a pseudo-terminal. + Copyright (C) 1998-2002, 2009-2010 Free Software Foundation, Inc. + Contributed by Zack Weinberg , 1998. + + 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 . */ + +#include + +#include + +#include +#include +#include +#include +#include + +#if HAVE_SETRLIMIT +# include +# include +# include +#endif + +#include "configmake.h" +#include "pty-private.h" + +#ifndef _LIBC +# define __builtin_expect(expr,val) (expr) +# define __set_errno(e) errno = (e) +# define __dup2 dup2 +# define __fork fork +# define __setrlimit setrlimit +# define __waitpid waitpid +#endif + +int +grantpt (int fd) +{ + /* This function is most often called from a process without 'root' + credentials. Use the helper program. */ + int retval = -1; + pid_t pid = __fork (); + if (pid == -1) + goto cleanup; + else if (pid == 0) + { + /* This is executed in the child process. */ + +#if HAVE_SETRLIMIT && defined RLIMIT_CORE + /* Disable core dumps. */ + struct rlimit rl = { 0, 0 }; + __setrlimit (RLIMIT_CORE, &rl); +#endif + + /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */ + if (fd != PTY_FILENO) + if (__dup2 (fd, PTY_FILENO) < 0) + _exit (FAIL_EBADF); + +#ifdef CLOSE_ALL_FDS + CLOSE_ALL_FDS (); +#endif + + execle (_PATH_PT_CHOWN, strrchr (_PATH_PT_CHOWN, '/') + 1, NULL, NULL); + _exit (FAIL_EXEC); + } + else + { + int w; + + if (__waitpid (pid, &w, 0) == -1) + goto cleanup; + if (!WIFEXITED (w)) + __set_errno (ENOEXEC); + else + switch (WEXITSTATUS (w)) + { + case 0: + retval = 0; + break; + case FAIL_EBADF: + __set_errno (EBADF); + break; + case FAIL_EINVAL: + __set_errno (EINVAL); + break; + case FAIL_EACCES: + __set_errno (EACCES); + break; + case FAIL_EXEC: + __set_errno (ENOEXEC); + break; + case FAIL_ENOMEM: + __set_errno (ENOMEM); + break; + + default: + assert(! "getpt: internal error: invalid exit code from pt_chown"); + } + } + + cleanup: + return retval; +} diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 60c10bd037..9f301815b8 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -201,6 +201,22 @@ _GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - " # endif #endif +#if @GNULIB_GRANTPT@ +/* Change the ownership and access permission of the slave side of the + pseudo-terminal whose master side is specified by FD. */ +# if !@HAVE_GRANTPT@ +_GL_FUNCDECL_SYS (grantpt, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (grantpt, int, (int fd)); +_GL_CXXALIASWARN (grantpt); +#elif defined GNULIB_POSIXCHECK +# undef grantpt +# if HAVE_RAW_DECL_GRANTPT +_GL_WARN_ON_USE (ptsname, "grantpt is not portable - " + "use gnulib module grantpt for portability"); +# endif +#endif + #if @GNULIB_MALLOC_POSIX@ # if !@HAVE_MALLOC_POSIX@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/grantpt.m4 b/m4/grantpt.m4 new file mode 100644 index 0000000000..d7f527198e --- /dev/null +++ b/m4/grantpt.m4 @@ -0,0 +1,25 @@ +# grantpt.m4 serial 1 +dnl Copyright (C) 2010 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. + +AC_DEFUN([gl_FUNC_GRANTPT], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc to declare grantpt(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS([grantpt]) + if test $ac_cv_func_grantpt = no; then + HAVE_GRANTPT=0 + AC_LIBOBJ([grantpt]) + gl_PREREQ_GRANTPT + fi +]) + +# Prerequisites of lib/grantpt.c. +AC_DEFUN([gl_PREREQ_GRANTPT], [ + AC_CHECK_FUNCS([setrlimit]) +]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 85efb6e7c1..7fe01b5809 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 24 +# stdlib_h.m4 serial 25 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -33,7 +33,7 @@ AC_DEFUN([gl_STDLIB_H], #if HAVE_RANDOM_H # include #endif - ]], [atoll canonicalize_file_name getloadavg getsubopt mkdtemp + ]], [atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r setstate_r realpath rpmatch setenv strtod strtoll strtoull unsetenv]) ]) @@ -54,6 +54,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME]) GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG]) GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) + GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT]) GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX]) GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP]) @@ -77,6 +78,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) + HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT]) HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX]) HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP]) diff --git a/modules/grantpt b/modules/grantpt new file mode 100644 index 0000000000..4a2e16809c --- /dev/null +++ b/modules/grantpt @@ -0,0 +1,27 @@ +Description: +grantpt() function: Acquire ownership of the slave side of a pseudo-terminal. + +Files: +lib/grantpt.c +m4/grantpt.m4 + +Depends-on: +stdlib +extensions +pt_chown +configmake + +configure.ac: +gl_FUNC_GRANTPT +gl_STDLIB_MODULE_INDICATOR([grantpt]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/stdlib b/modules/stdlib index 663fc72e59..567a80754f 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -33,6 +33,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \ -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ + -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \ -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \ @@ -55,6 +56,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ + -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ diff --git a/tests/test-stdlib-c++.cc b/tests/test-stdlib-c++.cc index d1e36aba16..f9ea7004e4 100644 --- a/tests/test-stdlib-c++.cc +++ b/tests/test-stdlib-c++.cc @@ -48,6 +48,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::getsubopt, int, (char **, char *const *, char **)); #endif +#if GNULIB_GRANTPT +SIGNATURE_CHECK (GNULIB_NAMESPACE::grantpt, int, (int)); +#endif + #if GNULIB_MALLOC_POSIX SIGNATURE_CHECK (GNULIB_NAMESPACE::malloc, void *, (size_t)); #endif