Skip to content

Commit e0ab359

Browse files
committed
Print error message on empty BPF
This is useful when we're not sure if a filter is installed or not
1 parent 808358b commit e0ab359

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/seccomp-tools/dumper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ def dump_by_pid(pid, limit, &block)
181181
while limit.negative? || i < limit
182182
begin
183183
bpf = Ptrace.seccomp_get_filter(pid, i)
184-
rescue Errno::ENOENT, Errno::EINVAL
184+
rescue Errno::EINVAL
185+
Logger.error('No seccomp filters installed')
186+
break
187+
rescue Errno::ENOENT
188+
Logger.error('No filter exists at this index')
185189
break
186190
end
187191
collect << (block.nil? ? bpf : yield(bpf, nil))

spec/cli/dump_spec.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,22 @@
3434
break if line.start_with?('Welcome')
3535
end
3636
expect { described_class.new(['-f', 'inspect', '-p', pid.to_s]).handle }.to output(@bpf_inspect).to_stdout
37-
expect { described_class.new(['-l', '2', '-p', pid.to_s]).handle }.to output(@bpf_disasm).to_stdout
37+
expect { described_class.new(['-l', '2', '-p', pid.to_s]).handle }.to output(@bpf_disasm+"[ERROR] No filter exists at this index\n").to_stdout
3838
i.write("0\n")
3939
end
4040
end
4141

42+
it 'by pid without filter' do
43+
pid = Process.spawn('sleep 60')
44+
begin
45+
error = /No seccomp filters installed/
46+
expect { described_class.new(['-p', pid.to_s]).handle }.to output(error).to_stdout
47+
ensure
48+
Process.kill('TERM', pid)
49+
Process.wait(pid)
50+
end
51+
end
52+
4253
it 'by pid without root' do
4354
pid = Process.spawn('sleep 60')
4455
begin

0 commit comments

Comments
 (0)