-
Notifications
You must be signed in to change notification settings - Fork 76
/
main.go
56 lines (46 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"ehids/user"
"github.com/cilium/ebpf/rlimit"
_ "github.com/shuLhan/go-bindata"
"log"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
// Allow the current process to lock memory for eBPF resources.
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
stopper := make(chan os.Signal, 1)
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
ctx, cancelFun := context.WithCancel(context.TODO())
logger := log.Default()
logger.Println("https://github.com/ehids/ehids-agent")
logger.Printf("process pid: %d\n", os.Getpid())
for k, module := range user.GetModules() {
if module.Name() != "EBPFProbeBPFCall" {
//continue //模块启用临时开关
}
logger.Printf("start to run %s module", k)
//初始化
err := module.Init(ctx, logger)
if err != nil {
panic(err)
}
// 加载ebpf,挂载到hook点上,开始监听
go func(module user.IModule) {
err := module.Run()
if err != nil {
logger.Printf("%v\n", err)
}
}(module)
}
<-stopper
cancelFun()
logger.Println("Received signal, exiting program..")
time.Sleep(time.Millisecond * 100)
}