1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-14 07:30:21 +00:00

Merge pull request #163 from waywardmonkeys/use-posix-pseudoterminals

Switch to using POSIX pseudoterminals.
This commit is contained in:
Larry Masinter 2021-01-01 23:30:30 -08:00 committed by GitHub
commit 33a67a80e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 71 deletions

View File

@ -1,7 +1,2 @@
int fork_Unix(void);
#ifdef FULLSLAVENAME
int ForkUnixShell(int slot, char *PtySlave, char *termtype, char *shellarg);
#else
int ForkUnixShell(int slot, char ltr, char numb, char *termtype, char *shellarg);
#endif

View File

@ -20,12 +20,6 @@ Unix Interface Communications
#include "lispemul.h"
/* FULLSLAVENAME => use a full file name for slave PTY */
#ifdef OS5
#define FULLSLAVENAME
#endif /* OS5 */
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h> /* JRB - timeout.h needs setjmp.h */
@ -39,15 +33,8 @@ Unix Interface Communications
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
#include <termios.h>
#ifdef sun
/* to get S_IFIFO defn for creating fifos */
#include <sys/stat.h>
#endif /* sun */
#include <unistd.h>
#include "address.h"
#include "adr68k.h"
@ -290,58 +277,31 @@ int FindUnixPipes(void) {
/* F i n d A v a i l a b l e P t y */
/* */
/* Given strings Master and Slave, fill them with path names */
/* of the forms: */
/* to the master and slave psuedoterminals. */
/* */
/* Master: /dev/ptyxx */
/* Slave: /dev/ttyxx */
/* */
/* Which are the first available pty/tty pair for communicating */
/* with a forked shell. */
/* */
/* Assumes that valid PTY names are [pqr][0-f]; if your system */
/* is different, you'll need to change it. */
/* This uses POSIX pseudoterminals. */
/* */
/************************************************************************/
#define PTYLETTERS "pqr"
#define PTYNUMBERS "0123456789abcdef"
/* Find the first PTY pair that is not in use */
int FindAvailablePty(char *Master, char *Slave) {
int res;
char *let, *num;
#ifdef OS5
res = open("/dev/ptmx", O_RDWR);
res = posix_openpt(O_RDWR);
if (res < 0) {
perror("ptmx open");
perror("open_pt failed");
return (-1);
}
grantpt(res);
unlockpt(res);
strcpy(Slave, ptsname(res));
DBPRINT(("slave pty name is %s.\n", Slave));
#else
/* From p to r */
for (let = PTYLETTERS; *let != 0; let++) /* and 0 to f */
for (num = PTYNUMBERS; *num != 0; num++) {
sprintf(Master, "/dev/pty%c%c", *let, *num);
sprintf(Slave, "%c%c", *let, *num);
DBPRINT(("Trying %s. ", Master));
/* Try to open the Master side */
res = open(Master, O_RDWR);
#endif
if (res != -1) {
fcntl(res, F_SETFL, fcntl(res, F_GETFL, 0) | O_NONBLOCK);
return (res);
}
#ifndef FULLSLAVENAME
}
#endif /* because we commented out the for above also... */
return (-1);
return (-1);
}
/************************************************************************/
@ -627,11 +587,9 @@ LispPTR Unix_handlecomm(LispPTR *args) {
d[3] = slot;
write(UnixPipeOut, d, 4);
#ifdef FULLSLAVENAME
len = strlen(SlavePTY) + 1;
write(UnixPipeOut, &len, 2);
write(UnixPipeOut, SlavePTY, len);
#endif
if (command != 4) { /* New style has arg1 = termtype, arg2 = command */
WriteLispStringToPipe(args[1]);

View File

@ -36,7 +36,6 @@
#ifdef OS5
#include <sys/stropts.h>
#define FULLSLAVENAME
#endif
#include "dbprint.h"
@ -81,15 +80,8 @@ loop:
/* Creates a PTY connection to a csh */
#ifdef FULLSLAVENAME
int ForkUnixShell(int slot, char *PtySlave, char *termtype, char *shellarg)
#else
int ForkUnixShell(int slot, char ltr, char numb, char *termtype, char *shellarg)
#endif
{
#ifndef FULLSLAVENAME
char PtySlave[20];
#endif
int res, PID, SlaveFD;
struct termios tio;
@ -103,9 +95,6 @@ int ForkUnixShell(int slot, char ltr, char numb, char *termtype, char *shellarg)
perror("setsid");
/* Open the slave side */
#ifndef FULLSLAVENAME
sprintf(PtySlave, "/dev/tty%c%c", ltr, numb);
#endif
SlaveFD = open(PtySlave, O_RDWR);
if (SlaveFD == -1) {
perror("Slave Open");
@ -304,12 +293,10 @@ int fork_Unix() {
case 'P': /* Fork PTY shell */
if (slot >= 0) { /* Found a free slot */
char termtype[32];
#ifdef FULLSLAVENAME
char slavepty[32]; /* For slave pty name */
if (SAFEREAD(LispPipeIn, (char *)&tmp, 2) < 0) perror("Slave reading slave pty len");
if (SAFEREAD(LispPipeIn, slavepty, tmp) < 0) perror("Slave reading slave pty id");
#endif /* FULLSLAVENAME */
if (IOBuf[0] == 'P') { /* The new style, which takes term type & command to csh */
if (SAFEREAD(LispPipeIn, (char *)&tmp, 2) < 0) perror("Slave reading cmd length");
@ -328,12 +315,8 @@ int fork_Unix() {
cmdstring[0] = 0;
}
/* Alloc a PTY and fork */
#ifdef FULLSLAVENAME
/* Alloc a PTY and fork */
pid = ForkUnixShell(slot, slavepty, termtype, cmdstring);
#else
pid = ForkUnixShell(slot, IOBuf[1], IOBuf[2], termtype, cmdstring);
#endif
if (pid == -1) {
printf("Impossible failure from ForkUnixShell??\n");