22
gadgetregistry "github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-registry"
23
"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets"
24
"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/trace/signal/types"
25
"github.com/inspektor-gadget/inspektor-gadget/pkg/params"
26
"github.com/inspektor-gadget/inspektor-gadget/pkg/parser"
29
type GadgetDesc struct{}
31
func (g *GadgetDesc) Name() string {
35
func (g *GadgetDesc) Category() string {
36
return gadgets.CategoryTrace
39
func (g *GadgetDesc) Type() gadgets.GadgetType {
40
return gadgets.TypeTrace
43
func (g *GadgetDesc) Description() string {
44
return "Trace signals received by processes"
49
ParamTargetSignal = "signal"
50
ParamFailedOnly = "failed-only"
51
ParamKillOnly = "kill-only"
54
func (g *GadgetDesc) ParamDescs() params.ParamDescs {
55
return params.ParamDescs{
59
Description: "Show only signal sent by this particular PID",
60
TypeHint: params.TypeInt32,
63
Key: ParamTargetSignal,
64
Description: `Trace only this signal (it can be an int like 9 or string beginning with "SIG" like "SIGKILL")`,
65
Validator: validateSignal,
70
DefaultValue: "false",
71
Description: "Show only events where the syscall sending a signal failed",
72
TypeHint: params.TypeBool,
77
DefaultValue: "false",
78
Description: "Show only events issued by kill syscall",
79
TypeHint: params.TypeBool,
84
func (g *GadgetDesc) Parser() parser.Parser {
85
return parser.NewParser[types.Event](types.GetColumns())
88
func (g *GadgetDesc) EventPrototype() any {
93
gadgetregistry.Register(&GadgetDesc{})
98
func validateSignal(signal string) error {
102
if strings.HasPrefix(signal, "SIG") {
105
if _, err := strconv.Atoi(signal); err == nil {
108
return errors.New("expected a signal number or a signal name starting with 'SIG'")