Please see my other emails on this subject.
If you're going to fix this (and it's on my very long todo list),
let's do it right. The grantpt, unlockpt, etc. should be in the code
for OPENing the pty, not the code for printing it!
We'll have to fix similar code in s/hpux.h and probably elsewhere.
Consider throwing most of the current code away and starting fresh
with Expect's pty_termios.c, or some other source of excellent
pty-handling code.
Martin
>>>> "AJ" == Andreas Jaeger <aj(a)suse.de>
writes:
AJ> Compiling on Linux/i686 I get these warnings:
AJ> In file included from /usr/src/cvs/release-21-2/src/callproc.c:31:
AJ> /usr/src/cvs/release-21-2/src/process.h:143: warning: `PTY_ITERATION'
redefined
AJ> s/linux.h:216: warning: this is the location of the previous definition
AJ> /usr/src/cvs/release-21-2/src/process.h:146: warning: `PTY_OPEN' redefined
AJ> s/linux.h:228: warning: this is the location of the previous definition
AJ> /usr/src/cvs/release-21-2/src/process.h:148: warning: `PTY_TTY_NAME_SPRINTF'
redefined
AJ> s/linux.h:253: warning: this is the location of the previous definition
AJ> process.h has:
AJ> #ifdef HAVE_GETPT
AJ> #define PTY_ITERATION
AJ> #define PTY_OPEN \
AJ> if ((fd = getpt()) < 0 || grantpt (fd) < 0 || unlockpt (fd) < 0) \
AJ> return -1;
AJ> #define PTY_NAME_SPRINTF
AJ> #define PTY_TTY_NAME_SPRINTF strcpy (pty_name, ptsname (fd));
AJ> #endif
AJ> Compare this with linux.h:
AJ> #define PTY_ITERATION for (i = 0; i < 1; i++)
AJ> /* no iteration at all */
AJ> #define PTY_OPEN \
AJ> do { \
AJ> fd = getpt(); \
AJ> if (fcntl (fd, F_SETFL, O_NDELAY) == -1) \
AJ> fatal ("could not set master PTY to non-block mode"); \
AJ> } while (0)
AJ> #define PTY_TTY_NAME_SPRINTF \
AJ> { \
AJ> char *ptsname(), *ptyname; \
AJ> \
AJ> EMACS_BLOCK_SIGNAL (SIGCHLD); \
AJ> if (grantpt(fd) == -1) \
AJ> fatal("could not grant slave pty"); \
AJ> if (unlockpt(fd) == -1) \
AJ> fatal("could not unlock slave pty"); \
AJ> if (!(ptyname = ptsname(fd))) \
AJ> fatal ("could not enable slave pty"); \
AJ> strncpy(pty_name, ptyname, sizeof(pty_name)); \
AJ> pty_name[sizeof(pty_name) - 1] = 0; \
AJ> EMACS_UNBLOCK_SIGNAL (SIGCHLD); \
AJ> }
AJ> IMO we should unify this. Could some folks please try the appended
AJ> patch? It works for me on Linux 2.4.0.../glibc 2.1.3/i686 but I'd
AJ> like to give it some more testing before it gets applied.
AJ> Andreas
AJ> 2000-09-20 Andreas Jaeger <aj(a)suse.de>
AJ> * src/s/linux.h: Move PTY handling to process.h
AJ> * src/process.h: Unify PTY handling with version from s/linux.h.
AJ> Index: src/process.h
AJ> ===================================================================
AJ> RCS file: /usr/CVSroot/XEmacs/xemacs/src/process.h,v
AJ> retrieving revision 1.8.2.10
AJ> diff -u -r1.8.2.10 process.h
AJ> --- src/process.h 2000/06/12 04:18:21 1.8.2.10
AJ> +++ src/process.h 2000/09/20 08:00:01
AJ> @@ -139,13 +139,43 @@
AJ> #endif /* emacs */
AJ> -#ifdef HAVE_GETPT
AJ> +#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT) &&
defined(HAVE_PTSNAME)
AJ> +/* No iteration at all: */
AJ> #define PTY_ITERATION
AJ> -#define PTY_OPEN \
AJ> - if ((fd = getpt()) < 0 || grantpt (fd) < 0 || unlockpt (fd) < 0) \
AJ> - return -1;
AJ> +
AJ> +#ifdef HAVE_GETPT
AJ> +/* Use getpt() if it's available. */
AJ> +
AJ> +#define PTY_OPEN \
AJ> + do { \
AJ> + fd = getpt(); \
AJ> + if (fcntl (fd, F_SETFL, O_NDELAY) == -1) \
AJ> + fatal ("could not set master PTY to non-block mode"); \
AJ> + } while (0)
AJ> +
AJ> #define PTY_NAME_SPRINTF
AJ> -#define PTY_TTY_NAME_SPRINTF strcpy (pty_name, ptsname (fd));
AJ> +
AJ> +#else
AJ> +/* the master PTY device */
AJ> +#define PTY_NAME_SPRINTF strcpy (pty_name, "/dev/ptmx");
AJ> +#endif
AJ> +
AJ> +#define PTY_TTY_NAME_SPRINTF \
AJ> + { \
AJ> + char *ptsname(), *ptyname; \
AJ> + \
AJ> + EMACS_BLOCK_SIGNAL (SIGCHLD); \
AJ> + if (grantpt(fd) == -1) \
AJ> + fatal("could not grant slave pty"); \
AJ> + if (unlockpt(fd) == -1) \
AJ> + fatal("could not unlock slave pty"); \
AJ> + if (!(ptyname = ptsname(fd))) \
AJ> + fatal ("could not enable slave pty"); \
AJ> + strncpy(pty_name, ptyname, sizeof(pty_name)); \
AJ> + pty_name[sizeof(pty_name) - 1] = 0; \
AJ> + EMACS_UNBLOCK_SIGNAL (SIGCHLD); \
AJ> + }
AJ> +
AJ> #endif
AJ> #endif /* INCLUDED_process_h_ */
AJ> Index: src/s/linux.h
AJ> ===================================================================
AJ> RCS file: /usr/CVSroot/XEmacs/xemacs/src/s/linux.h,v
AJ> retrieving revision 1.11.2.4
AJ> diff -u -r1.11.2.4 linux.h
AJ> --- src/s/linux.h 2000/09/14 06:31:09 1.11.2.4
AJ> +++ src/s/linux.h 2000/09/20 08:00:01
AJ> @@ -208,48 +208,3 @@
AJ> /* XEmacs: removed setpgrp() definition because we use setpgid() when
AJ> it's available, and autodetect it. */
AJ> -#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT) &&
defined(HAVE_PTSNAME)
AJ> -/* UNIX98 PTYs are available.
AJ> - Added by Florian Weimer <Florian.Weimer(a)RUS.Uni-Stuttgart.DE>,
AJ> - RUS-CERT, University of Stuttgart. Based on Emacs code for DGUX. */
AJ> -
AJ> -#define PTY_ITERATION for (i = 0; i < 1; i++)
AJ> -/* no iteration at all */
AJ> -
AJ> -/* Use getpt() if it's available, because it provides Unix98 PTY
AJ> - emulation for kernels which doesn't support it natively. */
AJ> -
AJ> -#ifdef HAVE_GETPT
AJ> -#define PTY_OPEN \
AJ> - do { \
AJ> - fd = getpt(); \
AJ> - if (fcntl (fd, F_SETFL, O_NDELAY) == -1) \
AJ> - fatal ("could not set master PTY to non-block mode"); \
AJ> - } while (0)
AJ> -
AJ> -#else
AJ> -/* the master PTY device */
AJ> -#define PTY_NAME_SPRINTF strcpy (pty_name, "/dev/ptmx");
AJ> -#endif
AJ> -
AJ> -/* This sets the name of the slave side of the PTY. grantpt(3) and
AJ> - unlockpt(3) may fork a subprocess, so keep sigchld_handler() from
AJ> - intercepting that death. */
AJ> -
AJ> -#define PTY_TTY_NAME_SPRINTF \
AJ> - { \
AJ> - char *ptsname(), *ptyname; \
AJ> - \
AJ> - EMACS_BLOCK_SIGNAL (SIGCHLD); \
AJ> - if (grantpt(fd) == -1) \
AJ> - fatal("could not grant slave pty"); \
AJ> - if (unlockpt(fd) == -1) \
AJ> - fatal("could not unlock slave pty"); \
AJ> - if (!(ptyname = ptsname(fd))) \
AJ> - fatal ("could not enable slave pty"); \
AJ> - strncpy(pty_name, ptyname, sizeof(pty_name)); \
AJ> - pty_name[sizeof(pty_name) - 1] = 0; \
AJ> - EMACS_UNBLOCK_SIGNAL (SIGCHLD); \
AJ> - }
AJ> -
AJ> -#endif