If I build the latest XEmacs on Linux with getpt(), I get these warnings:
/project/xemacs/ws/ia64/src/process.h:143: warning: `PTY_ITERATION' redefined
s/linux.h:216: warning: this is the location of the previous definition
/project/xemacs/ws/ia64/src/process.h:146: warning: `PTY_OPEN' redefined
s/linux.h:228: warning: this is the location of the previous definition
/project/xemacs/ws/ia64/src/process.h:148: warning: `PTY_TTY_NAME_SPRINTF' redefined
Inspection shows that we have similar code in
src/process.h:
#ifdef HAVE_GETPT
#define PTY_ITERATION
#define PTY_OPEN \
if ((fd = getpt()) < 0 || grantpt (fd) < 0 || unlockpt (fd) < 0) \
return -1;
#define PTY_NAME_SPRINTF
#define PTY_TTY_NAME_SPRINTF strcpy (pty_name, ptsname (fd));
#endif
and src/s/linux.h:
#ifdef HAVE_GETPT
#define PTY_OPEN \
do { \
fd = getpt(); \
if (fcntl (fd, F_SETFL, O_NDELAY) == -1) \
fatal ("could not set master PTY to non-block mode"); \
} while (0)
#else
/* the master PTY device */
#define PTY_NAME_SPRINTF strcpy (pty_name, "/dev/ptmx");
#endif
/* This sets the name of the slave side of the PTY. grantpt(3) and
unlockpt(3) may fork a subprocess, so keep sigchld_handler() from
intercepting that death. */
#define PTY_TTY_NAME_SPRINTF \
{ \
char *ptsname(), *ptyname; \
\
sigblock(sigmask(SIGCHLD)); \
if (grantpt(fd) == -1) \
fatal("could not grant slave pty"); \
if (unlockpt(fd) == -1) \
fatal("could not unlock slave pty"); \
if (!(ptyname = ptsname(fd))) \
fatal ("could not enable slave pty"); \
strncpy(pty_name, ptyname, sizeof(pty_name)); \
pty_name[sizeof(pty_name) - 1] = 0; \
sigsetmask(siggetmask() & ~sigmask(SIGCHLD)); \
}
I see various bugs and buglets:
- before redefining macros like PTY_ITERATION, you need to #undef them
first.
- ptsname doesn't have a full prototype. Actually, we shouldn't have
system functions declared in XEmacs source files anyways.
- the functions grantpt() and unlockpt() are logically part of
PTY_OPEN, not PTY_TTY_NAME_SPRINTF.
What exactly were the bugs that this external patch was supposed to
fix?
Actually, this is the sort of thing I've maintained in the past. My
approach would be to grok the pty_termios.c file and import its wisdom
into XEmacs.
For amusement, here is some code from pty_termios.c:
} else if (grantpt(master)) {
static char buf[500];
exp_pty_error = buf;
sprintf(exp_pty_error,"grantpt(%s) failed - likely reason is that your system
administrator (in a rage of blind passion to rid the system of security holes) removed
setuid from the utility used internally by grantpt to change pty permissions. Tell your
system admin to reestablish setuid on the utility. Get the utility name by running Expect
under truss or trace.", expErrnoMsg(errno));
close(master);
return(-1);
}
However, be careful. Expect is a full-time hobby for Don Libes, and
fixing the pty code in XEmacs may become a similar full-time hobby.
Martin