Skip to content

Commit

Permalink
Fix "executable in PATH" sysprobe
Browse files Browse the repository at this point in the history
The loop over the varargs was not capturing the loop variable correctly,
so all the probes would check the same binary. Remove the loop and let
callers call the function multiple times for each executable. This is
less error prone. That bug was first introduced in 0f474b8, but didn't
become effective before 0f474b8.

Fixes: 0f474b8 ("Some new sysinfo probes")
Fixes: 19c800d ("Add sysprobe and some docs for required mount/umount")
Signed-off-by: Tom Wieczorek <[email protected]>
(cherry picked from commit c2d5e87)
  • Loading branch information
twz123 authored and github-actions[bot] committed Oct 26, 2023
1 parent 5b393b3 commit e4057ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion docs/raspberry-pi4.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ Operating system: Linux (pass)
Linux kernel release: 5.15.0-1013-raspi (pass)
Max. file descriptors per process: current: 1024 / max: 1048576 (warning: < 65536)
AppArmor: unavailable (pass)
Executable in path: modprobe: /usr/sbin/modprobe (pass)
Executable in PATH: modprobe: /usr/sbin/modprobe (pass)
Executable in PATH: mount: /usr/bin/mount (pass)
Executable in PATH: umount: /usr/bin/umount (pass)
/proc file system: mounted (0x9fa0) (pass)
Control Groups: version 2 (pass)
cgroup controller "cpu": available (pass)
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/sysinfo/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func (s *K0sSysinfoSpec) addHostSpecificProbes(p probes.Probes) {
linux.AssertAppArmor()

if s.WorkerRoleEnabled {
probes.AssertExecutablesInPath(linux, "modprobe", "mount", "umount")
probes.AssertExecutableInPath(linux, "modprobe")
probes.AssertExecutableInPath(linux, "mount")
probes.AssertExecutableInPath(linux, "umount")
linux.RequireProcFS()
addCgroups(linux)
}
Expand Down
22 changes: 10 additions & 12 deletions internal/pkg/sysinfo/probes/executables.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ import (
"os/exec"
)

func AssertExecutablesInPath(p Probes, executables ...string) {
for _, executable := range executables {
p.Set(fmt.Sprintf("executableInPath:%s", executable), func(path ProbePath, _ Probe) Probe {
return ProbeFn(func(r Reporter) error {
desc := NewProbeDesc(fmt.Sprintf("Executable in path: %s", executable), path)
path, err := exec.LookPath(executable)
if err != nil {
return r.Warn(desc, ErrorProp(err), "")
}
func AssertExecutableInPath(p Probes, executable string) {
p.Set(fmt.Sprintf("executableInPath:%s", executable), func(path ProbePath, _ Probe) Probe {
return ProbeFn(func(r Reporter) error {
desc := NewProbeDesc(fmt.Sprintf("Executable in PATH: %s", executable), path)
path, err := exec.LookPath(executable)
if err != nil {
return r.Warn(desc, ErrorProp(err), "")
}

return r.Pass(desc, StringProp(path))
})
return r.Pass(desc, StringProp(path))
})
}
})
}

0 comments on commit e4057ba

Please sign in to comment.