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.message}")
return
end
begin
progs = JSON.parse(res.output)
rescue TypeError, JSON::ParserError => e
add_error("failed to parse bpftool output: #{e.message}")
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
|