refactor: small comment / structure updates

This commit is contained in:
henrygd
2026-01-05 16:25:30 -05:00
parent 6282794004
commit 3d970defe9
2 changed files with 13 additions and 20 deletions

View File

@@ -20,24 +20,6 @@ import (
var errNoActiveTime = errors.New("no active time")
// isSystemdAvailable checks if systemd is running as the init system (PID 1).
// This prevents unnecessary connection attempts on systems using other init systems
// like OpenRC, runit, or when running in containers without systemd.
func isSystemdAvailable() bool {
// Check if /run/systemd/system directory exists - this is a reliable indicator
// that systemd is running as the init system
if _, err := os.Stat("/run/systemd/system"); err == nil {
return true
}
// Fallback: check if PID 1 is systemd by reading /proc/1/comm
if data, err := os.ReadFile("/proc/1/comm"); err == nil {
return strings.TrimSpace(string(data)) == "systemd"
}
return false
}
// systemdManager manages the collection of systemd service statistics.
type systemdManager struct {
sync.Mutex
@@ -47,6 +29,17 @@ type systemdManager struct {
patterns []string
}
// isSystemdAvailable checks if systemd is used on the system to avoid unnecessary connection attempts.
func isSystemdAvailable() bool {
if _, err := os.Stat("/run/systemd/system"); err == nil {
return true
}
if data, err := os.ReadFile("/proc/1/comm"); err == nil {
return strings.TrimSpace(string(data)) == "systemd"
}
return false
}
// newSystemdManager creates a new systemdManager.
func newSystemdManager() (*systemdManager, error) {
if skipSystemd, _ := GetEnv("SKIP_SYSTEMD"); skipSystemd == "true" {