简体   繁体   中英

golang read files in linux with parent process namespace

I have used the setns system call in linux to set the current go process's NET namespace. This namespace changes the way /sys/class/net appears to the current process. However, If I try to view these files with the golang apis, I see only the parent's view (not namespaced). I think this is because go is forking without inheriting the parent's namespace. How can I read the files in /sys/class/net with go such that the setns system call persists in the child who is reading the file.

turns out this a known 'wontfix' issue in go: https://github.com/golang/go/issues/8676

the workaround I found was to use cgo to fork in ac function exposed to go runtime and then call setns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM