-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (45 loc) · 1.16 KB
/
main.cpp
File metadata and controls
57 lines (45 loc) · 1.16 KB
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
57
// user space code for test.bpf.c
#include <unordered_map>
#include <iostream>
#include <string>
#include <csignal>
#include "file_logs.h"
#include "ui.h"
#include "bpf_handling.h"
std::unordered_map<std::string, file_logs*> watchlist;
std::string op_map[] = {
"OPEN",
"WRITE",
"UNLINK",
"RENAME",
"CHMOD",
"CHOWN"
};
int running = 1;
void handle_signal(int sig) {
std::cout << "Received signal " << sig << ", shutting down..." << std::endl;
watchlist.clear();
running = 0;
}
int main() {
signal(SIGINT, handle_signal);
signal(SIGTERM, handle_signal);
// Start the polling loop in a separate thread
std::thread bpf_handler_thread(BPF_Handler::load_and_attach_bpf);
// Start the UI loop
std::thread ui_thread(UserInterface::game_loop);
// Cleanup
if (bpf_handler_thread.joinable()) {
bpf_handler_thread.join();
}
if (ui_thread.joinable()) {
ui_thread.join();
}
for (const auto& [path, logs] : watchlist) {
logs->clear_logs();
delete logs; // Free memory
}
watchlist.clear();
std::cout << "Exiting Safely..." << std::endl;
return 0;
}