Skip to content

Commit

Permalink
pkg/sensors: RawDetachUnloader do not detach on unpin false
Browse files Browse the repository at this point in the history
Avoid detaching the programs on Unload with unpin == false otherwise the
program pins stay but the programs don't run.

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Jan 28, 2025
1 parent b76687b commit b4815d7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pkg/sensors/unloader/unloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@ type RawDetachUnloader struct {
AttachType ebpf.AttachType
}

func (rdu *RawDetachUnloader) Unload(_ bool) error {
func (rdu *RawDetachUnloader) Unload(unpin bool) error {
defer rdu.Prog.Close()
err := link.RawDetachProgram(link.RawDetachProgramOptions{
Target: rdu.TargetFD,
Program: rdu.Prog,
Attach: rdu.AttachType,
})
if err != nil {
return fmt.Errorf("failed to detach %s: %w", rdu.Name, err)
// PROG_ATTACH does not return any link, so there's nothing to unpin,
// but we must skip the detach operation for 'unpin == false' otherwise
// the pinned program will be un-attached
if unpin {
err := link.RawDetachProgram(link.RawDetachProgramOptions{
Target: rdu.TargetFD,
Program: rdu.Prog,
Attach: rdu.AttachType,
})
if err != nil {
return fmt.Errorf("failed to detach %s: %w", rdu.Name, err)
}
}
return nil
}
Expand Down

0 comments on commit b4815d7

Please sign in to comment.