mirror of
https://github.com/springzfx/cgproxy.git
synced 2026-04-23 10:11:04 +08:00
check again after small period(100ms) to avoid kde cgroup override
This commit is contained in:
@@ -103,8 +103,13 @@ class cgproxyd {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!belongToCgroup(cg, config.cgroup_noproxy)) {
|
if (!belongToCgroup(cg, config.cgroup_noproxy)) {
|
||||||
info("execsnoop; noproxy: %d %s", pid, path.get());
|
int res = attach(pid, config.cgroup_noproxy_preserved);
|
||||||
return attach(pid, config.cgroup_noproxy_preserved);
|
if (res == 0) {
|
||||||
|
info("execsnoop; noproxy: %d %s", pid, path.get());
|
||||||
|
} else {
|
||||||
|
info("execsnoop; noproxy failed: %d %s", pid, path.get());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +127,13 @@ class cgproxyd {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!belongToCgroup(cg, config.cgroup_proxy)) {
|
if (!belongToCgroup(cg, config.cgroup_proxy)) {
|
||||||
info("execsnoop: proxied: %d %s", pid, path.get());
|
int res = attach(pid, config.cgroup_proxy_preserved);
|
||||||
return attach(pid, config.cgroup_proxy_preserved);
|
if (res == 0) {
|
||||||
|
info("execsnoop: proxied: %d %s", pid, path.get());
|
||||||
|
} else {
|
||||||
|
info("execsnoop: proxied failed: %d %s", pid, path.get());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <thread>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace CGPROXY::CGROUP {
|
namespace CGPROXY::CGROUP {
|
||||||
@@ -68,9 +69,19 @@ int attach(const string pid, const string cgroup_target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// put pid to target cgroup
|
// put pid to target cgroup
|
||||||
ofstream procs(cgroup_target_procs, ofstream::app);
|
if (write2procs(pid, cgroup_target_procs) != 0) return_error;
|
||||||
|
|
||||||
|
// wait for small period and check again
|
||||||
|
this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
if (getCgroup(pid) != cgroup_target && write2procs(pid, cgroup_target_procs) != 0)
|
||||||
|
return_error;
|
||||||
|
return_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write2procs(string pid, string procspath) {
|
||||||
|
ofstream procs(procspath, ofstream::app);
|
||||||
if (!procs.is_open()) {
|
if (!procs.is_open()) {
|
||||||
error("open file %s failed", cgroup_target_procs.c_str());
|
error("open file %s failed", procspath.c_str());
|
||||||
return_error;
|
return_error;
|
||||||
}
|
}
|
||||||
procs << pid.c_str() << endl;
|
procs << pid.c_str() << endl;
|
||||||
@@ -79,7 +90,7 @@ int attach(const string pid, const string cgroup_target) {
|
|||||||
// maybe there some write error, for example process pid may not exist
|
// maybe there some write error, for example process pid may not exist
|
||||||
if (!procs) {
|
if (!procs) {
|
||||||
error("write %s to %s failed, maybe process %s not exist", pid.c_str(),
|
error("write %s to %s failed, maybe process %s not exist", pid.c_str(),
|
||||||
cgroup_target_procs.c_str(), pid.c_str());
|
procspath.c_str(), pid.c_str());
|
||||||
return_error;
|
return_error;
|
||||||
}
|
}
|
||||||
return_success;
|
return_success;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ bool validate(string pid, string cgroup);
|
|||||||
string get_cgroup2_mount_point();
|
string get_cgroup2_mount_point();
|
||||||
int attach(const string pid, const string cgroup_target);
|
int attach(const string pid, const string cgroup_target);
|
||||||
int attach(const int pid, const string cgroup_target);
|
int attach(const int pid, const string cgroup_target);
|
||||||
|
int write2procs(string pid, string procspath);
|
||||||
|
|
||||||
} // namespace CGPROXY::CGROUP
|
} // namespace CGPROXY::CGROUP
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ string getCgroup(const string &pid) {
|
|||||||
ifstream ifs(cgroup_f);
|
ifstream ifs(cgroup_f);
|
||||||
debug("prcessing file %s", cgroup_f.c_str());
|
debug("prcessing file %s", cgroup_f.c_str());
|
||||||
while (ifs.good() && getline(ifs, line)) {
|
while (ifs.good() && getline(ifs, line)) {
|
||||||
debug("process line: %s", line.c_str());
|
// debug("process line: %s", line.c_str());
|
||||||
if (line[0] == '0') {
|
if (line[0] == '0') {
|
||||||
cgroup = line.substr(3);
|
cgroup = line.substr(3);
|
||||||
debug("get cgroup of %s: %s", pid.c_str(), cgroup.c_str());
|
debug("get cgroup of %s: %s", pid.c_str(), cgroup.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user