diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2018-11-09 13:12:28 +0100 |
---|---|---|
committer | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2018-11-09 13:12:28 +0100 |
commit | 4990afa7fc1ec3a9ee74073c02512b1e29e2c154 (patch) | |
tree | 621897b5353e053edf0283a87cacd9f11daafa77 | |
parent | 3c4068317133413784b475f3959b76c37061b258 (diff) | |
download | microcom-4990afa7fc1ec3a9ee74073c02512b1e29e2c154.tar.gz microcom-4990afa7fc1ec3a9ee74073c02512b1e29e2c154.tar.xz |
Let microcom return != 0 on EOF
To prevent issuing another error message, add a message to all failing exit
paths of mux_loop and drop the one from main().
Fixes: https://github.com/pengutronix/microcom/issues/7
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
-rw-r--r-- | microcom.c | 2 | ||||
-rw-r--r-- | mux.c | 26 |
2 files changed, 19 insertions, 9 deletions
@@ -328,8 +328,6 @@ int main(int argc, char *argv[]) /* run the main program loop */ ret = mux_loop(ios); - if (ret) - fprintf(stderr, "%s\n", strerror(-ret)); ios->exit(ios); @@ -400,6 +400,8 @@ int mux_loop(struct ios_ops *ios) unsigned char buf[BUFSIZE]; while (1) { + int ret; + FD_ZERO(&ready); if (!listenonly) FD_SET(STDIN_FILENO, &ready); @@ -410,25 +412,35 @@ int mux_loop(struct ios_ops *ios) if (FD_ISSET(ios->fd, &ready)) { /* pf has characters for us */ len = read(ios->fd, buf, BUFSIZE); - if (len < 0) - return -errno; + if (len < 0) { + ret = -errno; + fprintf(stderr, "%s\n", strerror(-ret)); + return ret; + } if (len == 0) { fprintf(stderr, "Got EOF from port\n"); - return 0; + return -EINVAL; } i = handle_receive_buf(ios, buf, len); - if (i < 0) + if (i < 0) { + fprintf(stderr, "%s\n", strerror(-i)); return i; + } } if (!listenonly && FD_ISSET(STDIN_FILENO, &ready)) { /* standard input has characters for us */ i = read(STDIN_FILENO, buf, BUFSIZE); - if (i < 0) - return -errno; - if (i == 0) + if (i < 0) { + ret = -errno; + fprintf(stderr, "%s\n", strerror(-ret)); + return ret; + } + if (i == 0) { + fprintf(stderr, "Got EOF from stdin\n"); return -EINVAL; + } cook_buf(ios, buf, i); } |