comparison audioDB.cpp @ 151:5fa52830e532

More defensive command-line error checking: * the command line is also used by the WS server, so don't call exit() directly, call error(); * turn the server flag on before parsing the command-line, so that calls to error() do the right thing..
author mas01cr
date Wed, 31 Oct 2007 15:38:11 +0000
parents ddd83d773d6c
children ea6936b82915
comparison
equal deleted inserted replaced
150:521cecd1eab7 151:5fa52830e532
40 printf("%s\n", gengetopt_args_info_purpose); 40 printf("%s\n", gengetopt_args_info_purpose);
41 printf("%s\n", gengetopt_args_info_usage); 41 printf("%s\n", gengetopt_args_info_usage);
42 printf("%s\n", gengetopt_args_info_help[1]); 42 printf("%s\n", gengetopt_args_info_help[1]);
43 printf("%s\n", gengetopt_args_info_help[2]); 43 printf("%s\n", gengetopt_args_info_help[2]);
44 printf("%s\n", gengetopt_args_info_help[0]); 44 printf("%s\n", gengetopt_args_info_help[0]);
45 exit(1); 45 error("No command found");
46 } 46 }
47 47
48 if(O2_ACTION(COM_SERVER)) 48 if(O2_ACTION(COM_SERVER))
49 startServer(); 49 startServer();
50 50
80 } 80 }
81 81
82 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS 82 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS
83 { 83 {
84 try { 84 try {
85 isServer = 1; // FIXME: Hack
85 processArgs(argc, argv); 86 processArgs(argc, argv);
86 isServer = 1; // FIXME: Hack
87 assert(O2_ACTION(COM_QUERY)); 87 assert(O2_ACTION(COM_QUERY));
88 query(dbName, inFile, adbQueryResponse); 88 query(dbName, inFile, adbQueryResponse);
89 } catch(char *err) { 89 } catch(char *err) {
90 cleanup(); 90 cleanup();
91 throw(err); 91 throw(err);
93 } 93 }
94 94
95 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS 95 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS
96 { 96 {
97 try { 97 try {
98 isServer = 1; // FIXME: Hack
98 processArgs(argc, argv); 99 processArgs(argc, argv);
99 isServer = 1; // FIXME: Hack
100 assert(O2_ACTION(COM_STATUS)); 100 assert(O2_ACTION(COM_STATUS));
101 status(dbName, adbStatusResponse); 101 status(dbName, adbStatusResponse);
102 } catch(char *err) { 102 } catch(char *err) {
103 cleanup(); 103 cleanup();
104 throw(err); 104 throw(err);
135 printf("%s\n", gengetopt_args_info_help[0]); 135 printf("%s\n", gengetopt_args_info_help[0]);
136 exit(0); 136 exit(0);
137 } 137 }
138 138
139 if (cmdline_parser (argc, argv, &args_info) != 0) 139 if (cmdline_parser (argc, argv, &args_info) != 0)
140 exit(1) ; 140 error("Error parsing command line");
141 141
142 if(args_info.help_given){ 142 if(args_info.help_given){
143 cmdline_parser_print_help(); 143 cmdline_parser_print_help();
144 exit(0); 144 exit(0);
145 } 145 }
173 if(args_info.SERVER_given){ 173 if(args_info.SERVER_given){
174 command=COM_SERVER; 174 command=COM_SERVER;
175 port=args_info.SERVER_arg; 175 port=args_info.SERVER_arg;
176 if(port<100 || port > 100000) 176 if(port<100 || port > 100000)
177 error("port out of range"); 177 error("port out of range");
178 isServer=1; 178 isServer = 1;
179 #if defined(O2_DEBUG) 179 #if defined(O2_DEBUG)
180 struct sigaction sa; 180 struct sigaction sa;
181 sa.sa_sigaction = sigterm_action; 181 sa.sa_sigaction = sigterm_action;
182 sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER; 182 sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
183 sigaction(SIGTERM, &sa, NULL); 183 sigaction(SIGTERM, &sa, NULL);