* IDState cleaned up. Should work on all *NIXes now.
* Can now get IDState of arbitrary PID.
* Shuffled some env stuff around.
This commit is contained in:
brent saner
2025-11-07 23:11:47 -05:00
parent 675a10addd
commit 803be548cf
16 changed files with 434 additions and 296 deletions

32
funcs.go Normal file
View File

@@ -0,0 +1,32 @@
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
}