9
9
"errors"
10
10
"fmt"
11
11
"io"
12
+ "io/fs"
12
13
"log"
13
14
"os"
14
15
"path"
@@ -24,6 +25,7 @@ import (
24
25
"github.com/cilium/ebpf"
25
26
"github.com/cilium/ebpf/btf"
26
27
"github.com/cilium/ebpf/link"
28
+ "github.com/cilium/ebpf/pin"
27
29
"github.com/spf13/cobra"
28
30
"golang.org/x/sys/unix"
29
31
"golang.org/x/term"
@@ -403,26 +405,20 @@ func getTetragonProgs(base string) ([]*prog, error) {
403
405
var progs []* prog
404
406
405
407
// Walk bpffs/tetragon and look for programs
406
- err := filepath . Walk (base ,
407
- func (path string , finfo os. FileInfo , err error ) error {
408
+ err := pin . WalkDir (base ,
409
+ func (path string , finfo fs. DirEntry , obj pin. Pinner , err error ) error {
408
410
if err != nil {
409
411
return err
410
412
}
411
413
if finfo .IsDir () {
412
414
return nil
413
415
}
414
- if strings .HasSuffix (path , "/link" ) || strings .HasSuffix (path , "/link_override" ) {
415
- return nil // skip BPF links, they make the syscall fail since cilium/ebpf@78074c59
416
- }
417
- p , err := ebpf .LoadPinnedProgram (path , nil )
418
- if err != nil {
419
- return err
420
- }
421
- defer p .Close ()
422
416
423
- if ! isProg (p .FD ()) {
417
+ p , ok := obj .(* ebpf.Program )
418
+ if ! ok {
424
419
return nil
425
420
}
421
+ defer p .Close ()
426
422
427
423
info , err := p .Info ()
428
424
if err != nil {
@@ -440,7 +436,7 @@ func getTetragonProgs(base string) ([]*prog, error) {
440
436
progs = append (progs , & prog {
441
437
id : uint32 (id ),
442
438
name : getName (p , info ),
443
- pin : path ,
439
+ pin : filepath . Join ( base , path ) ,
444
440
cnt : runCnt ,
445
441
time : runTime ,
446
442
alive : true ,
@@ -450,18 +446,6 @@ func getTetragonProgs(base string) ([]*prog, error) {
450
446
return progs , err
451
447
}
452
448
453
- func isProg (fd int ) bool {
454
- return isBPFObject ("prog" , fd )
455
- }
456
-
457
- func isBPFObject (object string , fd int ) bool {
458
- readlink , err := os .Readlink (fmt .Sprintf ("/proc/self/fd/%d" , fd ))
459
- if err != nil {
460
- return false
461
- }
462
- return readlink == fmt .Sprintf ("anon_inode:bpf-%s" , object )
463
- }
464
-
465
449
func getName (p * ebpf.Program , info * ebpf.ProgramInfo ) string {
466
450
handle , err := p .Handle ()
467
451
if err != nil {
0 commit comments