-rw-r--r-- | src/iiid.cc | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/iiid.cc b/src/iiid.cc index d655fe3..b3dd3bf 100644 --- a/src/iiid.cc +++ b/src/iiid.cc | |||
@@ -1,97 +1,99 @@ | |||
1 | #include <syslog.h> | 1 | #include <syslog.h> |
2 | #include <getopt.h> | 2 | #include <getopt.h> |
3 | #include <sys/stat.h> | 3 | #include <sys/stat.h> |
4 | #include <glob.h> | 4 | #include <glob.h> |
5 | #include <iostream> | 5 | #include <iostream> |
6 | #include <cassert> | 6 | #include <cassert> |
7 | #include <stdexcept> | 7 | #include <stdexcept> |
8 | #include "eyetil.h" | 8 | #include "eyetil.h" |
9 | #include "eyefiworker.h" | 9 | #include "eyefiworker.h" |
10 | 10 | ||
11 | #include "config.h" | 11 | #include "config.h" |
12 | 12 | ||
13 | #include "eyefi.nsmap" | 13 | #include "eyefi.nsmap" |
14 | 14 | ||
15 | #define PHEADER \ | 15 | #define PHEADER \ |
16 | PACKAGE " Version " VERSION "\n" \ | 16 | PACKAGE " Version " VERSION "\n" \ |
17 | "Copyright (c) 2009 Klever Group" | 17 | "Copyright (c) 2009 Klever Group" |
18 | 18 | ||
19 | int main(int argc,char **argv) try { | 19 | int main(int argc,char **argv) try { |
20 | 20 | ||
21 | int port = 59278; | 21 | int port = 59278; |
22 | 22 | ||
23 | while(true) { | 23 | while(true) { |
24 | static struct option opts[] = { | 24 | static struct option opts[] = { |
25 | { "help", no_argument, 0, 'h' }, | 25 | { "help", no_argument, 0, 'h' }, |
26 | { "usage", no_argument, 0, 'h' }, | 26 | { "usage", no_argument, 0, 'h' }, |
27 | { "version", no_argument, 0, 'V' }, | 27 | { "version", no_argument, 0, 'V' }, |
28 | { "license", no_argument, 0, 'L' }, | 28 | { "license", no_argument, 0, 'L' }, |
29 | { "port", required_argument, 0, 'p' }, | 29 | { "port", required_argument, 0, 'p' }, |
30 | { NULL, 0, 0, 0 } | 30 | { NULL, 0, 0, 0 } |
31 | }; | 31 | }; |
32 | int c = getopt_long(argc,argv,"hVLp:",opts,NULL); | 32 | int c = getopt_long(argc,argv,"hVLp:",opts,NULL); |
33 | if(c==-1) break; | 33 | if(c==-1) break; |
34 | switch(c) { | 34 | switch(c) { |
35 | case 'h': | 35 | case 'h': |
36 | std::cerr << PHEADER << std::endl << std::endl | 36 | std::cerr << PHEADER << std::endl << std::endl |
37 | << " " << argv[0] << " [options]" << std::endl | 37 | << " " << argv[0] << " [options]" << std::endl |
38 | << std::endl << | 38 | << std::endl << |
39 | " -h, --help,\n" | 39 | " -h, --help,\n" |
40 | " --usage display this text\n" | 40 | " --usage display this text\n" |
41 | " -V, --version display version information\n" | 41 | " -V, --version display version information\n" |
42 | " -L, --license show license\n" | 42 | " -L, --license show license\n" |
43 | " -p <port>, --port=<port> port to listen to\n" | 43 | " -p <port>, --port=<port> port to listen to\n" |
44 | " (you're not likely to ever need it)\n" | 44 | " (you're not likely to ever need it)\n" |
45 | << std::endl << std::endl; | 45 | << std::endl << std::endl; |
46 | exit(0); | 46 | exit(0); |
47 | break; | 47 | break; |
48 | case 'V': | 48 | case 'V': |
49 | std::cerr << VERSION << std::endl; | 49 | std::cerr << VERSION << std::endl; |
50 | exit(0); | 50 | exit(0); |
51 | break; | 51 | break; |
52 | case 'L': | 52 | case 'L': |
53 | extern const char *COPYING; | 53 | extern const char *COPYING; |
54 | std::cerr << COPYING << std::endl; | 54 | std::cerr << COPYING << std::endl; |
55 | exit(0); | 55 | exit(0); |
56 | break; | 56 | break; |
57 | case 'p': | 57 | case 'p': |
58 | port = 0xffff&strtol(optarg,0,0); | 58 | port = 0xffff&strtol(optarg,0,0); |
59 | if(errno) { | 59 | if(errno) { |
60 | std::cerr << "Failed to parse port number" << std::endl; | 60 | std::cerr << "Failed to parse port number" << std::endl; |
61 | exit(1); | 61 | exit(1); |
62 | } | 62 | } |
63 | break; | 63 | break; |
64 | default: | 64 | default: |
65 | std::cerr << "Huh?" << std::endl; | 65 | std::cerr << "Huh?" << std::endl; |
66 | exit(1); | 66 | exit(1); |
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | const char *ident = rindex(*argv,'/'); | 71 | const char *ident = rindex(*argv,'/'); |
72 | if(ident) | 72 | if(ident) |
73 | ++ident; | 73 | ++ident; |
74 | else | 74 | else |
75 | ident = *argv; | 75 | ident = *argv; |
76 | openlog(ident,LOG_PERROR|LOG_PID,LOG_DAEMON); | 76 | openlog(ident,LOG_PERROR|LOG_PID,LOG_DAEMON); |
77 | syslog(LOG_INFO,"Starting iii eye-fi manager"); | 77 | syslog(LOG_INFO,"Starting iii eye-fi manager"); |
78 | 78 | ||
79 | struct stat st; | 79 | struct stat st; |
80 | if(stat(EYEKIN_CONF_DIR,&st) || !S_ISDIR(st.st_mode)) | 80 | if(stat(EYEKIN_CONF_DIR,&st) || !S_ISDIR(st.st_mode)) |
81 | syslog(LOG_WARNING,"configuration directory '%s' does not exist or is not a directory",EYEKIN_CONF_DIR); | 81 | syslog(LOG_WARNING,"configuration directory '%s' does not exist or is not a directory",EYEKIN_CONF_DIR); |
82 | glob_t g; int rg = glob(EYEKIN_CONF_DIR"/????????????.conf",GLOB_NOSORT,NULL,&g); | 82 | glob_t g; int rg = glob(EYEKIN_CONF_DIR"/????????????.conf",GLOB_NOSORT,NULL,&g); |
83 | if(rg || !g.gl_pathc) | 83 | if(rg || !g.gl_pathc) |
84 | syslog(LOG_WARNING,"I see nothing resembling a card config in '%s'",EYEKIN_CONF_DIR); | 84 | syslog(LOG_WARNING,"I see nothing resembling a card config in '%s'",EYEKIN_CONF_DIR); |
85 | else | 85 | else |
86 | globfree(&g); | 86 | globfree(&g); |
87 | 87 | ||
88 | eyefiworker().run(port); | 88 | eyefiworker().run(port); |
89 | 89 | ||
90 | closelog(); | 90 | closelog(); |
91 | return 0; | 91 | return 0; |
92 | } catch(std::exception& e) { | 92 | } catch(const throwable_exit& e) { |
93 | return e.rc; | ||
94 | } catch(const std::exception& e) { | ||
93 | syslog(LOG_CRIT,"Exiting iii daemon, because of error condition"); | 95 | syslog(LOG_CRIT,"Exiting iii daemon, because of error condition"); |
94 | syslog(LOG_CRIT,"Exception: %s",e.what()); | 96 | syslog(LOG_CRIT,"Exception: %s",e.what()); |
95 | return 1; | 97 | return 1; |
96 | } | 98 | } |
97 | 99 | ||