tools:iio:iio_event_monitor: save right errno
authorHartmut Knaack <knaack.h@gmx.de>
Sun, 31 May 2015 12:39:49 +0000 (14:39 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sun, 31 May 2015 16:34:05 +0000 (17:34 +0100)
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@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
tools/iio/iio_event_monitor.c

index f6fdab48d3405c705e8d0436404aa8a8a36ab4d9..578390db1bec2df150bca79563e43a47e63c9c5e 100644 (file)
@@ -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) {