From 3650482b0905a0f46b47b44e13310a2f0dd2d1d6 Mon Sep 17 00:00:00 2001 From: henrygd Date: Fri, 14 Nov 2025 14:06:46 -0500 Subject: [PATCH] refactor: move getRootMountPoint to disk.go --- agent/agent.go | 37 ------------------------------------- agent/disk.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index d6bbae1e..75f51cbc 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -229,40 +229,3 @@ func (a *Agent) getFingerprint() string { return fingerprint } - -// getRootMountPoint returns the appropriate root mount point for the system -// For immutable systems like Fedora Silverblue, it returns /sysroot instead of / -func (a *Agent) getRootMountPoint() string { - // Check for typical immutable system indicators - // 1. Check if /etc/os-release contains indicators of an immutable system - if osReleaseContent, err := os.ReadFile("/etc/os-release"); err == nil { - content := string(osReleaseContent) - // Look for indicators of atomic/immutable systems - if strings.Contains(content, "fedora") && strings.Contains(content, "silverblue") || - strings.Contains(content, "coreos") || - strings.Contains(content, "flatcar") || - strings.Contains(content, "rhel-atomic") || - strings.Contains(content, "centos-atomic") { - // Verify that /sysroot exists before returning it - if _, err := os.Stat("/sysroot"); err == nil { - return "/sysroot" - } - } - } - - // 2. Check if /run/ostree is present (ostree-based systems like Silverblue) - if _, err := os.Stat("/run/ostree"); err == nil { - // Verify that /sysroot exists before returning it - if _, err := os.Stat("/sysroot"); err == nil { - return "/sysroot" - } - } - - return "/" -} - -// isImmutableSystem detects if the system is likely an immutable system like Fedora Silverblue -// where the real root filesystem is mounted at /sysroot instead of / -func (a *Agent) isImmutableSystem() bool { - return a.getRootMountPoint() != "/" -} diff --git a/agent/disk.go b/agent/disk.go index 4900311c..38f9ce0d 100644 --- a/agent/disk.go +++ b/agent/disk.go @@ -315,3 +315,32 @@ func (a *Agent) updateDiskIo(cacheTimeMs uint16, systemStats *system.Stats) { } } } + +// getRootMountPoint returns the appropriate root mount point for the system +// For immutable systems like Fedora Silverblue, it returns /sysroot instead of / +func (a *Agent) getRootMountPoint() string { + // 1. Check if /etc/os-release contains indicators of an immutable system + if osReleaseContent, err := os.ReadFile("/etc/os-release"); err == nil { + content := string(osReleaseContent) + if strings.Contains(content, "fedora") && strings.Contains(content, "silverblue") || + strings.Contains(content, "coreos") || + strings.Contains(content, "flatcar") || + strings.Contains(content, "rhel-atomic") || + strings.Contains(content, "centos-atomic") { + // Verify that /sysroot exists before returning it + if _, err := os.Stat("/sysroot"); err == nil { + return "/sysroot" + } + } + } + + // 2. Check if /run/ostree is present (ostree-based systems like Silverblue) + if _, err := os.Stat("/run/ostree"); err == nil { + // Verify that /sysroot exists before returning it + if _, err := os.Stat("/sysroot"); err == nil { + return "/sysroot" + } + } + + return "/" +}