def drain_fd(fd, buf=nil)
      loop do
        tmp = fd.read_nonblock(4096)
        buf << tmp unless buf.nil?
      end
    rescue EOFError, Errno::EPIPE
      fd.close
      true
    rescue Errno::EINTR
    rescue Errno::EWOULDBLOCK, Errno::EAGAIN
      false
    end
def drain_fd(fd, buf=nil)
      loop do
        tmp = fd.read_nonblock(4096)
        buf << tmp unless buf.nil?
      end
    rescue EOFError, Errno::EPIPE
      fd.close
      true
    rescue Errno::EINTR
    rescue Errno::EWOULDBLOCK, Errno::EAGAIN
      false
    end
Do nonblocking reads from `fd`, appending all data read into `buf`.

 @param [IO] fd The file to read from.
 @param [String] buf A buffer to append the read data to.

 @return [true, false] Whether `fd` was closed due to an exceptional
   condition (`EOFError` or `EPIPE`).