func TestSysctlRaw(t *testing.T) { if runtime.GOOS == "openbsd" { t.Skip("kern.proc.pid does not exist on OpenBSD") } _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid()) if err != nil { t.Fatal(err) } }
func init() { pid = unix.Getpid() pgid, _ = unix.Getpgid(pid) ppid = unix.Getppid() for _, fd := range []int{unix.Stdin, unix.Stdout, unix.Stderr} { if isatty.IsTerminal(uintptr(fd)) { terminal = fd } } }
func makeNetworkNS(containerID string) string { namespace := "/var/run/netns/" + containerID pid := unix.Getpid() tid := unix.Gettid() err := os.MkdirAll("/var/run/netns", 0600) Expect(err).NotTo(HaveOccurred()) runtime.LockOSThread() defer runtime.UnlockOSThread() go (func() { defer GinkgoRecover() err = unix.Unshare(unix.CLONE_NEWNET) Expect(err).NotTo(HaveOccurred()) fd, err := os.Create(namespace) Expect(err).NotTo(HaveOccurred()) defer fd.Close() err = unix.Mount("/proc/self/ns/net", namespace, "none", unix.MS_BIND, "") Expect(err).NotTo(HaveOccurred()) })() Eventually(namespace).Should(BeAnExistingFile()) fd, err := unix.Open(fmt.Sprintf("/proc/%d/task/%d/ns/net", pid, tid), unix.O_RDONLY, 0) Expect(err).NotTo(HaveOccurred()) defer unix.Close(fd) _, _, e1 := unix.Syscall(unix.SYS_SETNS, uintptr(fd), uintptr(unix.CLONE_NEWNET), 0) Expect(e1).To(BeZero()) return namespace }
func allNetNSInCurrentProcess() []string { pid := unix.Getpid() paths, err := filepath.Glob(fmt.Sprintf("/proc/%d/task/*/ns/net", pid)) Expect(err).NotTo(HaveOccurred()) return paths }
func currentNetNSPath() string { pid := unix.Getpid() tid := unix.Gettid() return fmt.Sprintf("/proc/%d/task/%d/ns/net", pid, tid) }
func TestSysctlRaw(t *testing.T) { _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid()) if err != nil { t.Fatal(err) } }