diff options
author | Thomas Osterried <thomas@osterried.de> | 2008-04-13 23:03:52 +0000 |
---|---|---|
committer | Thomas Osterried <thomas@osterried.de> | 2008-04-13 23:03:52 +0000 |
commit | 0cbbc646f7a69b7efd4f74209ccc31d04b18d118 (patch) | |
tree | 491f598be7e6c8b9a7baf9421857421f74b9dff4 | |
parent | bb18a39b4a7f79f7bfe4861fdb8860e3eef58246 (diff) |
the following issues are fixed:
1. if stdin closes (i.e. if call is right end of a pipe),
then call should close. this also fixes the case when
call reads from a unix fifo, and the other end of the
fifo terminates. This produced highest cpu-load,
with select(), read() = 0, select(), read() = 0, ..
2. if stdin is not a tty, i.e. call is called from ax25d,
then it's not a good idea to honor the ~ commands.
In that special case, you could imagine what ~! means,
while ax25d is running as uid 0...
3. while not operating on pty, the FILE buffers are not
flushed in all cases. Thus, the messages like "Connected .."
were be printed in the termination phase of the program..
-rw-r--r-- | call/call.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/call/call.c b/call/call.c index 60cd774..6841b90 100644 --- a/call/call.c +++ b/call/call.c @@ -88,6 +88,8 @@ static int window = 0; static char *port = NULL; static char *mycall = NULL; +static int stdin_is_tty = 1; + int interrupted = FALSE; int paclen = 0; int fd; @@ -1521,6 +1523,12 @@ int cmd_call(char *call[], int mode) } if (FD_ISSET(fd, &sock_read)) { bytes = read(fd, buf, 511); + if (bytes == 0) { + /* read EOF on stdin */ + /* cause program to terminate */ + flags &= ~FLAG_RECONNECT; + break; + } if (bytes == -1 && errno != EWOULDBLOCK && errno != EAGAIN) { if (errno != ENOTCONN) @@ -1667,7 +1675,7 @@ int cmd_call(char *call[], int mode) if (bytes > 0) statline(mode, ""); - if (bytes > 1 && *buf == '~') { + if (bytes > 1 && *buf == '~' && stdin_is_tty) { buf[bytes] = 0; switch (buf[1]) { @@ -2062,6 +2070,11 @@ int main(int argc, char **argv) int p; int mode = TALKMODE; + if (!isatty(STDIN_FILENO)) + stdin_is_tty = 0; + + setlinebuf(stdin); + while ((p = getopt(argc, argv, "b:dhm:p:rs:tvw:")) != -1) { switch (p) { case 'b': @@ -2182,7 +2195,6 @@ int main(int argc, char **argv) } printf("GW4PTS AX.25 Connect v1.11\n"); - while (cmd_call(argv + optind + 1, mode)) { printf("Wait 60 sec before reconnect\n"); sleep(60); |