From fa53c4818145dd017a2a806ab0b412c8b9f4c127 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 10 May 2024 10:30:56 +0200 Subject: [PATCH 1/2] fix(pkg/driverbuilder): fixed local builder template. Fix on top of #342. Signed-off-by: Federico Di Pierro --- pkg/driverbuilder/builder/templates/local.sh | 2 +- pkg/driverbuilder/local.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/driverbuilder/builder/templates/local.sh b/pkg/driverbuilder/builder/templates/local.sh index 06fa856..ce344d3 100644 --- a/pkg/driverbuilder/builder/templates/local.sh +++ b/pkg/driverbuilder/builder/templates/local.sh @@ -20,7 +20,7 @@ # looking for it in a bunch of ways. Convenient when running Falco inside # a container or in other weird environments. # -set -xeuo pipefail +set -xeo pipefail {{ if or .BuildProbe (and .BuildModule (not .UseDKMS)) }} cd {{ .DriverBuildDir }} diff --git a/pkg/driverbuilder/local.go b/pkg/driverbuilder/local.go index 3ab6832..5fe28e5 100644 --- a/pkg/driverbuilder/local.go +++ b/pkg/driverbuilder/local.go @@ -74,7 +74,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { // if an unsupported target is passed. // Go on skipping automatic kernel headers download. if err == nil { - lbp.Logger.Info("Trying automatic kernel headers download") + lbp.Logger.Info("Trying automatic kernel headers download.") kernelDownloadScript, err := builder.KernelDownloadScript(realBuilder, nil, kr, lbp.Printer) // Patch kernel download script to echo KERNELDIR. // We need to capture KERNELDIR to later pass it as env variable to the build. @@ -90,7 +90,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { for scanner.Scan() { path = scanner.Text() } - lbp.Logger.Info("Setting KERNELDIR env var", lbp.Logger.Args("path", path)) + lbp.Logger.Info("Setting KERNELDIR env var.", lbp.Logger.Args("path", path)) // add the kerneldir path to env lbp.envMap[kernelDirEnv] = path defer func() { @@ -98,11 +98,11 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { _ = os.RemoveAll(path) }() } else { - lbp.Logger.Warn("Failed to download headers", lbp.Logger.Args("err", err)) + lbp.Logger.Warn("Failed to download headers.", lbp.Logger.Args("err", err)) } } } else { - lbp.Logger.Info("Skipping kernel headers automatic download", lbp.Logger.Args("err", err)) + lbp.Logger.Info("Skipping kernel headers automatic download.", lbp.Logger.Args("err", err)) } } @@ -202,7 +202,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { if err = copyDataToLocalPath(srcProbePath, c.ProbeFilePath); err != nil { return err } - lbp.Logger.Info("eBPF probe available", lbp.Logger.Args("path", c.ProbeFilePath)) + lbp.Logger.Info("eBPF probe available.", lbp.Logger.Args("path", c.ProbeFilePath)) c.ProbeFilePath = "" } } @@ -218,7 +218,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { if err = copyDataToLocalPath(koFiles[0], c.ModuleFilePath); err != nil { return err } - lbp.Logger.Info("kernel module available", lbp.Logger.Args("path", b.ModuleFilePath)) + lbp.Logger.Info("kernel module available.", lbp.Logger.Args("path", b.ModuleFilePath)) c.ModuleFilePath = "" break } else { @@ -226,7 +226,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { dkmsLogFile := fmt.Sprintf("/var/lib/dkms/%s/%s/build/make.log", c.DriverName, c.DriverVersion) logs, err := os.ReadFile(filepath.Clean(dkmsLogFile)) if err != nil { - lbp.Logger.Warn("Running dkms build failed, couldn't find dkms log", lbp.Logger.Args("file", dkmsLogFile)) + lbp.Logger.Warn("Running dkms build failed, couldn't find dkms log.", lbp.Logger.Args("file", dkmsLogFile)) } else { lbp.Logger.Warn("Running dkms build failed. Dumping dkms log.", lbp.Logger.Args("file", dkmsLogFile)) logBuf := bytes.NewBuffer(logs) @@ -241,7 +241,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { } if c.ModuleFilePath != "" || c.ProbeFilePath != "" { - return fmt.Errorf("Failed to build all requested drivers.") + return errors.New("failed to build all requested drivers") } return nil } From cdbddc96aa77adeaade383c8dce4e5c06f16d29d Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 10 May 2024 15:33:43 +0200 Subject: [PATCH 2/2] chore(pkg/driverbuilder): if envMap is nil, default at empty map. Signed-off-by: Federico Di Pierro --- pkg/driverbuilder/local.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/driverbuilder/local.go b/pkg/driverbuilder/local.go index 5fe28e5..c54bf94 100644 --- a/pkg/driverbuilder/local.go +++ b/pkg/driverbuilder/local.go @@ -38,6 +38,9 @@ func NewLocalBuildProcessor(useDKMS, downloadHeaders, printOnError bool, envMap map[string]string, timeout int, ) *LocalBuildProcessor { + if envMap == nil { + envMap = make(map[string]string) + } return &LocalBuildProcessor{ useDKMS: useDKMS, srcDir: srcDir,