@@ -3,14 +3,12 @@ package ebpf
33import (
44 gocontext "context"
55 "encoding/binary"
6- "errors"
76 "fmt"
87 "os"
98 "strconv"
109 "strings"
1110 "sync"
1211 "sync/atomic"
13- "syscall"
1412 "unsafe"
1513
1614 "kernel.org/pub/linux/libs/security/libcap/cap"
@@ -540,23 +538,37 @@ func (t *Tracee) Init(ctx gocontext.Context) error {
540538 // Checking the kernel symbol needs to happen after obtaining the capability;
541539 // otherwise, we get a warning.
542540 usedClockID := traceetime .CLOCK_BOOTTIME
541+ // err = capabilities.GetInstance().Specific(
542+ // func() error {
543+ // supported, err := bpf.BPFHelperIsSupported(bpf.BPFProgTypeKprobe, bpf.BPFFuncKtimeGetBootNs)
544+
545+ // // only report if operation not permitted
546+ // if errors.Is(err, syscall.EPERM) {
547+ // return err
548+ // }
549+
550+ // // If bpf_ktime_get_boot_ns is not available, eBPF will generate events based on monotonic time.
551+ // if !supported {
552+ // usedClockID = traceetime.CLOCK_MONOTONIC
553+ // }
554+ // return nil
555+ // },
556+ // cap.BPF,
557+ // cap.PERFMON,
558+ // )
543559 err = capabilities .GetInstance ().Specific (
544560 func () error {
545- supported , err := bpf .BPFHelperIsSupported (bpf .BPFProgTypeKprobe , bpf .BPFFuncKtimeGetBootNs )
546-
547- // only report if operation not permitted
548- if errors .Is (err , syscall .EPERM ) {
549- return err
550- }
551-
552561 // If bpf_ktime_get_boot_ns is not available, eBPF will generate events based on monotonic time.
553- if ! supported {
554- usedClockID = traceetime .CLOCK_MONOTONIC
562+ if _ , err = t .kernelSymbols .GetSymbolByName ("bpf_ktime_get_boot_ns" ); err != nil {
563+ // The only case handled is when the symbol is not found
564+ if strings .Contains (err .Error (), "symbol not found" ) {
565+ usedClockID = traceetime .CLOCK_MONOTONIC
566+ err = nil
567+ }
555568 }
556- return nil
569+ return err
557570 },
558- cap .BPF ,
559- cap .PERFMON ,
571+ cap .SYSLOG ,
560572 )
561573 if err != nil {
562574 return errfmt .WrapError (err )
0 commit comments