@@ -31,6 +31,8 @@ import (
3131
3232 "github.com/alecthomas/kingpin/v2"
3333 "golang.org/x/sys/unix"
34+
35+ "github.com/prometheus/procfs"
3436)
3537
3638const (
@@ -179,25 +181,27 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger *slog.Lo
179181}
180182
181183func mountPointDetails (logger * slog.Logger ) ([]filesystemLabels , error ) {
182- file , err := os .Open (procFilePath ("1/mountinfo" ))
184+ fs , err := procfs .NewFS (* procPath )
185+ if err != nil {
186+ return nil , fmt .Errorf ("failed to open procfs: %w" , err )
187+ }
188+ mountInfo , err := fs .GetProcMounts (1 )
183189 if errors .Is (err , os .ErrNotExist ) {
184190 // Fallback to `/proc/self/mountinfo` if `/proc/1/mountinfo` is missing due hidepid.
185191 logger .Debug ("Reading root mounts failed, falling back to self mounts" , "err" , err )
186- file , err = os . Open ( procFilePath ( "self/mountinfo" ) )
192+ mountInfo , err = fs . GetMounts ( )
187193 }
188194 if err != nil {
189195 return nil , err
190196 }
191- defer file .Close ()
192197
193198 return parseFilesystemLabels (file )
194199}
195200
196- func parseFilesystemLabels (r io. Reader ) ([]filesystemLabels , error ) {
201+ func parseFilesystemLabels (mountInfo [] * procfs. MountInfo ) ([]filesystemLabels , error ) {
197202 var filesystems []filesystemLabels
198203
199- scanner := bufio .NewScanner (r )
200- for scanner .Scan () {
204+ for mount in range mountInfo {
201205 parts := strings .Fields (scanner .Text ())
202206
203207 if len (parts ) < 11 {
0 commit comments