From f9f8f35ccd8b505a827d40f95c52ed039512b79d Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Mon, 19 Aug 2024 19:41:01 +0800 Subject: Write documents of the program. Add README.md on the design of the whole program, and how its every part(listener, filter) works, finally how to compile and use them. Besides, notes.md records the things and technology learned in this program, such as how to read kernel src, how the pthread_create/fork/ clone syscall works on processes and threads, the techs used to make docker container works well, and books to be read. Good good study, day day up. --- listener/deal.go | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'listener/deal.go') diff --git a/listener/deal.go b/listener/deal.go index 70c2827..af65ff8 100644 --- a/listener/deal.go +++ b/listener/deal.go @@ -10,17 +10,8 @@ import ( "go.mongodb.org/mongo-driver/bson" ) -const ( - dbName string = "test" - pidColName string = "pids" - fdColName string = "fds" - fileColName string = "files" -) - -var pidCol, fdCol, fileCol mongoClient - func initPidCol() (err error) { - // TODO: 这里是否需要补全一下进程信息? + // 这里是否需要补全一下进程信息? dirs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", containerdPid)) if err != nil { return err @@ -41,6 +32,9 @@ func initPidCol() (err error) { process.Star = true } err = pidCol.InsertOne(process) + if err != nil { + return err + } } return nil } @@ -49,27 +43,6 @@ func deal() { defer wg.Done() var cooked Event var ok bool - var err error - - if err = pidCol.init(dbName, pidColName); err != nil { - fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err) - return - } - if err = initPidCol(); err != nil { - fmt.Fprintf(os.Stderr, "Err while initing pidcol: %v\n", err) - } - - if err = fdCol.init(dbName, fdColName); err != nil { - fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err) - return - } - if err = fileCol.init(dbName, fileColName); err != nil { - fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err) - } - - defer pidCol.Disconnect() - defer fdCol.Disconnect() - defer fileCol.Disconnect() for { cooked, ok = <-cookedChan -- cgit v1.2.3-70-g09d2