mirror of
https://github.com/springzfx/cgproxy.git
synced 2026-01-07 13:07:56 +08:00
fix print usage and clang format
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
#include "common.hpp"
|
||||
#include "socket_client.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
using namespace CGPROXY;
|
||||
|
||||
void print_usage() {
|
||||
fprintf(stdout, "Usage: cgproxy [--help] [--debug] [--noproxy] <CMD>\n");
|
||||
fprintf(stdout, "Alias: cgnoproxy = cgproxy --noproxy\n");
|
||||
bool print_help = false, proxy = true;
|
||||
void print_usage() {
|
||||
fprintf(stdout, "Usage: cgproxy [--help] [--debug] [--noproxy] <CMD>\n");
|
||||
fprintf(stdout, "Alias: cgnoproxy = cgproxy --noproxy\n");
|
||||
}
|
||||
|
||||
void processArgs(const int argc, char *argv[], int &shift, bool &proxy) {
|
||||
void processArgs(const int argc, char *argv[], int &shift) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--noproxy") == 0) { proxy = false; }
|
||||
if (strcmp(argv[i], "--debug") == 0) { enable_debug = true; }
|
||||
@@ -18,9 +20,9 @@ void processArgs(const int argc, char *argv[], int &shift, bool &proxy) {
|
||||
}
|
||||
}
|
||||
|
||||
bool attach2cgroup(pid_t pid,bool proxy) {
|
||||
bool attach2cgroup(pid_t pid, bool proxy) {
|
||||
json j;
|
||||
j["type"] = proxy?MSG_TYPE_PROXY_PID:MSG_TYPE_NOPROXY_PID;
|
||||
j["type"] = proxy ? MSG_TYPE_PROXY_PID : MSG_TYPE_NOPROXY_PID;
|
||||
j["data"] = pid;
|
||||
int status;
|
||||
SOCKET::send(j.dump(), status);
|
||||
@@ -28,16 +30,16 @@ bool attach2cgroup(pid_t pid,bool proxy) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc == 1) {
|
||||
error(
|
||||
"usage: cgproxy [--debug] <CMD>\nexample: cgroxy curl -I https://www.google.com");
|
||||
exit(EXIT_FAILURE);
|
||||
int shift = 1;
|
||||
processArgs(argc, argv, shift);
|
||||
|
||||
if (argc==shift||print_help) {
|
||||
print_usage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int shift = 1; bool proxy=true;
|
||||
processArgs(argc, argv, shift,proxy);
|
||||
pid_t pid = getpid();
|
||||
if (!attach2cgroup(pid,proxy)) {
|
||||
if (!attach2cgroup(pid, proxy)) {
|
||||
error("attach process failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user