monitor: Add error return value to control_tty()
diff --git a/monitor/control.c b/monitor/control.c
index f9a0b53..67cfdfd 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -1253,22 +1253,24 @@
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 @@
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 @@
data = malloc(sizeof(*data));
if (!data) {
close(fd);
- return;
+ return -ENOMEM;
}
memset(data, 0, sizeof(*data));
@@ -1299,6 +1302,8 @@
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 601a45f..55384db 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);