Skip to content

Commit

Permalink
chore(prog): Add autoattach api
Browse files Browse the repository at this point in the history
Signed-off-by: Tao Chen <chen.dylane@gmail.com>
  • Loading branch information
chentao-kernel committed Mar 11, 2024
1 parent 51a3b3d commit 7279938
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func (p *BPFProg) SetAutoload(autoload bool) error {
return nil
}

func (p *BPFProg) SetAutoattach(autoload bool) {
C.bpf_program__set_autoattach(p.prog, C.bool(autoload))
}

func (p *BPFProg) Autoattach() bool {
return bool(C.bpf_program__autoattach(p.prog))
}

// AttachGeneric is used to attach the BPF program using autodetection
// for the attach target. You can specify the destination in BPF code
// via the SEC() such as `SEC("fentry/some_kernel_func")`
Expand Down
7 changes: 7 additions & 0 deletions selftest/set-attach/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func main() {
os.Exit(-1)
}

prog.SetAutoattach(false)
if prog.Autoattach() {
fmt.Println(os.Stderr, "set auto attach failed")
os.Exit(-1)
}
prog.SetAutoattach(true)

err = bpfModule.BPFLoadObject()
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down

0 comments on commit 7279938

Please sign in to comment.