diff options
author | We-unite <3205135446@qq.com> | 2024-08-19 19:41:01 +0800 |
---|---|---|
committer | We-unite <3205135446@qq.com> | 2024-08-22 14:12:01 +0800 |
commit | f9f8f35ccd8b505a827d40f95c52ed039512b79d (patch) | |
tree | 241c393f6b865958191df802cd112f26d40dddc4 /listener/deal.go | |
parent | ae4957b41156d576e849ec0424edd4d89d8d49f2 (diff) | |
download | godo-f9f8f35ccd8b505a827d40f95c52ed039512b79d.tar.gz godo-f9f8f35ccd8b505a827d40f95c52ed039512b79d.zip |
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.
Diffstat (limited to 'listener/deal.go')
-rw-r--r-- | listener/deal.go | 35 |
1 files changed, 4 insertions, 31 deletions
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 ( | |||
10 | "go.mongodb.org/mongo-driver/bson" | 10 | "go.mongodb.org/mongo-driver/bson" |
11 | ) | 11 | ) |
12 | 12 | ||
13 | const ( | ||
14 | dbName string = "test" | ||
15 | pidColName string = "pids" | ||
16 | fdColName string = "fds" | ||
17 | fileColName string = "files" | ||
18 | ) | ||
19 | |||
20 | var pidCol, fdCol, fileCol mongoClient | ||
21 | |||
22 | func initPidCol() (err error) { | 13 | func initPidCol() (err error) { |
23 | // TODO: 这里是否需要补全一下进程信息? | 14 | // 这里是否需要补全一下进程信息? |
24 | dirs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", containerdPid)) | 15 | dirs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", containerdPid)) |
25 | if err != nil { | 16 | if err != nil { |
26 | return err | 17 | return err |
@@ -41,6 +32,9 @@ func initPidCol() (err error) { | |||
41 | process.Star = true | 32 | process.Star = true |
42 | } | 33 | } |
43 | err = pidCol.InsertOne(process) | 34 | err = pidCol.InsertOne(process) |
35 | if err != nil { | ||
36 | return err | ||
37 | } | ||
44 | } | 38 | } |
45 | return nil | 39 | return nil |
46 | } | 40 | } |
@@ -49,27 +43,6 @@ func deal() { | |||
49 | defer wg.Done() | 43 | defer wg.Done() |
50 | var cooked Event | 44 | var cooked Event |
51 | var ok bool | 45 | var ok bool |
52 | var err error | ||
53 | |||
54 | if err = pidCol.init(dbName, pidColName); err != nil { | ||
55 | fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err) | ||
56 | return | ||
57 | } | ||
58 | if err = initPidCol(); err != nil { | ||
59 | fmt.Fprintf(os.Stderr, "Err while initing pidcol: %v\n", err) | ||
60 | } | ||
61 | |||
62 | if err = fdCol.init(dbName, fdColName); err != nil { | ||
63 | fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err) | ||
64 | return | ||
65 | } | ||
66 | if err = fileCol.init(dbName, fileColName); err != nil { | ||
67 | fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err) | ||
68 | } | ||
69 | |||
70 | defer pidCol.Disconnect() | ||
71 | defer fdCol.Disconnect() | ||
72 | defer fileCol.Disconnect() | ||
73 | 46 | ||
74 | for { | 47 | for { |
75 | cooked, ok = <-cookedChan | 48 | cooked, ok = <-cookedChan |