* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)script.c 5.5 (Berkeley) %G%";
char *line
= "/dev/ptyXX";
while ((ch
= getopt(argc
, argv
, "a")) != EOF
)
fprintf(stderr
, "usage: script [-a] [file]\n");
if ((fscript
= fopen(fname
, aflg
? "a" : "w")) == NULL
) {
printf("Script started, file is %s\n", fname
);
(void) signal(SIGCHLD
, finish
);
subchild
= child
= fork();
while ((cc
= read(0, ibuf
, BUFSIZ
)) > 0)
(void) write(master
, ibuf
, cc
);
while ((pid
= wait3(&status
, WNOHANG
, 0)) > 0)
char obuf
[BUFSIZ
], *ctime();
tvec
= time((time_t *)NULL
);
fprintf(fscript
, "Script started on %s", ctime(&tvec
));
cc
= read(master
, obuf
, sizeof (obuf
));
(void) write(1, obuf
, cc
);
(void) fwrite(obuf
, 1, cc
, fscript
);
t
= open("/dev/tty", O_RDWR
);
(void) ioctl(t
, TIOCNOTTY
, (char *)0);
execl(shell
, "sh", "-i", 0);
(void) ioctl(0, TIOCSETP
, (char *)&sbuf
);
tvec
= time((time_t *)NULL
);
fprintf(fscript
,"\nscript done on %s", ctime(&tvec
));
(void) ioctl(0, TIOCSETP
, (char *)&b
);
printf("Script done, file is %s\n", fname
);
pty
= &line
[strlen("/dev/ptyp")];
for (bank
= "pqrs"; *bank
; bank
++) {
line
[strlen("/dev/pty")] = *bank
;
if (stat(line
, &stb
) < 0)
for (cp
= "0123456789abcdef"; *cp
; cp
++) {
master
= open(line
, O_RDWR
);
char *tp
= &line
[strlen("/dev/")];
/* verify slave side is usable */
ok
= access(line
, R_OK
|W_OK
) == 0;
(void) ioctl(0, TIOCGETP
, (char *)&b
);
(void) ioctl(0, TIOCGETC
, (char *)&tc
);
(void) ioctl(0, TIOCGETD
, (char *)&l
);
(void) ioctl(0, TIOCGLTC
, (char *)&lc
);
(void) ioctl(0, TIOCLGET
, (char *)&lb
);
(void) ioctl(0, TIOCGWINSZ
, (char *)&win
);
fprintf(stderr
, "Out of pty's\n");
line
[strlen("/dev/")] = 't';
slave
= open(line
, O_RDWR
);
(void) ioctl(slave
, TIOCSETP
, (char *)&b
);
(void) ioctl(slave
, TIOCSETC
, (char *)&tc
);
(void) ioctl(slave
, TIOCSLTC
, (char *)&lc
);
(void) ioctl(slave
, TIOCLSET
, (char *)&lb
);
(void) ioctl(slave
, TIOCSETD
, (char *)&l
);
(void) ioctl(slave
, TIOCSWINSZ
, (char *)&win
);