diff options
author | 2010-07-23 16:38:06 +0300 | |
---|---|---|
committer | 2010-07-23 17:06:01 +0300 | |
commit | e73ca6a0e7b62add68cee0e258bb46d15c4741aa (patch) | |
tree | 6893dcc43d32ed97bc27cda322f5ae6c6f5dd3ac | |
parent | Add daemon mode to segget (diff) | |
download | idfetch-e73ca6a0e7b62add68cee0e258bb46d15c4741aa.tar.gz idfetch-e73ca6a0e7b62add68cee0e258bb46d15c4741aa.tar.bz2 idfetch-e73ca6a0e7b62add68cee0e258bb46d15c4741aa.zip |
Add command line arguments: --no-daemon and --conf-dir=specify_conf_dir_here
Arguments are optional. If no arguments provided, segget will run in a daemon
mode and use /etc/seggetd dir to read configuration files.
-rw-r--r-- | segget/config.cpp | 4 | ||||
-rw-r--r-- | segget/segget.cpp | 33 | ||||
-rw-r--r-- | segget/segget.h | 3 | ||||
-rw-r--r-- | segget/settings.h | 4 |
4 files changed, 34 insertions, 10 deletions
diff --git a/segget/config.cpp b/segget/config.cpp index 6c926df..fbbbab0 100644 --- a/segget/config.cpp +++ b/segget/config.cpp @@ -31,10 +31,10 @@ void Tconfig::load_settings_from_config_file(){ ifstream file; file.exceptions (ifstream::failbit | ifstream::badbit); try{ - file.open(config_file_name.c_str()); + file.open((settings.conf_dir+"/"+config_file_name).c_str()); } catch(...){ - error_log("Error opening settings file: "+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it."); + error_log("Error opening settings file: "+settings.conf_dir+"/"+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it."); return; } try{ diff --git a/segget/segget.cpp b/segget/segget.cpp index 59c96ed..214c452 100644 --- a/segget/segget.cpp +++ b/segget/segget.cpp @@ -451,18 +451,37 @@ int init_curses(){ } return 1; } +int parse_cli_arguments(int argc, char* argv[]){ + try{ + string option,name,value; + cout << "argc = " << argc << endl; + int posEqual; + for(int i = 0; i < argc; i++){ + cout << "argv[" << i << "] = " << argv[i] << endl; + option=argv[i]; + posEqual=option.find('='); + name = trim(option.substr(0,posEqual)); + value = trim(option.substr(posEqual+1)); + if (name=="--conf-dir") {settings.conf_dir=value; continue;}; + if (name=="--no-daemon"){settings.no_daemon_flag=true; continue;} + } + return 0; + }catch(...){ + perror("Error in segget.cpp: init_curses()"); + } + return 1; +} -int main() +int main(int argc, char* argv[]) { try{ - bool daemon_mode_flag=true; - if (daemon_mode_flag){ - start_daemon_mode(); - }else{ + parse_cli_arguments(argc, argv); + if (settings.no_daemon_flag){ init_curses(); routine(); - // exit curses - endwin(); + endwin(); // exit curses + }else{ + start_daemon_mode(); } exit (0); }catch(...){ diff --git a/segget/segget.h b/segget/segget.h index c03e6ea..45b4abd 100644 --- a/segget/segget.h +++ b/segget/segget.h @@ -62,13 +62,14 @@ CURLM *cm; int routine(); void start_daemon_mode(); +int parse_cli_arguments(int argc, char* argv[]); int init_curses(); int load_pkgs(); void show_pkgs(); int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num); int choose_segment(uint connection_num); int download_pkgs(); -int main(); +int main(int argc, char* argv[]); void *print_message_function( void *); #endif
\ No newline at end of file diff --git a/segget/settings.h b/segget/settings.h index bfe9c02..28d910e 100644 --- a/segget/settings.h +++ b/segget/settings.h @@ -39,6 +39,8 @@ class Tsettings{ private: void load_provide_mirror_files_restricted_patterns_vector(); public: + string conf_dir; + bool no_daemon_flag; //folders string distfiles_dir; string segments_dir; @@ -81,6 +83,8 @@ class Tsettings{ string debug_log_file; Tsettings(): + conf_dir("/etc/seggetd"), + no_daemon_flag(false), //folders distfiles_dir("./distfiles"), segments_dir("./tmp"), |