From f4655e64a1461c22ad7a3871375269915a743f40 Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Tue, 6 Aug 2024 14:31:31 +0800 Subject: 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. --- src/godo.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/godo.go') 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() { var auditCmd *exec.Cmd pidSyscall := []string{"execve"} - // 设置监听规则 + // // 设置监听规则 for i := 0; i < len(pidSyscall); i++ { auditCmd = exec.Command("auditctl", "-a", "exit,always", "-F", "arch=b64", "-S", pidSyscall[i]) auditCmd.Run() } // 监听文件的消息 - fileSyscall := []string{"open", "write", "close"} + fileSyscall := []string{"open", "close", "write"} // fileSyscall := []string{"open", "write", "creat", "unlink", "opendir", "mkdir", "rmdir", "chmod", "fchmod", "chown", "fchown", "lchown", "flock"} for i := 0; i < len(fileSyscall); i++ { auditCmd = exec.Command("auditctl", "-a", "exit,always", "-F", "arch=b64", "-S", fileSyscall[i]) @@ -106,7 +106,7 @@ func procWatch() error { } defer ns.Close() for { - res, err := ns.Receive() + res, err := ns.Receive(20) if err != nil { fmt.Printf("Error recv: %v\n", err) continue -- cgit v1.2.3-70-g09d2