From 9dc47e653d5e46cd0e1f0b75f001dde22e2a446c Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 27 Apr 2016 14:16:08 +0300 Subject: [PATCH] monitor: Add error return value to control_tty() --- monitor/control.c | 17 +++++++++++------ monitor/control.h | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/monitor/control.c b/monitor/control.c index f9a0b53cb..67cfdfd9b 100644 --- a/monitor/control.c +++ b/monitor/control.c @@ -1253,22 +1253,24 @@ static unsigned int get_speed(unsigned int speed) return 0; } -void control_tty(const char *path, unsigned int speed) +int control_tty(const char *path, unsigned int speed) { struct control_data *data; struct termios ti; - int fd; + int fd, err; fd = open(path, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd < 0) { + err = -errno; perror("Failed to open serial port"); - return; + return err; } if (tcflush(fd, TCIOFLUSH) < 0) { + err = -errno; perror("Failed to flush serial port"); close(fd); - return; + return err; } memset(&ti, 0, sizeof(ti)); @@ -1281,9 +1283,10 @@ void control_tty(const char *path, unsigned int speed) cfsetspeed(&ti, get_speed(speed)); if (tcsetattr(fd, TCSANOW, &ti) < 0) { + err = -errno; perror("Failed to set serial port settings"); close(fd); - return; + return err; } printf("--- %s opened ---\n", path); @@ -1291,7 +1294,7 @@ void control_tty(const char *path, unsigned int speed) data = malloc(sizeof(*data)); if (!data) { close(fd); - return; + return -ENOMEM; } memset(data, 0, sizeof(*data)); @@ -1299,6 +1302,8 @@ void control_tty(const char *path, unsigned int speed) data->fd = fd; mainloop_add_fd(data->fd, EPOLLIN, tty_callback, data, free_data); + + return 0; } bool control_writer(const char *path) diff --git a/monitor/control.h b/monitor/control.h index 601a45f01..55384dbd9 100644 --- a/monitor/control.h +++ b/monitor/control.h @@ -27,7 +27,7 @@ bool control_writer(const char *path); void control_reader(const char *path); void control_server(const char *path); -void control_tty(const char *path, unsigned int speed); +int control_tty(const char *path, unsigned int speed); int control_tracing(void); void control_message(uint16_t opcode, const void *data, uint16_t size); -- 2.47.3