Skip to content

Commit

Permalink
mountinfo: add GetMountsForPID, deprecate PidMountInfo
Browse files Browse the repository at this point in the history
Function PidMountInfo is not named correctly (it should be PID not Pid,
and we already have mountinfo in the package name so it's tautological),
and can not accept FilterFunc.

Introduce GetMountsForPid, and deprecate PidMountInfo.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Oct 2, 2020
1 parent 9cdf5ed commit 3c9a928
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mountinfo/mountinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,28 @@ func parseMountTable(filter FilterFunc) ([]*Info, error) {
return GetMountsFromReader(f, filter)
}

// PidMountInfo collects the mounts for a specific process ID. If the process
// ID is unknown, it is better to use `GetMounts` which will inspect
// "/proc/self/mountinfo" instead.
func PidMountInfo(pid int) ([]*Info, error) {
// GetMountsForPID retrieves the list of mounts from a given process' mount
// namespace. Unless there is a need to get mounts from a mount namespace
// different from that of a calling process, use GetMounts.
//
// This function is Linux-specific.
func GetMountsForPID(pid int, filter FilterFunc) ([]*Info, error) {
f, err := os.Open(fmt.Sprintf("/proc/%d/mountinfo", pid))
if err != nil {
return nil, err
}
defer f.Close()

return GetMountsFromReader(f, nil)
return GetMountsFromReader(f, filter)
}

// PidMountInfo collects the mounts for a specific process ID. If the process
// ID is unknown, it is better to use `GetMounts` which will inspect
// "/proc/self/mountinfo" instead.
//
// Deprecated: this will be removed before v1; use GetMountsForPID instead.
func PidMountInfo(pid int) ([]*Info, error) {
return GetMountsForPID(pid, nil)
}

// A few specific characters in mountinfo path entries (root and mountpoint)
Expand Down

0 comments on commit 3c9a928

Please sign in to comment.