[PATCH 09/32] tools:iio:iio_event_monitor: save right errno

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move up error handling code to preserve the errno coming from ioctl(),
before it may be changed by close().

Signed-off-by: Hartmut Knaack <knaack.h@xxxxxx>
---
 tools/iio/iio_event_monitor.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index f6fdab4..578390d 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -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) {
-- 
2.3.6

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux