aboutsummaryrefslogtreecommitdiffstats
path: root/src/godo.go
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-08-06 14:31:31 +0800
committerWe-unite <3205135446@qq.com>2024-08-06 14:31:31 +0800
commitf4655e64a1461c22ad7a3871375269915a743f40 (patch)
tree535e8d77431337bc431df85cfc2b675464395879 /src/godo.go
parent78de56b9f2d862bbdac8a02a72dd95500b7ef83e (diff)
downloadgodo-f4655e64a1461c22ad7a3871375269915a743f40.tar.gz
godo-f4655e64a1461c22ad7a3871375269915a743f40.zip
Expand connector buffer, put all file info into db
This commit I make several changes, reasons are as follows: - Expand netlink connector buffer size. Originally it uses only one page of mem, but sometimes it causes "no enough buffer" errno, or the socket is blocked long time. Now it's 20 pages. - All file infos are thrown into database. As the last commit co- mment, There's 2 tables, "fds" and "files". When a file discriptor is closed, the info in fds will be found, delete, and put into the "file" table with its close time. Left questions: - The netlink connector is always found blocked without any reasons. Fix it, or replace the golang-coded connector with C program? The key is why it's blocked. Maybe it's in the kernel src code. - sometimes audit still losts info(not too much). For instance, I use vim in the docker to change hello.c, the hello.c may be opened but no close info recvd. Or, the swap file of vim, such as .hello.c.swp or .hello.c.swx is not closed. What's more, the hello.c is never written, but swap files are. May vim write to swap files, and replace the origin file? Let's check it. - Besides, when a pid exits, we should check its file discriptors and close them all.
Diffstat (limited to 'src/godo.go')
-rw-r--r--src/godo.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/godo.go b/src/godo.go
index 77e677c..923ef85 100644
--- a/src/godo.go
+++ b/src/godo.go
@@ -44,14 +44,14 @@ func main() {
44 var auditCmd *exec.Cmd 44 var auditCmd *exec.Cmd
45 45
46 pidSyscall := []string{"execve"} 46 pidSyscall := []string{"execve"}
47 // 设置监听规则 47 // // 设置监听规则
48 for i := 0; i < len(pidSyscall); i++ { 48 for i := 0; i < len(pidSyscall); i++ {
49 auditCmd = exec.Command("auditctl", "-a", "exit,always", "-F", "arch=b64", "-S", pidSyscall[i]) 49 auditCmd = exec.Command("auditctl", "-a", "exit,always", "-F", "arch=b64", "-S", pidSyscall[i])
50 auditCmd.Run() 50 auditCmd.Run()
51 } 51 }
52 52
53 // 监听文件的消息 53 // 监听文件的消息
54 fileSyscall := []string{"open", "write", "close"} 54 fileSyscall := []string{"open", "close", "write"}
55 // fileSyscall := []string{"open", "write", "creat", "unlink", "opendir", "mkdir", "rmdir", "chmod", "fchmod", "chown", "fchown", "lchown", "flock"} 55 // fileSyscall := []string{"open", "write", "creat", "unlink", "opendir", "mkdir", "rmdir", "chmod", "fchmod", "chown", "fchown", "lchown", "flock"}
56 for i := 0; i < len(fileSyscall); i++ { 56 for i := 0; i < len(fileSyscall); i++ {
57 auditCmd = exec.Command("auditctl", "-a", "exit,always", "-F", "arch=b64", "-S", fileSyscall[i]) 57 auditCmd = exec.Command("auditctl", "-a", "exit,always", "-F", "arch=b64", "-S", fileSyscall[i])
@@ -106,7 +106,7 @@ func procWatch() error {
106 } 106 }
107 defer ns.Close() 107 defer ns.Close()
108 for { 108 for {
109 res, err := ns.Receive() 109 res, err := ns.Receive(20)
110 if err != nil { 110 if err != nil {
111 fmt.Printf("Error recv: %v\n", err) 111 fmt.Printf("Error recv: %v\n", err)
112 continue 112 continue