>>>> "Jan" == Jan Vroonhof
<vroonhof(a)math.ethz.ch> writes:
Jan> nbecker(a)fred.net writes:
> I've been using this patch for unix98 ptys. Would you guys
like to
> include this? Do you think it needs to be modified before it will be
> accepted?
Jan> I think the test probably should autoconf based, but currently all the
Jan> others don't seem to do that either. Maybe Martin can give his view.
Jan is right.
> else
> glibc should emulate with old pty behaviour
> // or so I'm told
Jan> Yes. However, wasn't there a security problem with that emulation? Has
Jan> that bin fixed in newer glibc's?
> *** process.h 1998/04/11 05:37:05 1.8
> --- process.h 1999/09/20 13:29:18
> ***************
> *** 134,137 ****
> --- 134,149 ----
>
> #endif /* emacs */
>
> + #if defined (__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__
>= 1)
> + # define HAVE_GETPT
> + #endif
Jan> If not autoconf bases then this should be in the s&m files, not in a
Jan> general include file.
Here's a completely untested patch that should do a much better job of
defining HAVE_GETPT
nbecker: Please apply this patch, run autoconf, fix up the rest of
your pty98 code in accordance with this, and then resubmit your patch.
Wouldn't it also be worthwhile to add configure tests for grantpt(),
unlockpt() and ptsname()? If you do, however, make sure we don't do
pointless tests for unlockpt() if, for example, grantpt() was not found.
Why are your calling ptsname_r() instead of ptsname()? ptsname_r() is
non-standard and only useful in a threaded program.
From the glibc manual:
Allocating Pseudo-Terminals
---------------------------
This subsection describes functions for allocating a pseudo-terminal,
and for making this pseudo-terminal available for actual use. These
functions are declared in the header file `stdlib.h'.
- Function: int getpt (void)
The `getpt' function returns a new file descriptor for the next
available master pseudo-terminal. The normal return value from
`getpt' is a non-negative integer file descriptor. In the case of
an error, a value of -1 is returned instead. The following
`errno' conditions are defined for this function:
`ENOENT'
There are no free master pseudo-terminals available.
This function is a GNU extension.
- Function: int grantpt (int FILEDES)
The `grantpt' function changes the ownership and access permission
of the slave pseudo-terminal device corresponding to the master
pseudo-terminal device associated with the file descriptor
FILEDES. The owner is set from the real user ID of the calling
process (*note Process Persona::.), and the group is set to a
special group (typically "tty") or from the real group ID of the
calling process. The access permission is set such that the file
is both readable and writable by the owner and only writable by
the group.
On some systems this function is implemented by invoking a special
`setuid' root program (*note How Change Persona::.). As a
consequence, installing a signal handler for the `SIGCHLD' signal
(*note Job Control Signals::.) may interfere with a call to
`grantpt'.
The normal return value from `grantpt' is 0; a value of -1 is
returned in case of failure. The following `errno' error
conditions are defined for this function:
`EBADF'
The FILEDES argument is not a valid file descriptor.
`ENINVAL'
The FILEDES argument is not associated with a master
pseudo-terminal device.
`EACCESS'
The slave pseudo-terminal device corresponding to the master
associated with FILEDES could not be accessed.
- Function: int unlockpt (int FILEDES)
The `unlockpt' function unlocks the slave pseudo-terminal device
corresponding to the master pseudo-terminal device associated with
the file descriptor FILEDES. On many systems, the slave can only
be opened after unlocking, so portable applications should always
call `unlockpt' before trying to open the slave.
The normal return value from `unlockpt' is 0; a value of -1 is
returned in case of failure. The following `errno' error
conditions are defined for this function:
`EBADF'
The FILEDES argument is not a valid file descriptor.
`EINVAL'
The FILEDES argument is not associated with a master
pseudo-terminal device.
- Function: char * ptsname (int FILEDES)
If the file descriptor FILEDES is associated with a master
pseudo-terminal device, the `ptsname' function returns a pointer
to a statically-allocated, null-terminated string containing the
file name of the associated slave pseudo-terminal file. This
string might be overwritten by subsequent calls to `ptsname'.
- Function: int ptsname_r (int FILEDES, char *BUF, size_t LEN)
The `ptsname_r' function is similar to the `ptsname' function
except that it places its result into the user-specified buffer
starting at BUF with length LEN.
This function is a GNU extension.
*Portability Note:* On System V derived systems, the file returned
by the `ptsname' and `ptsname_r' functions may be STREAMS-based, and
therefore require additional processing after opening before it
actually behaves as a pseudo terminal.
Typical usage of these functions is illustrated by the following
example:
int
open_pty_pair (int *amaster, int *aslave)
{
int master, slave;
char *name
master = getpt ();
if (master < 0)
return 0;
if (grantpt (master) < 0 || unlockpt (master) < 0)
goto close_master;
name = ptsname (master);
if (name == NULL)
goto close_master;
slave = open (name, O_RDWR);
if (slave == -1)
goto close_master;
if (isastream (slave))
{
if (ioctl (slave, I_PUSH, "ptem") < 0
|| ioctl (slave, I_PUSH, "ldterm") < 0)
goto close_slave;
}
*amaster = master;
*aslave = slave;
return 1;
close_slave:
close (slave);
close_master:
close (master);
return 0;
}
Index: configure.in
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/configure.in,v
retrieving revision 1.111.2.43
diff -u -r1.111.2.43 configure.in
--- configure.in 1999/09/16 20:18:45 1.111.2.43
+++ configure.in 1999/09/21 07:00:07
@@ -3118,7 +3118,7 @@
XE_COMPUTE_RUNPATH()
fi
-AC_CHECK_FUNCS(cbrt closedir dup2 eaccess fmod fpathconf frexp ftime gethostname
getpagesize gettimeofday getcwd getwd logb lrand48 matherr mkdir mktime perror poll random
rename res_init rint rmdir select setitimer setpgid setlocale setsid sigblock sighold
sigprocmask snprintf strcasecmp strerror tzset ulimit usleep utimes waitpid vsnprintf)
+AC_CHECK_FUNCS(cbrt closedir dup2 eaccess fmod fpathconf frexp ftime gethostname
getpagesize gettimeofday getcwd getpt getwd logb lrand48 matherr mkdir mktime perror poll
random rename res_init rint rmdir select setitimer setpgid setlocale setsid sigblock
sighold sigprocmask snprintf stpcpy strcasecmp strerror tzset ulimit usleep utimes waitpid
vsnprintf)
dnl realpath is buggy on linux, decosf and aix4
Index: src/config.h.in
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/config.h.in,v
retrieving revision 1.49.2.12
diff -u -r1.49.2.12 config.h.in
--- config.h.in 1999/08/27 03:46:43 1.49.2.12
+++ config.h.in 1999/09/21 07:00:11
@@ -272,6 +272,7 @@
#undef HAVE_GETTIMEOFDAY
#undef HAVE_GETWD
#undef HAVE_GETCWD
+#undef HAVE_GETPT
#undef HAVE_LOGB
#undef HAVE_LRAND48
#undef HAVE_MATHERR
@@ -294,6 +295,7 @@
#undef HAVE_SIGPROCMASK
#undef HAVE_SIGSETJMP
#undef HAVE_SNPRINTF
+#undef HAVE_STPCPY
#undef HAVE_STRCASECMP
#undef HAVE_STRERROR
#undef HAVE_TZSET