Skip to content

Commit 7a19b38

Browse files
committed
prevent ps, lsof and netstat chisels from printing their output if no event has been processed
1 parent ec5a841 commit 7a19b38

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

userspace/sysdig/chisels/lsof.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require "common"
4545
local dctable = {}
4646
local capturing = false
4747
local filter = nil
48+
local match = false
4849

4950
-- Argument notification callback
5051
function on_set_arg(name, val)
@@ -70,6 +71,7 @@ end
7071
-- Event parsing callback
7172
function on_event()
7273
sysdig.end_capture()
74+
match = true
7375
return false
7476
end
7577

@@ -79,6 +81,11 @@ function on_capture_end()
7981
return
8082
end
8183

84+
if match == false then
85+
print("empty capture or no event matching the filter")
86+
return
87+
end
88+
8289
local ttable = sysdig.get_thread_table(filter)
8390

8491
local sorted_ttable = pairs_top_by_val(ttable, 0, function(t,a,b) return a < b end)

userspace/sysdig/chisels/netstat.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ require "common"
4646
local dctable = {}
4747
local capturing = false
4848
local filter = "(fd.type=ipv4)"
49+
local match = false
4950

5051
-- Argument notification callback
5152
function on_set_arg(name, val)
@@ -71,6 +72,7 @@ end
7172
-- Event parsing callback
7273
function on_event()
7374
sysdig.end_capture()
75+
match = true
7476
return false
7577
end
7678

@@ -80,6 +82,11 @@ function on_capture_end()
8082
return
8183
end
8284

85+
if match == false then
86+
print("empty capture or no event matching the filter")
87+
return
88+
end
89+
8390
local ttable = sysdig.get_thread_table(filter)
8491

8592
print(extend_string("Proto", 6) ..

userspace/sysdig/chisels/ps.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require "common"
4545
local dctable = {}
4646
local capturing = false
4747
local filter = nil
48+
local match = false
4849

4950
-- Argument notification callback
5051
function on_set_arg(name, val)
@@ -69,6 +70,7 @@ end
6970
-- Event parsing callback
7071
function on_event()
7172
sysdig.end_capture()
73+
match = true
7274
return false
7375
end
7476

@@ -78,6 +80,11 @@ function on_capture_end(ts_s, ts_ns, delta)
7880
return
7981
end
8082

83+
if match == false then
84+
print("empty capture or no event matching the filter")
85+
return
86+
end
87+
8188
local ttable = sysdig.get_thread_table(filter)
8289

8390
local sorted_ttable = pairs_top_by_val(ttable, 0, function(t,a,b) return a < b end)

0 commit comments

Comments
 (0)