From 34e5d81329ff91fe4b0f5c5697d7d507cd41ddd9 Mon Sep 17 00:00:00 2001 From: springzfx Date: Sat, 30 May 2020 01:59:24 +0800 Subject: [PATCH] change status signal place --- src/execsnoop.cpp | 7 +++++-- src/execsnoop.h | 2 +- src/socket_server.cpp | 7 ++++--- src/socket_server.h | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/execsnoop.cpp b/src/execsnoop.cpp index c83ad31..189a3b3 100644 --- a/src/execsnoop.cpp +++ b/src/execsnoop.cpp @@ -48,6 +48,7 @@ struct data_t { }; function callback = NULL; +promise status; void handle_events(void *cb_cookie, void *data, int data_size) { auto event = static_cast(data); @@ -91,13 +92,15 @@ int execsnoop() { return 1; } + status.set_value(); + while (true) bpf.poll_perf_buffer("events"); return 0; } -void startThread(function c, promise status) { - status.set_value(); +void startThread(function c, promise _status) { + status = move(_status); callback = c; execsnoop(); } diff --git a/src/execsnoop.h b/src/execsnoop.h index 93eb22e..86783d7 100644 --- a/src/execsnoop.h +++ b/src/execsnoop.h @@ -14,7 +14,7 @@ extern function callback; void handle_events(void *cb_cookie, void *data, int data_size); int execsnoop(); -extern "C" void startThread(function c, promise status); +extern "C" void startThread(function c, promise _status); typedef void startThread_t(function, promise); startThread_t *_startThread; // only for dlsym() diff --git a/src/socket_server.cpp b/src/socket_server.cpp index f20a6ce..2081d8c 100644 --- a/src/socket_server.cpp +++ b/src/socket_server.cpp @@ -9,7 +9,7 @@ namespace fs = std::filesystem; namespace CGPROXY::SOCKET { -void SocketServer::socketListening(function callback) { +void SocketServer::socketListening(function callback, promise status) { debug("starting socket listening"); sfd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -26,6 +26,8 @@ void SocketServer::socketListening(function callback) { listen(sfd, LISTEN_BACKLOG); chmod(SOCKET_PATH, S_IRWXU | S_IRWXG | S_IRWXO); + status.set_value(); + while (true) { close(cfd); cfd = accept(sfd, NULL, NULL); @@ -56,9 +58,8 @@ SocketServer::~SocketServer() { } void startThread(function callback, promise status) { - status.set_value(); SocketServer server; - server.socketListening(callback); + server.socketListening(callback, move(status)); } } // namespace CGPROXY::SOCKET \ No newline at end of file diff --git a/src/socket_server.h b/src/socket_server.h index 166d503..bbd1c4a 100644 --- a/src/socket_server.h +++ b/src/socket_server.h @@ -20,7 +20,7 @@ public: int sfd = -1, cfd = -1, flag = -1; struct sockaddr_un unix_socket; - void socketListening(function callback); + void socketListening(function callback, promise status); ~SocketServer(); };