author | Michael Krelin <hacker@klever.net> | 2012-01-20 21:36:25 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2012-01-20 21:36:25 (UTC) |
commit | 8f8bdd258276b1a53100393d6e7557f078898e71 (patch) (unidiff) | |
tree | ea2fed0a86506212d55598674854d0d736634475 | |
parent | 62d09cb2346588773a9e25ac9e9a942816b8581a (diff) | |
download | iii-8f8bdd258276b1a53100393d6e7557f078898e71.zip iii-8f8bdd258276b1a53100393d6e7557f078898e71.tar.gz iii-8f8bdd258276b1a53100393d6e7557f078898e71.tar.bz2 |
throw a fit if unable to parse config file
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | src/eyekinfig.cc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/eyekinfig.cc b/src/eyekinfig.cc index 56c74a7..6dde7b2 100644 --- a/src/eyekinfig.cc +++ b/src/eyekinfig.cc | |||
@@ -2,14 +2,14 @@ | |||
2 | #include <stdexcept> | 2 | #include <stdexcept> |
3 | #include <autosprintf.h> | 3 | #include <autosprintf.h> |
4 | #include "eyekinfig.h" | 4 | #include "eyekinfig.h" |
5 | 5 | ||
6 | #include "config.h" | 6 | #include "config.h" |
7 | 7 | ||
8 | eyekinfig_t::eyekinfig_t(const std::string& ma) | 8 | eyekinfig_t::eyekinfig_t(const std::string& ma) : macaddress(ma) { |
9 | : macaddress(ma) { | 9 | try { |
10 | static cfg_opt_t opts[] = { | 10 | static cfg_opt_t opts[] = { |
11 | CFG_STR((char*)"targetdir",(char*)"/var/lib/" PACKAGE "/%s",CFGF_NONE), | 11 | CFG_STR((char*)"targetdir",(char*)"/var/lib/" PACKAGE "/%s",CFGF_NONE), |
12 | CFG_STR((char*)"uploadkey",(char*)"",CFGF_NONE), | 12 | CFG_STR((char*)"uploadkey",(char*)"",CFGF_NONE), |
13 | CFG_STR((char*)"on-start-session",(char*)"",CFGF_NONE), | 13 | CFG_STR((char*)"on-start-session",(char*)"",CFGF_NONE), |
14 | CFG_STR((char*)"on-upload-photo",(char*)"",CFGF_NONE), | 14 | CFG_STR((char*)"on-upload-photo",(char*)"",CFGF_NONE), |
15 | CFG_STR((char*)"on-mark-last-photo-in-roll",(char*)"",CFGF_NONE), | 15 | CFG_STR((char*)"on-mark-last-photo-in-roll",(char*)"",CFGF_NONE), |
@@ -17,23 +17,25 @@ eyekinfig_t::eyekinfig_t(const std::string& ma) | |||
17 | CFG_END() | 17 | CFG_END() |
18 | }; | 18 | }; |
19 | cfg = cfg_init(opts,CFGF_NONE); | 19 | cfg = cfg_init(opts,CFGF_NONE); |
20 | if(!cfg) | 20 | if(!cfg) |
21 | throw std::runtime_error("failed to cfg_init()"); | 21 | throw std::runtime_error("failed to cfg_init()"); |
22 | std::string::size_type ls = macaddress.rfind('/'); | 22 | std::string::size_type ls = macaddress.rfind('/'); |
23 | if(cfg_parse(cfg,gnu::autosprintf( | 23 | std::string cf = gnu::autosprintf( EYEKIN_CONF_DIR "/%s.conf", |
24 | EYEKIN_CONF_DIR "/%s.conf", | 24 | macaddress.c_str()+((ls==std::string::npos)?0:ls+1) ); |
25 | (ls==std::string::npos) | 25 | int r = cfg_parse(cfg,cf.c_str()); |
26 | ? macaddress.c_str() | 26 | if(r != CFG_SUCCESS) { |
27 | : macaddress.substr(ls+1).c_str() | 27 | cfg_free(cfg); cfg=0; |
28 | )) ==CFG_PARSE_ERROR) { | 28 | if(CFG_FILE_ERROR) throw std::runtime_error(gnu::autosprintf("failed to open configuration file '%s'",cf.c_str())); |
29 | if(cfg) cfg_free(cfg); | 29 | throw std::runtime_error(gnu::autosprintf("failed to parse configuration file '%s'",cf.c_str())); |
30 | cfg=0; | ||
31 | throw std::runtime_error("failed to cfg_parse()"); | ||
32 | } | 30 | } |
31 | }catch(...) { | ||
32 | if(cfg) cfg_free(cfg), cfg=0; | ||
33 | throw; | ||
33 | } | 34 | } |
35 | } | ||
34 | 36 | ||
35 | eyekinfig_t::~eyekinfig_t() { | 37 | eyekinfig_t::~eyekinfig_t() { |
36 | if(cfg) cfg_free(cfg); | 38 | if(cfg) cfg_free(cfg); |
37 | } | 39 | } |
38 | 40 | ||
39 | std::string eyekinfig_t::get_targetdir() { | 41 | std::string eyekinfig_t::get_targetdir() { |