summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debugfs-gpio-trace.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/debugfs-gpio-trace.c b/debugfs-gpio-trace.c
index 7390dfa..3baec31 100644
--- a/debugfs-gpio-trace.c
+++ b/debugfs-gpio-trace.c
@@ -312,8 +312,9 @@ ssize_t read_file(int fd, char* buf, ssize_t len)
rc = read(fd, buf + count, sizeof(buf - count));
nr++;
+ printf("Total read %d bytes in %d reads with rc %d\n", count, nr, rc);
+
if (rc == 0) {
- printf("Total read %d bytes in %d reads\n", count, nr);
return count;
} else if (rc == -1) {
rc = errno;
@@ -327,6 +328,42 @@ ssize_t read_file(int fd, char* buf, ssize_t len)
}
}
+int monitor_loop(int fd, char* buf, ssize_t buf_size)
+{
+ int rc;
+ fd_set rfds;
+ off_t file_size;
+ struct timespec ts;
+
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+
+ ts.tv_sec = 5;
+
+ rc = pselect(fd + 1, &rfds, NULL, NULL, &ts, 0);
+ if (rc == -1){
+ rc = errno;
+ printf("%s: pselect: %s (%d)\n",
+ __func__, strerror (rc), rc);
+ } else if (rc) {
+ if (FD_ISSET(fd, &rfds)) {
+ printf("[ %d ] "
+ "--------------------"
+ "--------------------"
+ "--------------------"
+ "--------------------"
+ "\n", rc);
+ file_size = read_file(fd, buf, buf_size);
+ rc = parse_file(fd, buf, file_size);
+ if (rc)
+ return rc;
+ } else {
+ printf("%s: pselect: no more data?\n", __func__);
+ }
+ }
+
+}
+
int main(int argc, char * const argv[])
{
int fd;
@@ -349,6 +386,7 @@ int main(int argc, char * const argv[])
return EX_OSFILE;
}
+#if 0
printf("%s: fd: %d\n", __func__, fd);
file_size = mmap_file(fd, &mmap_buf); /* For tests on files */
@@ -364,7 +402,18 @@ int main(int argc, char * const argv[])
if (rc)
return rc;
}
+#else
+ file_size = read_file(fd, static_buf, sizeof(static_buf));
+ rc = parse_file(fd, static_buf, file_size);
+ if (rc)
+ return rc;
+ while (1) {
+ rc = monitor_loop(fd, static_buf, sizeof(static_buf));
+ if (rc)
+ return rc;
+ }
+#endif
rc = close(fd);
if (rc == -1) {
rc = errno;