summaryrefslogtreecommitdiff
path: root/tools/iio/generic_buffer.c
diff options
context:
space:
mode:
authorHartmut Knaack <knaack.h@gmx.de>2015-05-31 14:40:04 +0200
committerJonathan Cameron <jic23@kernel.org>2015-05-31 19:24:18 +0100
commit6bb7cac8551e2d60edbd25a6d046cc45932c4c3e (patch)
tree34a1b4188e6cc0724095f74e7a298696db45e469 /tools/iio/generic_buffer.c
parentc8ce9903cba202936999c2c9463fbb370ee145ba (diff)
downloadlinux-6bb7cac8551e2d60edbd25a6d046cc45932c4c3e.tar.gz
tools:iio:generic_buffer: add error handling
Add error handling to calls which can indicate a major problem by returning an error code. Signed-off-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio/generic_buffer.c')
-rw-r--r--tools/iio/generic_buffer.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index 93ac93f74549..cf9a4120204f 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -347,7 +347,14 @@ int main(int argc, char **argv)
.events = POLLIN,
};
- poll(&pfd, 1, -1);
+ ret = poll(&pfd, 1, -1);
+ if (ret < 0) {
+ ret = -errno;
+ goto error_close_buffer_access;
+ } else if (ret == 0) {
+ continue;
+ }
+
toread = buf_len;
} else {
@@ -378,11 +385,14 @@ int main(int argc, char **argv)
if (!notrigger)
/* Disconnect the trigger - just write a dummy name. */
- write_sysfs_string("trigger/current_trigger",
- dev_dir_name, "NULL");
+ ret = write_sysfs_string("trigger/current_trigger",
+ dev_dir_name, "NULL");
+ if (ret < 0)
+ printf("Failed to write to %s\n", dev_dir_name);
error_close_buffer_access:
- close(fp);
+ if (close(fp) == -1)
+ perror("Failed to close buffer");
error_free_buffer_access:
free(buffer_access);
error_free_data: