Method: NewRelic::Agent::SystemInfo.proc_try_read

Defined in:
lib/new_relic/agent/system_info.rb

.proc_try_read(path) ⇒ Object

A File.read against /(proc|sysfs)/* can hang with some older Linuxes. See bugzilla.redhat.com/show_bug.cgi?id=604887, RUBY-736, and github.com/opscode/ohai/commit/518d56a6cb7d021b47ed3d691ecf7fba7f74a6a7 for details on why we do it this way.

[View source]

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/new_relic/agent/system_info.rb', line 282

def self.proc_try_read(path)
  return nil unless File.exist?(path)

  content = +''
  File.open(path) do |f|
    loop do
      begin
        content << f.read_nonblock(4096)
      rescue EOFError
        break
      rescue Errno::EWOULDBLOCK, Errno::EAGAIN
        content = nil
        break # don't select file handle, just give up
      end
    end
  end
  content
end