From 891fdcfc93cd6f63f3c61904f4cc832b5e19dc0a Mon Sep 17 00:00:00 2001 From: fancy Date: Wed, 22 Apr 2020 20:06:01 +0800 Subject: [PATCH] fix typo, and clang-format cpp --- cgattach.cpp | 141 ++++++++++++++++++++++++----------------------- cgproxy.conf | 3 +- readme.md | 7 +-- run_in_cgroup.sh | 2 +- 4 files changed, 77 insertions(+), 76 deletions(-) diff --git a/cgattach.cpp b/cgattach.cpp index ff087b9..06f1102 100644 --- a/cgattach.cpp +++ b/cgattach.cpp @@ -1,80 +1,83 @@ -#include +#include #include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include +#include using namespace std; -void print_usage(){ - fprintf(stderr, "usage: cgattach \n"); +void print_usage() { fprintf(stderr, "usage: cgattach \n"); } + +bool exist(string path) { + struct stat st; + if (stat(path.c_str(), &st) != -1) { + return S_ISDIR(st.st_mode); + } + return false; } -bool exist(string path){ - struct stat st; - if (stat(path.c_str(),&st)!=-1){ - return S_ISDIR(st.st_mode); - } - return false; +bool validate(string pid, string cgroup) { + bool pid_v = regex_match(pid, regex("^[0-9]+$")); + bool cg_v = regex_match(cgroup, regex("^\\/[a-zA-Z0-9\\-_./@]+$")); + if (pid_v && cg_v) + return true; + // cout< @@ -89,7 +89,6 @@ v2ray_so_mark=255 table=100 mark=100 mark_newin=1 -v2ray_so_mark=255 ``` If you changed config, remember to restart service @@ -111,9 +110,9 @@ sudo systemctl restart cgproxy.service - `run_in_cgroup` run command in specific cgroup which will create if not exist , cgroup can be only one level down exist cgroup, otherwise created fail. ```bash - run_in_cgroup --cggroup=CGROUP + run_in_cgroup --cgroup=CGROUP # example - run_in_cgroup --cggroup=/mycgroup.slice ping 127.0.0.1 + run_in_cgroup --cgroup=/mycgroup.slice ping 127.0.0.1 ``` diff --git a/run_in_cgroup.sh b/run_in_cgroup.sh index d1a9530..f15c900 100644 --- a/run_in_cgroup.sh +++ b/run_in_cgroup.sh @@ -3,7 +3,7 @@ print_help(){ cat << 'DOC' usage: - run_in_cgroup --cggroup=CGROUP + run_in_cgroup --cgroup=CGROUP run_in_cgroup --help note: CGROUP must start will slash '/' , and no special character