Commit 5fdb8c61 authored by Hartmut Knaack's avatar Hartmut Knaack Committed by Jonathan Cameron

tools:iio:iio_event_monitor: save right errno

Move up error handling code to preserve the errno coming from ioctl(),
before it may be changed by close().
Signed-off-by: default avatarHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 2b6a6e67
......@@ -275,15 +275,17 @@ int main(int argc, char **argv)
}
ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
close(fd);
if (ret == -1 || event_fd == -1) {
ret = -errno;
fprintf(stdout, "Failed to retrieve event fd\n");
if (close(fd) == -1)
perror("Failed to close character device file");
goto error_free_chrdev_name;
}
close(fd);
while (true) {
ret = read(event_fd, &event, sizeof(event));
if (ret == -1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment