* IDState cleaned up. Should work on all *NIXes now. * Can now get IDState of arbitrary PID. * Shuffled some env stuff around.
33 lines
595 B
Go
33 lines
595 B
Go
package sysutils
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"r00t2.io/sysutils/errs"
|
|
)
|
|
|
|
// NsToInode splits a Linux namespace identifier (e.g. `net:[12345]`) to its type (e.g. `net`) and inode (e.g. `12345`).
|
|
func NsToInode(ns string) (typ string, inode uint64, err error) {
|
|
|
|
var fields []string
|
|
|
|
fields = strings.SplitN(ns, ":", 2)
|
|
|
|
if len(fields) != 2 {
|
|
err = errs.ErrInvalidNs
|
|
return
|
|
}
|
|
|
|
fields[1] = strings.TrimPrefix(fields[1], "[")
|
|
fields[1] = strings.TrimSuffix(fields[1], "]")
|
|
|
|
if inode, err = strconv.ParseUint(fields[1], 10, 64); err != nil {
|
|
return
|
|
}
|
|
|
|
typ = fields[0]
|
|
|
|
return
|
|
}
|