title: When using inotify_read, pnctl_signal does not interrupt the inotify_read
body: <p>I am building a log parser program in PHP. Log parser reads the data from the log file created by ProFTPD and then runs some actions if it detects specific commands. To be able to detect changes in the log file, I am using Inotify. If log file gets too large, I want to rotate the log by sending a signal to the log parser to finish processing the current file and then terminate the log parser. Logrotate would then restart the log parser again after it makes sure that the original file that is being read is emptied.</p>
  
  <p>The problem is that when I use Inotify and when the inotify is in blocking state, the interrupts won't work.</p>
  
  <p>For example:</p>
  
  <pre><code>#!/usr/bin/php -q
  &lt;?php
  declare(ticks = 1);
  
  $log_parser = new LogParser();
  $log_parser-&gt;process_log();
  
  class LogParser {
  
    private $ftp_log_file = '/var/log/proftpd/proftpd.log';
    # file descriptor for the log file
    private $fd;
    # inotify instance
    private $inotify_inst;
    # watch id for the inotifier
    private $watch_id;
  
    public function process_log() {
      // Open an inotify instance
      $this-&gt;inotify_inst = inotify_init();
      $this-&gt;watch_id = inotify_add_watch($this-&gt;inotify_inst, $this-&gt;ftp_log_file, IN_MODIFY);
  
      $this-&gt;fd = fopen($this-&gt;ftp_log_file, 'r');
      if ($this-&gt;fd === false)
        die("unable to open $this-&gt;ftp_log_file!\n");
  
      pcntl_signal(SIGUSR1,  function($signal) {
        $this-&gt;sig_handler($signal);
      });
  
      while (1) {
        # If the thread gets blocked here, the signals do not work
        $events = inotify_read($this-&gt;inotify_inst);
        while ($line = trim(fgets($this-&gt;fd))) {
          // Parse the log ...
        }
      }
      fclose($this-&gt;fd);
      // stop watching our directory
      inotify_rm_watch($this-&gt;inotify_inst, $this-&gt;watch_id);
      // close our inotify instance
      fclose($this-&gt;inotify_inst);
    }
  
    private function sig_handler($signo) {
      switch ($signo) {
        case SIGUSR1:
          // Do some action ... 
      }
    }
  
  }
  </code></pre>
  
  <p>I know that one solution could be that I start the parent process and then add the signal handler to that parent process. The parent process should start the log parser and the log parser would get blocked by inotify_read, but parent process wouldn't, but was wondering if there is a solution not involving the parent process - if the inotify is able to support interrupts?</p>
  
  <p>Thanks</p>