mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
fixed conf bugs and refactor
This commit is contained in:
parent
eb9633ed59
commit
0a7f9b5cc6
52
.cproject
52
.cproject
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.436825263">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.436825263" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1051378038">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1051378038" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
@ -14,28 +14,17 @@
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.436825263" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.436825263.480908490" name="/" resourcePath="">
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1517253393" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.1797790700" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
|
||||
<builder id="cdt.managedbuild.target.gnu.builder.base.1253245139" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.2108168419" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1940762076" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.997669137" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.233419498" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.460189617" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.54583610" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.2065407163" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.263855663" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.assembler.base.747872161" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1349563828" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
</tool>
|
||||
<configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.base.1051378038" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1051378038.1421447843" name="/" resourcePath="">
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1854135910" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.708367396" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
|
||||
<builder id="cdt.managedbuild.target.gnu.builder.base.1743684210" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1848194835" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1873425854" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1356109619" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1018655568" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.180014749" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.assembler.base.2017907772" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"/>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
</configuration>
|
||||
@ -43,16 +32,6 @@
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="udp2raw-tunnel-desktop.null.370025459" name="udp2raw-tunnel-desktop"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="Default">
|
||||
<resource resourceType="PROJECT" workspacePath="/udp2raw-tunnel-desktop"/>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.436825263;cdt.managedbuild.toolchain.gnu.base.436825263.480908490;cdt.managedbuild.tool.gnu.cpp.compiler.base.1940762076;cdt.managedbuild.tool.gnu.cpp.compiler.input.997669137">
|
||||
@ -62,5 +41,8 @@
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="udp2raw.null.1592488805" name="udp2raw"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
</cproject>
|
||||
|
70
common.cpp
70
common.cpp
@ -618,3 +618,73 @@ string trim(const string& str, char c) {
|
||||
size_t last = str.find_last_not_of(c);
|
||||
return str.substr(first,(last-first+1));
|
||||
}
|
||||
|
||||
vector<string> parse_conf_line(const string& s)
|
||||
{
|
||||
char buf[s.length()+200];
|
||||
char *p=buf;
|
||||
int i=int(s.length())-1;
|
||||
int j;
|
||||
vector<string>res;
|
||||
strcpy(buf,(char *)s.c_str());
|
||||
while(i>=0)
|
||||
{
|
||||
if(buf[i]==' ' || buf[i]== '\t')
|
||||
buf[i]=0;
|
||||
else break;
|
||||
i--;
|
||||
}
|
||||
while(*p!=0)
|
||||
{
|
||||
if(*p==' ' || *p== '\t')
|
||||
{
|
||||
p++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
int new_len=strlen(p);
|
||||
if(new_len==0)return res;
|
||||
if(p[0]=='#') return res;
|
||||
if(p[0]!='-')
|
||||
{
|
||||
mylog(log_fatal,"line :<%s> not begin with '-' ",s.c_str());
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
for(i=0;i<new_len;i++)
|
||||
{
|
||||
if(p[i]==' '||p[i]=='\t')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==new_len)
|
||||
{
|
||||
res.push_back(p);
|
||||
return res;
|
||||
}
|
||||
|
||||
j=i;
|
||||
while(p[j]==' '||p[j]=='\t')
|
||||
j++;
|
||||
p[i]=0;
|
||||
res.push_back(p);
|
||||
res.push_back(p+j);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
4
common.h
4
common.h
@ -166,6 +166,10 @@ vector< vector <string> > string_to_vec2(const char * s);
|
||||
|
||||
string trim(const string& str, char c);
|
||||
|
||||
string trim_conf_line(const string& str);
|
||||
|
||||
vector<string> parse_conf_line(const string& s);
|
||||
|
||||
//extern string iptables_pattern;
|
||||
|
||||
#endif /* COMMON_H_ */
|
||||
|
318
main.cpp
318
main.cpp
@ -575,6 +575,7 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
|
||||
int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,char *data,int data_len);
|
||||
int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * data, int data_len);
|
||||
|
||||
void process_arg(int argc, char *argv[]);
|
||||
int DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD;
|
||||
////////////////=======================declear divider=============================
|
||||
|
||||
@ -2522,7 +2523,7 @@ void print_help()
|
||||
printf(" this option disables port changing while re-connecting\n");
|
||||
// printf(" \n");
|
||||
printf("other options:\n");
|
||||
printf(" --config-file <string> read options from a configuration file instead of command line\n");
|
||||
printf(" --conf-file <string> read options from a configuration file instead of command line\n");
|
||||
printf(" --log-level <number> 0:never 1:fatal 2:error 3:warn \n");
|
||||
printf(" 4:info (default) 5:debug 6:trace\n");
|
||||
// printf("\n");
|
||||
@ -2546,70 +2547,84 @@ void print_help()
|
||||
|
||||
//printf("common options,these options must be same on both side\n");
|
||||
}
|
||||
void process_arg(int argc, char *argv[], bool read_config = true);
|
||||
std::string trim_config_line(std::string line)
|
||||
{
|
||||
auto str = trim(line, ' '); // Space
|
||||
str = trim(str, ' '); // Tab
|
||||
return str;
|
||||
}
|
||||
std::size_t find_config_divider(std::string line)
|
||||
{
|
||||
std::size_t pos = line.find(" ",0); // Space
|
||||
if(pos==std::string::npos)
|
||||
{
|
||||
pos = line.find(" ",0); // Tab
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
void load_config(char *config_file, int argc_orig, char *argv_orig[])
|
||||
|
||||
int load_config(char *file_name, int &argc, vector<string> &argv)
|
||||
{
|
||||
// Load configurations from config_file instead of the command line.
|
||||
// See config.example for example configurations
|
||||
std::ifstream conf_file(config_file);
|
||||
std::ifstream conf_file(file_name);
|
||||
std::string line;
|
||||
std::vector<std::string> arguments;
|
||||
if(conf_file.fail())
|
||||
{
|
||||
mylog(log_fatal,"conf_file %s open failed,reason :%s\n",file_name,strerror(errno));
|
||||
myexit(-1);
|
||||
}
|
||||
while(std::getline(conf_file,line))
|
||||
{
|
||||
line = trim_config_line(line);
|
||||
if(line==""||line.at(0)=='#')
|
||||
auto res=parse_conf_line(line);
|
||||
|
||||
argc+=res.size();
|
||||
for(int i=0;i<(int)res.size();i++)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
auto pos = find_config_divider(line);
|
||||
if(pos==std::string::npos)
|
||||
{
|
||||
arguments.push_back(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto p1 = line.substr(0,pos);
|
||||
auto p2 = line.substr(pos+1,line.length() - pos - 1);
|
||||
arguments.push_back(trim_config_line(p1));
|
||||
arguments.push_back(trim_config_line(p2));
|
||||
argv.push_back(res[i]);
|
||||
}
|
||||
}
|
||||
conf_file.close();
|
||||
|
||||
// Append the new arguments to the original argv
|
||||
int argc = arguments.size() + argc_orig;
|
||||
char *argv[argc];
|
||||
for(int i=0; i<argc; i++)
|
||||
return 0;
|
||||
}
|
||||
int unit_test()
|
||||
{
|
||||
printf("running unit test\n");
|
||||
vector<string> conf_lines= {"---aaa","--aaa bbb","-a bbb"," \t \t \t-a\t \t \t bbbbb\t \t \t "};
|
||||
for(int i=0;i<int(conf_lines.size());i++)
|
||||
{
|
||||
if(i<argc_orig)
|
||||
printf("orign:%s\n",conf_lines[i].c_str());
|
||||
auto res=parse_conf_line(conf_lines[i]);
|
||||
printf("pasrse_result: size %d",int(res.size()));
|
||||
for(int j=0;j<int(res.size());j++)
|
||||
{
|
||||
printf("<%s>",res[j].c_str());
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int process_log_level(int argc,char *argv[])
|
||||
{
|
||||
int i,j,k;
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"--log-level")==0)
|
||||
{
|
||||
if(i<argc -1)
|
||||
{
|
||||
sscanf(argv[i+1],"%d",&log_level);
|
||||
if(0<=log_level&&log_level<log_end)
|
||||
{
|
||||
argv[i] = argv_orig[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[i] = (char*)arguments[i-argc_orig].c_str();
|
||||
log_bare(log_fatal,"invalid log_level\n");
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
process_arg(argc,argv,false);
|
||||
}
|
||||
if(strcmp(argv[i],"--disable-color")==0)
|
||||
{
|
||||
enable_log_color=0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void process_arg(int argc, char *argv[], bool read_config)
|
||||
void process_arg(int argc, char *argv[])
|
||||
{
|
||||
int i,j,k,opt;
|
||||
|
||||
int option_index = 0;
|
||||
|
||||
char options[]="l:r:schk:ag";
|
||||
static struct option long_options[] =
|
||||
{
|
||||
/* These options set a flag. */
|
||||
@ -2634,85 +2649,37 @@ void process_arg(int argc, char *argv[], bool read_config)
|
||||
{"lower-level", required_argument, 0, 1},
|
||||
{"sock-buf", required_argument, 0, 1},
|
||||
{"seq-mode", required_argument, 0, 1},
|
||||
{"config-file", required_argument, 0, 1},
|
||||
{"conf-file", required_argument, 0, 1},
|
||||
{NULL, 0, 0, 0}
|
||||
};
|
||||
static std::map<string,string> short_opts_map = {
|
||||
{"-k","--key"},
|
||||
{"-a","--auto-rule"},
|
||||
{"-g","--gen-rule"},
|
||||
}; // Keep this in sync with the shortcuts
|
||||
|
||||
int option_index = 0;
|
||||
std::set<string> checked_opts = {};
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0)
|
||||
{
|
||||
print_help();
|
||||
myexit(0);
|
||||
}
|
||||
process_log_level(argc,argv);
|
||||
|
||||
if(read_config&&strcmp(argv[i],"--config-file")==0)
|
||||
{
|
||||
if(i<argc-1)
|
||||
{
|
||||
load_config(argv[i+1],argc,argv);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_bare(log_fatal,"you must provide path to the configuration file when using --config-file");
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
set<string> all_options;
|
||||
map<string,string> shortcut_map;
|
||||
|
||||
// Check for duplicate arguments
|
||||
if(strncmp("-",argv[i],1)==0)
|
||||
all_options.insert("--help");
|
||||
all_options.insert("-h");
|
||||
all_options.insert("--conf-file");
|
||||
string dummy="";
|
||||
for(i=0;i<(int)strlen(options);i++)
|
||||
{
|
||||
std::string opt(argv[i]);
|
||||
auto iter = short_opts_map.find(opt);
|
||||
if(iter!=short_opts_map.end())
|
||||
{
|
||||
opt = iter->second;
|
||||
}
|
||||
if(checked_opts.find(opt)!=checked_opts.end())
|
||||
{
|
||||
char *err_msg = new char(255);
|
||||
sprintf(err_msg,"Duplicate argument %s",opt.c_str());
|
||||
log_bare(log_fatal,err_msg);
|
||||
myexit(-1);
|
||||
}
|
||||
checked_opts.insert(opt);
|
||||
}
|
||||
}
|
||||
if (argc == 1)
|
||||
{
|
||||
print_help();
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
char val=options[i];
|
||||
if( ( val>='0'&&val<='9') ||( val>='a'&&val<='z')||(val>='A'&&val<='Z'))
|
||||
{
|
||||
if(strcmp(argv[i],"--log-level")==0)
|
||||
{
|
||||
if(i<argc -1)
|
||||
{
|
||||
sscanf(argv[i+1],"%d",&log_level);
|
||||
if(0<=log_level&&log_level<log_end)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
log_bare(log_fatal,"invalid log_level\n");
|
||||
myexit(-1);
|
||||
all_options.insert(dummy+'-'+val);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(strcmp(argv[i],"--disable-color")==0)
|
||||
for(i=0;i<int( sizeof(long_options)/sizeof(long_options[0]) );i++)
|
||||
{
|
||||
enable_log_color=0;
|
||||
if(long_options[i].name==NULL) break;
|
||||
int val=long_options[i].val;
|
||||
if( ( val>='0'&&val<='9') ||( val>='a'&&val<='z')||(val>='A'&&val<='Z'))
|
||||
{
|
||||
shortcut_map[dummy+"--"+long_options[i].name]= dummy+"-"+ char(val);
|
||||
}
|
||||
all_options.insert(dummy+"--"+long_options[i].name);
|
||||
}
|
||||
|
||||
mylog(log_info,"argc=%d ", argc);
|
||||
@ -2722,10 +2689,46 @@ void process_arg(int argc, char *argv[], bool read_config)
|
||||
}
|
||||
log_bare(log_info, "\n");
|
||||
|
||||
//string dummy="";
|
||||
for(i=+1;i<argc;i++)
|
||||
{
|
||||
if(argv[i][0]!='-') continue;
|
||||
string a=argv[i];
|
||||
if(a[0]=='-'&&a[1]!='-')
|
||||
a=dummy+a[0]+a[1];
|
||||
|
||||
if(all_options.find(a.c_str())==all_options.end())
|
||||
{
|
||||
mylog(log_fatal,"invaild option %s\n",a.c_str());
|
||||
myexit(-1);
|
||||
}
|
||||
for(j=i+1;j<argc;j++)
|
||||
{
|
||||
if(argv[j][0]!='-') continue;
|
||||
|
||||
string b=argv[j];
|
||||
|
||||
if(b[0]=='-'&&b[1]!='-')
|
||||
b=dummy+b[0]+b[1];
|
||||
|
||||
if(shortcut_map.find(a)!=shortcut_map.end())
|
||||
a=shortcut_map[a];
|
||||
if(shortcut_map.find(b)!=shortcut_map.end())
|
||||
b=shortcut_map[b];
|
||||
if(a==b)
|
||||
{
|
||||
mylog(log_fatal,"%s duplicates with %s\n",argv[i],argv[j]);
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int no_l = 1, no_r = 1;
|
||||
while ((opt = getopt_long(argc, argv, "l:r:schk:ag",long_options,&option_index)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv,options,long_options,&option_index)) != -1) {
|
||||
//string opt_key;
|
||||
//opt_key+=opt;
|
||||
switch (opt) {
|
||||
@ -2946,7 +2949,7 @@ void process_arg(int argc, char *argv[], bool read_config)
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"config-file")==0)
|
||||
else if(strcmp(long_options[option_index].name,"conf-file")==0)
|
||||
{
|
||||
mylog(log_info,"configuration loaded from %s\n",optarg);
|
||||
}
|
||||
@ -2995,7 +2998,94 @@ void process_arg(int argc, char *argv[], bool read_config)
|
||||
|
||||
log_bare(log_info,"\n");
|
||||
}
|
||||
void pre_process_arg(int argc, char *argv[])
|
||||
{
|
||||
int i,j,k;
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"--unit-test")==0)
|
||||
{
|
||||
unit_test();
|
||||
myexit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0)
|
||||
{
|
||||
print_help();
|
||||
myexit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
print_help();
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
|
||||
process_log_level(argc,argv);
|
||||
|
||||
int new_argc=0;
|
||||
vector<string> new_argv;
|
||||
|
||||
int count=0;
|
||||
int pos=-1;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"--conf-file")==0)
|
||||
{
|
||||
count++;
|
||||
pos=i;
|
||||
if(i==argc)
|
||||
{
|
||||
mylog(log_fatal,"--conf-file need a parameter\n");
|
||||
myexit(-1);
|
||||
}
|
||||
if(argv[i+1][1]=='-')
|
||||
{
|
||||
mylog(log_fatal,"--conf-file need a parameter\n");
|
||||
myexit(-1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("<%s>",argv[i]);
|
||||
new_argc++;
|
||||
new_argv.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
if(count>1)
|
||||
{
|
||||
mylog(log_fatal,"duplicated --conf-file option\n");
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
if(count>0)
|
||||
{
|
||||
load_config(argv[pos+1],new_argc,new_argv);
|
||||
}
|
||||
char* new_argv_char[new_argv.size()];
|
||||
|
||||
new_argc=0;
|
||||
for(i=0;i<(int)new_argv.size();i++)
|
||||
{
|
||||
if(strcmp(new_argv[i].c_str(),"--conf-file")==0)
|
||||
{
|
||||
mylog(log_fatal,"cant have --conf-file in a config file\n");
|
||||
myexit(-1);
|
||||
}
|
||||
new_argv_char[new_argc++]=(char *)new_argv[i].c_str();
|
||||
}
|
||||
process_arg(new_argc,new_argv_char);
|
||||
|
||||
}
|
||||
void *run_keep(void *none)
|
||||
{
|
||||
|
||||
@ -3168,7 +3258,7 @@ int main(int argc, char *argv[])
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGQUIT, signal_handler);
|
||||
|
||||
process_arg(argc,argv);
|
||||
pre_process_arg(argc,argv);
|
||||
|
||||
if(geteuid() != 0)
|
||||
{
|
||||
|
4
makefile
4
makefile
@ -13,10 +13,10 @@ TAR=${NAME}_binaries.tar.gz ${NAME}_amd64 ${NAME}_x86 ${NAME}_x86_asm_aes ${NA
|
||||
|
||||
all:
|
||||
rm -f ${NAME}
|
||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3
|
||||
fast:
|
||||
rm -f ${NAME}
|
||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt
|
||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb
|
||||
debug:
|
||||
rm -f ${NAME}
|
||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG
|
||||
|
Loading…
x
Reference in New Issue
Block a user