Skip to content
Snippets Groups Projects
Commit df016874 authored by Martin Pitt's avatar Martin Pitt
Browse files

umockdev-record: Check attributes with select() before read()

This might help against attributes which immediately block a read() even
in non-blocking mode.

See issue #81
parent 3657ef58
No related branches found
No related tags found
No related merge requests found
...@@ -216,6 +216,11 @@ print_device_attributes(string devpath, string subdir) ...@@ -216,6 +216,11 @@ print_device_attributes(string devpath, string subdir)
continue; continue;
} }
// trying to read some attributes hangs forever even with O_NONBLOCK, so check if there's anything
Posix.fd_set read_fds;
Posix.FD_ZERO(out read_fds);
Posix.FD_SET(fd, ref read_fds);
if (Posix.select(fd + 1, &read_fds, null, null, {0, 0}) > 0) {
ssize_t contents_len = Posix.read(fd, contents, contents.length - 1); ssize_t contents_len = Posix.read(fd, contents, contents.length - 1);
if (contents_len >= 0) { if (contents_len >= 0) {
contents[contents_len] = 0; contents[contents_len] = 0;
...@@ -223,6 +228,7 @@ print_device_attributes(string devpath, string subdir) ...@@ -223,6 +228,7 @@ print_device_attributes(string devpath, string subdir)
} else { } else {
debug("Cannot read %s, ignoring: %s", attr_path, strerror(errno)); debug("Cannot read %s, ignoring: %s", attr_path, strerror(errno));
} }
}
Posix.close(fd); Posix.close(fd);
} else if (FileUtils.test(attr_path, FileTest.IS_DIR)) { } else if (FileUtils.test(attr_path, FileTest.IS_DIR)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment