From 0430d5bdb270a4b76ad4863c26f9f43de5c14450 Mon Sep 17 00:00:00 2001 From: Mahe Tardy Date: Wed, 24 Jan 2024 19:52:34 +0100 Subject: [PATCH] pkg/bpf: improve modify return syscall detection err flow Avoiding logging in private function (except for debug), pass the error to the caller. Signed-off-by: Mahe Tardy --- pkg/bpf/detect.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/bpf/detect.go b/pkg/bpf/detect.go index a1479b5b491..c475cd35c91 100644 --- a/pkg/bpf/detect.go +++ b/pkg/bpf/detect.go @@ -122,10 +122,10 @@ func detectModifyReturn() bool { return true } -func detectModifyReturnSyscall() bool { +func detectModifyReturnSyscall() (bool, error) { sysGetcpu, err := arch.AddSyscallPrefix("sys_getcpu") if err != nil { - return false + return false, fmt.Errorf("failed to add arch specific syscall prefix: %w", err) } logger.GetLogger().Debugf("probing detectModifyReturnSyscall using %s", sysGetcpu) prog, err := ebpf.NewProgram(&ebpf.ProgramSpec{ @@ -140,8 +140,7 @@ func detectModifyReturnSyscall() bool { License: "MIT", }) if err != nil { - logger.GetLogger().WithError(err).Info("detectModifyReturnSyscall: failed to load") - return false + return false, fmt.Errorf("failed to load: %w", err) } defer prog.Close() @@ -149,11 +148,10 @@ func detectModifyReturnSyscall() bool { Program: prog, }) if err != nil { - logger.GetLogger().WithError(err).Info("detectModifyReturnSyscall, failed to attach") - return false + return false, fmt.Errorf("failed to attach: %w", err) } link.Close() - return true + return true, nil } func HasModifyReturn() bool { @@ -165,7 +163,11 @@ func HasModifyReturn() bool { func HasModifyReturnSyscall() bool { modifyReturnSyscall.init.Do(func() { - modifyReturnSyscall.detected = detectModifyReturnSyscall() + var err error + modifyReturnSyscall.detected, err = detectModifyReturnSyscall() + if err != nil { + logger.GetLogger().WithError(err).Error("detect modify return syscall") + } }) return modifyReturnSyscall.detected }