Class: OsCtld::Assets::CgroupProgram
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
- Defined in:
- lib/osctld/assets/cgroup_program.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(cgroup_path, opts) ⇒ CgroupProgram
constructor
A new instance of CgroupProgram.
- #validate(_run) ⇒ Object protected
Methods inherited from Base
#add_error, #prefetch_zfs, register, #run_validation, #state, #type, #valid?, #validate?, #validate_block
Constructor Details
#initialize(cgroup_path, opts) ⇒ CgroupProgram
Returns a new instance of CgroupProgram.
15 16 17 |
# File 'lib/osctld/assets/cgroup_program.rb', line 15 def initialize(cgroup_path, opts) # rubocop:disable all super end |
Instance Method Details
#exist? ⇒ Boolean
19 20 21 |
# File 'lib/osctld/assets/cgroup_program.rb', line 19 def exist? Dir.exist?(path) end |
#validate(_run) ⇒ Object (protected)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/osctld/assets/cgroup_program.rb', line 25 def validate(_run) unless exist? return if opts[:optional] add_error('cgroup not found') return end begin res = syscmd("bpftool -j cgroup list #{path}") rescue SystemCommandFailed => e add_error("bpftool failed: #{e.}") return end begin progs = JSON.parse(res.output) rescue TypeError, JSON::ParserError => e add_error("failed to parse bpftool output: #{e.}") return end add_error('more than one program attached') if progs.length > 2 prog = progs.detect { |v| v['name'] == opts[:program_name] } if prog.nil? add_error("program #{opts[:program_name]} not attached") return end if opts[:attach_type] && prog['attach_type'] != opts[:attach_type] add_error("invalid attach_type: expected #{opts[:attach_type]}, got #{prog['attach_type']}") end return unless opts[:attach_flags] && prog['attach_flags'] != opts[:attach_flags] add_error("invalid attach_flags: expected #{opts[:attach_flags]}, got #{prog['attach_flags']}") end |