Skip to content

Commit

Permalink
Merge pull request #3641 from twz123/sysinfo-fix-path-check
Browse files Browse the repository at this point in the history
Fix "executable in PATH" sysprobe
  • Loading branch information
twz123 authored Oct 26, 2023
2 parents 952d5be + c2d5e87 commit 297ea42
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 @@ -39,7 +39,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 297ea42

Please sign in to comment.