Copyright 2018 The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package procfs

import (
	
	
	
	
)
Namespace represents a single namespace of a process.
type Namespace struct {
	Type  string // Namespace type.
	Inode uint32 // Inode number of the namespace. If two processes are in the same namespace their inodes will match.
}
Namespaces contains all of the namespaces that the process is contained in.
Namespaces reads from /proc/<pid>/ns to get the namespaces of which the process is a member.
func ( Proc) () (Namespaces, error) {
	,  := os.Open(.path("ns"))
	if  != nil {
		return nil, 
	}
	defer .Close()

	,  := .Readdirnames(-1)
	if  != nil {
		return nil, fmt.Errorf("failed to read contents of ns dir: %v", )
	}

	 := make(Namespaces, len())
	for ,  := range  {
		,  := os.Readlink(.path("ns", ))
		if  != nil {
			return nil, 
		}

		 := strings.SplitN(, ":", 2)
		if len() != 2 {
			return nil, fmt.Errorf("failed to parse namespace type and inode from '%v'", )
		}

		 := [0]
		,  := strconv.ParseUint(strings.Trim([1], "[]"), 10, 32)
		if  != nil {
			return nil, fmt.Errorf("failed to parse inode from '%v': %v", [1], )
		}

		[] = Namespace{, uint32()}
	}

	return , nil