diff --git a/CMakeLists.txt b/CMakeLists.txt index fed9335..eb25d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,10 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(cgproxy VERSION 0.14) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result") +add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-result -Wno-unused-parameter) + +# for clangd +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) option(with_execsnoop "enable program level proxy control feature, need bcc installed" ON) option(build_tools OFF) diff --git a/src/cgproxyd.hpp b/src/cgproxyd.hpp index 25c901f..7d81060 100644 --- a/src/cgproxyd.hpp +++ b/src/cgproxyd.hpp @@ -149,8 +149,7 @@ class cgproxyd { return MSG_ERROR; } - int type, status; - int pid, cgroup_target; + int type, status, pid; try { type = j.at("type").get(); switch (type) { diff --git a/src/socket_client.cpp b/src/socket_client.cpp index 26c25d3..94682b3 100644 --- a/src/socket_client.cpp +++ b/src/socket_client.cpp @@ -42,11 +42,7 @@ void send(const char *msg, int &status) { } void send(const string msg, int &status) { - int msg_len = msg.length(); - char buff[msg_len]; - msg.copy(buff, msg_len, 0); - buff[msg_len] = '\0'; - send(buff, status); + send(msg.c_str(), status); debug("return status: %d", status); } diff --git a/src/socket_server.cpp b/src/socket_server.cpp index 2081d8c..84fea34 100644 --- a/src/socket_server.cpp +++ b/src/socket_server.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace fs = std::filesystem; @@ -39,12 +40,13 @@ void SocketServer::socketListening(function callback, promise flag = read(cfd, &msg_len, sizeof(int)); continue_if_error(flag, "read length"); // read msg - char msg[msg_len]; + auto msg=(char*)malloc(msg_len+1); flag = read(cfd, msg, msg_len * sizeof(char)); continue_if_error(flag, "read msg"); msg[msg_len] = '\0'; // handle msg int status = callback(msg); + free(msg); // send back flag flag = write(cfd, &status, sizeof(int)); continue_if_error(flag, "write back");