mirror of
https://github.com/springzfx/cgproxy.git
synced 2026-04-23 10:11:04 +08:00
execsnoop as library
This commit is contained in:
@@ -3,12 +3,17 @@ find_package(nlohmann_json REQUIRED)
|
|||||||
include_directories(${PROJECT_SOURCE_DIR})
|
include_directories(${PROJECT_SOURCE_DIR})
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
add_library(optional SHARED optional.cpp execsnoop.cpp)
|
||||||
|
target_link_libraries(optional bcc)
|
||||||
|
install(TARGETS optional DESTINATION /usr/lib/cgproxy/ PERMISSIONS ${basic_permission})
|
||||||
|
|
||||||
add_executable(main main.cpp
|
add_executable(main main.cpp
|
||||||
common.cpp config.cpp cgroup_attach.cpp
|
common.cpp config.cpp cgroup_attach.cpp
|
||||||
socket_client.cpp socket_server.cpp)
|
socket_client.cpp socket_server.cpp)
|
||||||
|
|
||||||
target_link_libraries(main nlohmann_json::nlohmann_json Threads::Threads bcc)
|
target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json Threads::Threads)
|
||||||
|
target_link_libraries(main PRIVATE optional)
|
||||||
set_target_properties(main PROPERTIES LINKER_LANGUAGE CXX)
|
set_target_properties(main PROPERTIES LINKER_LANGUAGE CXX)
|
||||||
set_target_properties(main PROPERTIES OUTPUT_NAME cgproxy)
|
set_target_properties(main PROPERTIES OUTPUT_NAME cgproxy)
|
||||||
|
|
||||||
install(TARGETS main DESTINATION /usr/bin PERMISSIONS ${basic_permission})
|
install(TARGETS main DESTINATION /usr/bin PERMISSIONS ${basic_permission})
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "cgroup_attach.h"
|
#include "cgroup_attach.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "execsnoop.hpp"
|
|
||||||
#include "socket_server.h"
|
#include "socket_server.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
@@ -15,6 +14,7 @@
|
|||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "optional.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
#ifndef EXECSNOOP_HPP
|
|
||||||
#define EXECSNOOP_HPP 1
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include "bcc/BPF.h"
|
#include "bcc/BPF.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <bcc/libbpf.h>
|
#include <bcc/libbpf.h>
|
||||||
@@ -93,19 +89,4 @@ int execsnoop() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct thread_arg {
|
} // namespace CGPROXY::EXESNOOP
|
||||||
function<int(int)> handle_pid;
|
|
||||||
};
|
|
||||||
|
|
||||||
void *startThread(void *arg) {
|
|
||||||
thread_arg *p = (thread_arg *)arg;
|
|
||||||
callback = p->handle_pid;
|
|
||||||
try {
|
|
||||||
execsnoop();
|
|
||||||
} catch (exception &e) {
|
|
||||||
error("bcc may not be installed, %s",e.what());
|
|
||||||
}
|
|
||||||
return (void *)0;
|
|
||||||
}
|
|
||||||
} // namespace CGPROXY::EXESNOOP
|
|
||||||
#endif
|
|
||||||
17
src/execsnoop.h
Normal file
17
src/execsnoop.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef EXECSNOOP_HPP
|
||||||
|
#define EXECSNOOP_HPP 1
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace CGPROXY::EXESNOOP {
|
||||||
|
|
||||||
|
extern const string BPF_PROGRAM;
|
||||||
|
struct data_t;
|
||||||
|
extern function<int(int)> callback;
|
||||||
|
void handle_events(void *cb_cookie, void *data, int data_size);
|
||||||
|
int execsnoop();
|
||||||
|
|
||||||
|
} // namespace CGPROXY::EXESNOOP
|
||||||
|
#endif
|
||||||
14
src/optional.cpp
Normal file
14
src/optional.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include "optional.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include "execsnoop.h"
|
||||||
|
|
||||||
|
namespace CGPROXY::EXESNOOP {
|
||||||
|
|
||||||
|
void *startThread(void *arg) {
|
||||||
|
thread_arg *p = (thread_arg *)arg;
|
||||||
|
callback = p->handle_pid;
|
||||||
|
execsnoop();
|
||||||
|
return (void *)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
src/optional.h
Normal file
16
src/optional.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef OPTIONAL_H
|
||||||
|
#define OPTIONAL_H 1
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace CGPROXY::EXESNOOP {
|
||||||
|
|
||||||
|
struct thread_arg {
|
||||||
|
function<int(int)> handle_pid;
|
||||||
|
};
|
||||||
|
void *startThread(void *arg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user