@@ -235,9 +235,10 @@ var fsTypeMap = map[int64]string{
235
235
ZFS_SUPER_MAGIC : "zfs" , /* 0x2FC12FC1 local */
236
236
}
237
237
238
- // readMountFile reads mountinfo or mounts file under /proc/1 or /proc/self
238
+ // readMountFile reads mountinfo or mounts file under the specified root path
239
+ // (eg, /proc/1, /proc/self, etc)
239
240
func readMountFile (root string ) (lines []string , useMounts bool , filename string , err error ) {
240
- filename = common . HostProc ( path .Join (root , "mountinfo" ) )
241
+ filename = path .Join (root , "mountinfo" )
241
242
lines , err = common .ReadLines (filename )
242
243
if err != nil {
243
244
var pathErr * os.PathError
@@ -246,7 +247,7 @@ func readMountFile(root string) (lines []string, useMounts bool, filename string
246
247
}
247
248
// if kernel does not support 1/mountinfo, fallback to 1/mounts (<2.6.26)
248
249
useMounts = true
249
- filename = common . HostProc ( path .Join (root , "mounts" ) )
250
+ filename = path .Join (root , "mounts" )
250
251
lines , err = common .ReadLines (filename )
251
252
if err != nil {
252
253
return
@@ -257,10 +258,22 @@ func readMountFile(root string) (lines []string, useMounts bool, filename string
257
258
}
258
259
259
260
func PartitionsWithContext (ctx context.Context , all bool ) ([]PartitionStat , error ) {
260
- lines , useMounts , filename , err := readMountFile ("1" )
261
+ // by default, try "/proc/1/..." first
262
+ root := common .HostProc (path .Join ("1" ))
263
+
264
+ // force preference for dirname of HOST_PROC_MOUNTINFO, if set #1271
265
+ hpmPath := os .Getenv ("HOST_PROC_MOUNTINFO" )
266
+ if hpmPath != "" {
267
+ root = filepath .Dir (hpmPath )
268
+ }
269
+
270
+ lines , useMounts , filename , err := readMountFile (root )
261
271
if err != nil {
262
- // fallback to "/proc/self/mountinfo" #1159
263
- lines , useMounts , filename , err = readMountFile ("self" )
272
+ if hpmPath != "" { // don't fallback with HOST_PROC_MOUNTINFO
273
+ return nil , err
274
+ }
275
+ // fallback to "/proc/self/..." #1159
276
+ lines , useMounts , filename , err = readMountFile (common .HostProc (path .Join ("self" )))
264
277
if err != nil {
265
278
return nil , err
266
279
}
0 commit comments