title: Listen to read only sysfs file using epoll
body: <p>I know that epoll can be used to effectively read on GPIO events from user space, and many other possibilities are possible for sockets. I wanted to listen to sysfs attribute that is read-only with epoll. Is it possible? I always get EPOLLERR here. If anyone could explain what the problem is here, I would appreciate it.</p>
  <pre><code>mFileFd = open(&quot;/sys/devices/virtual/thermal/thermal_zone0/temp&quot;, O_RDONLY | O_NONBLOCK);
  if (mFileFd &lt; 0) {
    perror(&quot;Error opening file.&quot;);
    return -1;
  }
  
  mEpollFd = epoll_create(1);
  if (mEpollFd &lt; 0) {
    perror(&quot;Unable to create epoll&quot;);
    return mEpollFd;
  }
  
  mEpollEvent.events = EPOLLIN;
  mEpollEvent.data.fd = mFileFd;
  
  err = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mFileFd, &amp; mEpollEvent);
  if (err) {
    perror(&quot;Unable to add fd to epoll instance.&quot;);
    return err;
  }
  
  int nfds = 0;
  int len = 0;
  char buf[200] = {
    0
  };
  
  nfds = epoll_wait(mEpollFd, mEpollEvents, 1, -1);
  if (nfds &lt; 0) {
    perror(&quot;Epoll error 1.&quot;);
    return -1;
  }
  for (int i = 0; i &lt; nfds; i++) {
    if ((mEpollEvents[i].events &amp; EPOLLERR) ||
      (mEpollEvents[i].events &amp; EPOLLHUP)) {
      fprintf(stderr, &quot;Epoll error 2.\n&quot;);
      return -1;
    }
  
    if (mEpollEvents[i].data.fd == mFileFd) {
      len = read(mFileFd, &amp; buf, sizeof(buf) - 1);
      if (len &lt; 0) {
        perror(&quot;File read error.&quot;);
        return -1;
      }
      buf[len] = '\0';
  
      printf(&quot;Got=%s&quot;, buf);
    }
  
  }
  </code></pre>