Skip to content

Commit

Permalink
Load linux_admin once when needed
Browse files Browse the repository at this point in the history
Due to some concerns about loading `linux_admin` multiple times when
calling `MiqSystem.num_cpus` causing a memory leak, this creates a
helper method that no-ops after it has been required once.
  • Loading branch information
NickLaMuro committed Jan 15, 2018
1 parent 58737f1 commit 3a7d4d1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/gems/pending/util/miq-system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.cpu_usage

def self.num_cpus
return unless Sys::Platform::IMPL == :linux
require 'linux_admin'
require_linux_admin
@num_cpus ||= LinuxAdmin::Hardware.new.total_cores
end

Expand Down Expand Up @@ -228,6 +228,12 @@ def self.open_browser(url)
when :mingw, :mswin then `start "#{url.gsub('"', '""')}"`
end
end

def self.require_linux_admin
return true if @linux_admin_required
require "linux_admin"
@linux_admin_required = true
end
end

if __FILE__ == $0
Expand Down

0 comments on commit 3a7d4d1

Please sign in to comment.