4 Star 1 Fork 0

Gitee 极速下载/netlink

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/vishvananda/netlink
克隆/下载
proc_event_test.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
Aditi Ghag 提交于 2022-01-25 09:49 . Fix darwin target compilation
// +build linux
package netlink
import (
"github.com/vishvananda/netns"
"os"
"os/exec"
"runtime"
"testing"
)
func TestSubscribeProcEvent(t *testing.T) {
skipUnlessRoot(t)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
pid1ns, err := netns.GetFromPid(1)
if err != nil {
panic(err)
}
err = netns.Set(pid1ns)
if err != nil {
panic(err)
}
ch := make(chan ProcEvent)
done := make(chan struct{})
defer close(done)
errChan := make(chan error)
if err := ProcEventMonitor(ch, done, errChan); err != nil {
t.Fatal(err)
}
cmd := exec.Command("false")
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
// first we wait for proc - i.e. childTgid is cmd.Process.Pid
for {
e := <-ch
t.Logf("pid: %+v e: %+v", os.Getpid(), e)
if e.Msg.Tgid() == uint32(os.Getpid()) {
if forkEvent, ok := e.Msg.(*ForkProcEvent); ok {
if forkEvent.ChildTgid == uint32(cmd.Process.Pid) {
break
}
}
}
}
// wait for exec event
for {
e := <-ch
if e.Msg.Tgid() == uint32(cmd.Process.Pid) {
if _, ok := e.Msg.(*ExecProcEvent); ok {
break
}
}
}
cmd.Wait()
for {
e := <-ch
if e.Msg.Tgid() == uint32(cmd.Process.Pid) {
if exitEvent, ok := e.Msg.(*ExitProcEvent); ok {
if exitEvent.ExitCode != 256 {
t.Errorf("Expected error code 256 (-1), but got %+v", exitEvent)
}
break
}
}
}
done <- struct{}{}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/netlink.git
[email protected]:mirrors/netlink.git
mirrors
netlink
netlink
main

搜索帮助