Skip to content

Commit

Permalink
fix incorrect systemd booted check
Browse files Browse the repository at this point in the history
Check for the directory /run/systemd/system, this is described in
sd_booted(3). Reading /proc/1/comm will fail when /proc is mounted
with the `hidepid=2` option.

[NO NEW TESTS NEEDED]

Fixes containers#16022

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Nov 7, 2022
1 parent 9e04bab commit 919678d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ var (
// RunsOnSystemd returns whether the system is using systemd
func RunsOnSystemd() bool {
runsOnSystemdOnce.Do(func() {
initCommand, err := os.ReadFile("/proc/1/comm")
// On errors, default to systemd
runsOnSystemd = err != nil || strings.TrimRight(string(initCommand), "\n") == "systemd"
// per sd_booted(3), check for this dir
fd, err := os.Stat("/run/systemd/system")
runsOnSystemd = err == nil && fd.IsDir()
})
return runsOnSystemd
}
Expand Down

0 comments on commit 919678d

Please sign in to comment.