Print this page
14249 pseudo-terminal nomenclature should reflect POSIX
Change-Id: Ib4a3cef899ff4c71b09cb0dc6878863c5e8357bc
*** 40,56 ****
void dooutput();
void doshell();
void fixtty();
void fail();
void done() __NORETURN;
! void getmaster();
! void getslave();
char *shell;
FILE *fscript;
! int master; /* file descriptor for master pseudo-tty */
! int slave; /* file descriptor for slave pseudo-tty */
int child;
int subchild;
char *fname = "typescript";
void sigwinch();
void finish();
--- 40,56 ----
void dooutput();
void doshell();
void fixtty();
void fail();
void done() __NORETURN;
! void getmanager();
! void getsubsid();
char *shell;
FILE *fscript;
! int manager; /* file descriptor for manager pseudo-tty */
! int subsid; /* file descriptor for subsidiary pseudo-tty */
int child;
int subchild;
char *fname = "typescript";
void sigwinch();
void finish();
*** 57,67 ****
struct termios b;
struct winsize size;
int lb;
int l;
! char *mptname = "/dev/ptmx"; /* master pseudo-tty device */
int aflg;
int
main(int argc, char *argv[])
--- 57,67 ----
struct termios b;
struct winsize size;
int lb;
int l;
! char *mptname = "/dev/ptmx"; /* manager pseudo-tty device */
int aflg;
int
main(int argc, char *argv[])
*** 101,111 ****
perror(fname);
fail();
}
setbuf(fscript, NULL);
chown(fname, ruidt, gidt);
! getmaster();
printf(gettext("Script started, file is %s\n"), fname);
fixtty();
(void) signal(SIGCHLD, finish);
child = fork();
--- 101,111 ----
perror(fname);
fail();
}
setbuf(fscript, NULL);
chown(fname, ruidt, gidt);
! getmanager();
printf(gettext("Script started, file is %s\n"), fname);
fixtty();
(void) signal(SIGCHLD, finish);
child = fork();
*** 144,154 ****
continue;
} else {
break;
}
}
! (void) write(master, ibuf, cc);
}
done();
}
void
--- 144,154 ----
continue;
} else {
break;
}
}
! (void) write(manager, ibuf, cc);
}
done();
}
void
*** 155,165 ****
sigwinch()
{
struct winsize ws;
if (ioctl(0, TIOCGWINSZ, &ws) == 0)
! (void) ioctl(master, TIOCSWINSZ, &ws);
}
#include <sys/wait.h>
void
--- 155,165 ----
sigwinch()
{
struct winsize ws;
if (ioctl(0, TIOCGWINSZ, &ws) == 0)
! (void) ioctl(manager, TIOCSWINSZ, &ws);
}
#include <sys/wait.h>
void
*** 188,198 ****
(void) close(0);
tvec = time((time_t *)0);
strftime(tbuf, BUFSIZ, "%c", localtime(&tvec));
fprintf(fscript, gettext("Script started on %s\n"), tbuf);
for (;;) {
! cc = read(master, obuf, sizeof (obuf));
if (cc <= 0)
break;
(void) write(1, obuf, cc);
(void) fwrite(obuf, 1, cc, fscript);
}
--- 188,198 ----
(void) close(0);
tvec = time((time_t *)0);
strftime(tbuf, BUFSIZ, "%c", localtime(&tvec));
fprintf(fscript, gettext("Script started on %s\n"), tbuf);
for (;;) {
! cc = read(manager, obuf, sizeof (obuf));
if (cc <= 0)
break;
(void) write(1, obuf, cc);
(void) fwrite(obuf, 1, cc, fscript);
}
*** 202,218 ****
void
doshell()
{
setpgrp(); /* relinquish control terminal */
! getslave();
! (void) close(master);
(void) fclose(fscript);
! (void) dup2(slave, 0);
! (void) dup2(slave, 1);
! (void) dup2(slave, 2);
! (void) close(slave);
execl(shell, shell, "-i", (char *)0);
perror(shell);
fail();
}
--- 202,218 ----
void
doshell()
{
setpgrp(); /* relinquish control terminal */
! getsubsid();
! (void) close(manager);
(void) fclose(fscript);
! (void) dup2(subsid, 0);
! (void) dup2(subsid, 1);
! (void) dup2(subsid, 2);
! (void) close(subsid);
execl(shell, shell, "-i", (char *)0);
perror(shell);
fail();
}
*** 247,270 ****
if (subchild) {
tvec = time((time_t *)0);
strftime(tbuf, BUFSIZ, "%c", localtime(&tvec));
fprintf(fscript, gettext("\nscript done on %s\n"), tbuf);
(void) fclose(fscript);
! (void) close(master);
} else {
(void) ioctl(0, TCSETSW, (char *)&b);
printf(gettext("Script done, file is %s\n"), fname);
}
exit(0);
}
void
! getmaster()
{
struct stat stb;
! if ((master = open(mptname, O_RDWR)) >= 0) { /* a pseudo-tty is free */
(void) ioctl(0, TCGETS, (char *)&b);
(void) ioctl(0, TIOCGWINSZ, (char *)&size);
return;
} else { /* out of pseudo-tty's */
perror(mptname);
--- 247,270 ----
if (subchild) {
tvec = time((time_t *)0);
strftime(tbuf, BUFSIZ, "%c", localtime(&tvec));
fprintf(fscript, gettext("\nscript done on %s\n"), tbuf);
(void) fclose(fscript);
! (void) close(manager);
} else {
(void) ioctl(0, TCSETSW, (char *)&b);
printf(gettext("Script done, file is %s\n"), fname);
}
exit(0);
}
void
! getmanager()
{
struct stat stb;
! if ((manager = open(mptname, O_RDWR)) >= 0) { /* a pseudo-tty is free */
(void) ioctl(0, TCGETS, (char *)&b);
(void) ioctl(0, TIOCGWINSZ, (char *)&size);
return;
} else { /* out of pseudo-tty's */
perror(mptname);
*** 272,294 ****
fail();
}
}
void
! getslave()
{
! char *slavename; /* name of slave pseudo-tty */
! grantpt(master); /* change permissions of slave */
! unlockpt(master); /* unlock slave */
! slavename = ptsname(master); /* get name of slave */
! slave = open(slavename, O_RDWR); /* open slave */
! if (slave < 0) { /* error on opening slave */
! perror(slavename);
fail();
}
! ioctl(slave, I_PUSH, "ptem"); /* push pt hw emulation module */
! ioctl(slave, I_PUSH, "ldterm"); /* push line discipline */
! (void) ioctl(slave, TCSETSF, (char *)&b);
! (void) ioctl(slave, TIOCSWINSZ, (char *)&size);
}
--- 272,294 ----
fail();
}
}
void
! getsubsid()
{
! char *subsidname; /* name of subsidiary pseudo-tty */
! grantpt(manager); /* change permissions of subsidiary */
! unlockpt(manager); /* unlock subsidiary */
! subsidname = ptsname(manager); /* get name of subsidiary */
! subsid = open(subsidname, O_RDWR); /* open subsidiary */
! if (subsid < 0) { /* error opening subsidiary */
! perror(subsidname);
fail();
}
! ioctl(subsid, I_PUSH, "ptem"); /* push pt hw emulation module */
! ioctl(subsid, I_PUSH, "ldterm"); /* push line discipline */
! (void) ioctl(subsid, TCSETSF, (char *)&b);
! (void) ioctl(subsid, TIOCSWINSZ, (char *)&size);
}