summaryrefslogtreecommitdiffstats
path: root/misc-utils/script.c
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:37 +0100
committerKarel Zak2006-12-07 00:25:37 +0100
commit5c36a0eb7cdb0360f9afd5d747c321f423b35984 (patch)
tree147599a77eaff2b5fbc0d389e89d2b51602326c0 /misc-utils/script.c
parentImported from util-linux-2.8 tarball. (diff)
downloadkernel-qcow2-util-linux-5c36a0eb7cdb0360f9afd5d747c321f423b35984.tar.gz
kernel-qcow2-util-linux-5c36a0eb7cdb0360f9afd5d747c321f423b35984.tar.xz
kernel-qcow2-util-linux-5c36a0eb7cdb0360f9afd5d747c321f423b35984.zip
Imported from util-linux-2.9i tarball.
Diffstat (limited to 'misc-utils/script.c')
-rw-r--r--misc-utils/script.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/misc-utils/script.c b/misc-utils/script.c
index af4013d30..23c48ea6b 100644
--- a/misc-utils/script.c
+++ b/misc-utils/script.c
@@ -49,6 +49,10 @@
#include <string.h>
#endif
+#ifdef HAVE_OPENPTY
+#include <pty.h>
+#endif
+
void done(void);
void fail(void);
void fixtty(void);
@@ -70,10 +74,12 @@ struct termios tt;
struct winsize win;
int lb;
int l;
+#ifndef HAVE_OPENPTY
char line[] = "/dev/ptyXX";
+#endif
int aflg;
-void
+int
main(argc, argv)
int argc;
char *argv[];
@@ -131,6 +137,8 @@ main(argc, argv)
doshell();
}
doinput();
+
+ return 0;
}
void
@@ -140,6 +148,9 @@ doinput()
char ibuf[BUFSIZ];
(void) fclose(fscript);
+#ifdef HAVE_OPENPTY
+ (void) close(slave);
+#endif
while ((cc = read(0, ibuf, BUFSIZ)) > 0)
(void) write(master, ibuf, cc);
done();
@@ -170,6 +181,9 @@ dooutput()
char obuf[BUFSIZ], *ctime();
(void) close(0);
+#ifdef HAVE_OPENPTY
+ (void) close(slave);
+#endif
tvec = time((time_t *)NULL);
fprintf(fscript, "Script started on %s", ctime(&tvec));
for (;;) {
@@ -250,6 +264,14 @@ done()
void
getmaster()
{
+#ifdef HAVE_OPENPTY
+ (void) tcgetattr(0, &tt);
+ (void) ioctl(0, TIOCGWINSZ, (char *)&win);
+ if (openpty(&master, &slave, NULL, &tt, &win) < 0) {
+ fprintf(stderr, "openpty failed\n");
+ fail();
+ }
+#else
char *pty, *bank, *cp;
struct stat stb;
@@ -282,12 +304,13 @@ getmaster()
}
fprintf(stderr, "Out of pty's\n");
fail();
+#endif /* not HAVE_OPENPTY */
}
void
getslave()
{
-
+#ifndef HAVE_OPENPTY
line[strlen("/dev/")] = 't';
slave = open(line, O_RDWR);
if (slave < 0) {
@@ -296,6 +319,7 @@ getslave()
}
(void) tcsetattr(slave, TCSAFLUSH, &tt);
(void) ioctl(slave, TIOCSWINSZ, (char *)&win);
+#endif
(void) setsid();
(void) ioctl(slave, TIOCSCTTY, 0);
}