Files
podman/vendor/github.com/containers/psgo/internal/proc/attr.go
Valentin Rothberg 159f7f179b vendor latest containers/psgo
Signed-off-by: Valentin Rothberg <vrothberg@suse.com>

Closes: #1162
Approved by: rhatdan
2018-07-26 17:01:40 +00:00

25 lines
568 B
Go

package proc
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
// ParseAttrCurrent returns the contents of /proc/$pid/attr/current of "?" if
// labeling is not supported on the host.
func ParseAttrCurrent(pid string) (string, error) {
data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%s/attr/current", pid))
if err != nil {
_, err = os.Stat(fmt.Sprintf("/proc/%s", pid))
if os.IsNotExist(err) {
// PID doesn't exist
return "", err
}
// PID exists but labeling seems to be unsupported
return "?", nil
}
return strings.Trim(string(data), "\n"), nil
}