set timeout for thread start

This commit is contained in:
springzfx
2020-05-30 02:16:44 +08:00
parent a1a1ed5bd9
commit 9b4ec44897
2 changed files with 13 additions and 5 deletions

View File

@@ -188,8 +188,12 @@ class cgproxyd {
thread th(SOCKET::startThread, handle_msg_static, move(status));
socketserver_thread = move(th);
status_f.wait();
info("socketserver thread started");
future_status fstatus=status_f.wait_for(chrono::seconds(THREAD_TIMEOUT));
if (fstatus == std::future_status::ready) {
info("socketserver thread started");
}else{
error("socketserver thread timeout, maybe failed");
}
}
void startExecsnoopThread() {
@@ -203,8 +207,12 @@ class cgproxyd {
thread th(EXECSNOOP::_startThread, handle_pid_static, move(status));
execsnoop_thread = move(th);
status_f.wait();
info("execsnoop thread started");
future_status fstatus=status_f.wait_for(chrono::seconds(THREAD_TIMEOUT));
if (fstatus == std::future_status::ready) {
info("execsnoop thread started");
}else{
error("execsnoop thread timeout, maybe failed");
}
}
void processRunningProgram() {

View File

@@ -20,7 +20,7 @@ using namespace std;
#define CGROUP_PROXY_PRESVERED "/proxy.slice"
#define CGROUP_NOPROXY_PRESVERED "/noproxy.slice"
#define THREAD_UNDEF 0
#define THREAD_TIMEOUT 5
#define MSG_TYPE_CONFIG_JSON 1
#define MSG_TYPE_CONFIG_PATH 2