Subject: alarm() does not work with tty read???
To: None <email@example.com>
From: Simon J. Gerraty <firstname.lastname@example.org>
Date: 12/07/1993 17:01:25
I'm "porting" mgetty+sendfax. sendfax works more or less ok.
mgetty gets stuck... it gets stuck because it tries to do a read from
a tty device with and
t->c_lflag &= ~ICANON;
t->c_cc[VMIN] = 0;
it should work, but the time out never happens.
I modified mgetty to simply use
and even with root sending SIGALRM's at the process it does not return
from the read.... so I hacked up the trivial prog at the end of this
post to test in isolation. I was going to check various reading
approaches, but the first one using alarm() as above, did not work so
I'm pretty sure we have a bug...
com.c just calls the line discipline's read entry, but I'm not too
sure the standard line discipline is implemented. kern/tty.c does not
look enough (no mention of VMIN etc - indeed it only appears in
arch/i386/isa/cy.c) and speaks of line disciplines as though they are
implemented elsewhere... any clues appreciated.
Anyway here is the test prog. You can call it with
./chat -l /dev/tty01 send expect ...
It always adds a "\r" for you (I said this was trivial).
int fd = -1;
struct termios tio;
if ((fd = open(name, O_RDWR)) >= 0)
/* hooks for later... */
volatile int timeout = 0;
tty_read(int fd, char *buf, int nbytes, int secs)
/* check that alarm() does work... */
c = -1;
c = read(fd, buf, nbytes);
wait_for(int fd, char *str)
printf("looking for '%s', got: ", str);
while ((c = tty_read(fd, buf, sizeof (buf) - 1, 5)) > 0)
buf[c] = '\0';
if (strstr(buf, str))
do_chat(int fd, char **args)
int i = 0;
for (i = 0; args[i]; i += 2)
printf("send: '%s'\n", args[i]);
write(fd, args[i], strlen(args[i]));
write(fd, "\r", 1);
wait_for(fd, args[i + 1]);
main(int argc, char **argv)
char *tty_dev = NULL;
int c, fd = -1;
while ((c = getopt(argc, argv, "l:")) != EOF)
tty_dev = optarg;
if ((fd = tty_open(tty_dev)) >= 0)