summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-04-30 13:34:38 +0200
committerJason Wessel <jason.wessel@windriver.com>2018-04-30 15:42:14 -0500
commit994f8b768924e633c4e4a5abdedde1553c4fcc30 (patch)
treed9b5bb20a9e2bc78df9e5785b5682cf7ae460d30
parent7214f9286607b49f07c4f24dad0db5802e5e2994 (diff)
downloadagent-proxy-994f8b768924e633c4e4a5abdedde1553c4fcc30.tar.gz
agent-proxy: improve error handling
If the baud rate cannot be set provide an error message and abort. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
-rw-r--r--agent-proxy-rs232.c32
-rw-r--r--agent-proxy.c3
2 files changed, 25 insertions, 10 deletions
diff --git a/agent-proxy-rs232.c b/agent-proxy-rs232.c
index 0e7841f..4027e8e 100644
--- a/agent-proxy-rs232.c
+++ b/agent-proxy-rs232.c
@@ -119,27 +119,39 @@ static int rate_to_code(int rate)
static int get_tty_state(unsigned int sock, struct hardwire_ttystate *state)
{
#ifdef HAVE_TERMIOS
- if (tcgetattr(sock, &state->termios) < 0)
+ if (tcgetattr(sock, &state->termios) < 0) {
+ perror("tcgetattr failed");
return -1;
+ }
return 0;
#endif
#ifdef HAVE_TERMIO
- if (ioctl(sock, TCGETA, &state->termio) < 0)
+ if (ioctl(sock, TCGETA, &state->termio) < 0) {
+ perror("ioctl failed");
return -1;
+ }
return 0;
#endif
#ifdef HAVE_SGTTY
- if (ioctl(sock, TIOCGETP, &state->sgttyb) < 0)
+ if (ioctl(sock, TIOCGETP, &state->sgttyb) < 0) {
+ perror("ioctl failed");
return -1;
- if (ioctl(sock, TIOCGETC, &state->tc) < 0)
+ }
+ if (ioctl(sock, TIOCGETC, &state->tc) < 0) {
+ perror("ioctl failed");
return -1;
- if (ioctl(sock, TIOCGLTC, &state->ltc) < 0)
+ }
+ if (ioctl(sock, TIOCGLTC, &state->ltc) < 0) {
+ perror("ioctl failed");
return -1;
- if (ioctl(sock, TIOCLGET, &state->lmode) < 0)
+ }
+ if (ioctl(sock, TIOCLGET, &state->lmode) < 0) {
+ perror("ioctl failed");
return -1;
+ }
return 0;
#endif
@@ -180,14 +192,16 @@ int setbaudrate(int sock, int baud)
int baud_code = rate_to_code(baud);
if (baud_code < 0) {
- /* The baud rate was not valid.
- A warning has already been issued. */
+ /* The baud rate was not valid. */
+ fprintf(stderr, "Invalid baud rate\n");
errno = EINVAL;
return -1;
}
- if (get_tty_state(sock, &state))
+ if (get_tty_state(sock, &state)) {
+ fprintf(stderr, "Cannot get tty state\n");
return -1;
+ }
#ifdef HAVE_TERMIOS
cfsetospeed(&state.termios, baud_code);
diff --git a/agent-proxy.c b/agent-proxy.c
index a2d7706..d0a43bd 100644
--- a/agent-proxy.c
+++ b/agent-proxy.c
@@ -673,7 +673,8 @@ static int setup_remote_port(struct port_st *rport, char *host, char *port)
}
if (baudinfo) {
- setbaudrate(rport->sock, atoi(baudinfo));
+ if (setbaudrate(rport->sock, atoi(baudinfo)))
+ return 1;
}
setstopbits(rport->sock, "1");
setcondefaults(rport->sock);