From: Andre Noll Date: Tue, 30 Sep 2008 20:23:18 +0000 (+0200) Subject: Implement better error diagnostics for para_client. X-Git-Tag: v0.3.3~44 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=08e8e00a1cd0d48bd9a4189661cd6336e063e887;hp=73b0bc66ce2f7b332e855434a393bf28da2ee0f0;p=paraslash.git Implement better error diagnostics for para_client. In case the config file contains errors, the old code caused para_client to exit without printing an error message. We need print_errors == 0 in client_open() because this function is also used by para_audiod which might not have a controlling terminal. So use gengetopt's --no-handle-error option that instructs the command line parser not to exit on errors. This wy we can use PARA_ERROR_LOG() to log an appropriate error message. --- diff --git a/NEWS b/NEWS index 6eccc8af..8487a6ad 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ amplification filter. used by the amp filter to pre-amplify the audio stream. - fix a close-without-open bug in para_write. - fix a bug in com_init() which was introduced in 0.3.2. + - better error diagnostics for para_client. ----------------------------------------- 0.3.2 (2008-04-11) "probabilistic parity" diff --git a/client.c b/client.c index cf115e03..4208579b 100644 --- a/client.c +++ b/client.c @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) s.default_timeout.tv_sec = 1; s.default_timeout.tv_usec = 0; ret = client_open(argc, argv, &ct); - if (ret < 0) /* can not use PARA_LOG here */ + if (ret < 0) /* can not use PARA_LOG here because ct is NULL */ exit(EXIT_FAILURE); register_task(&svt); ret = schedule(&s); diff --git a/client.ggo b/client.ggo index 702358cb..1d6b410d 100644 --- a/client.ggo +++ b/client.ggo @@ -1,4 +1,5 @@ # file client.conf +args "--no-handle-error" option "hostname" i "ip or host to connect" string typestr="host" default="localhost" optional option "user" u "paraslash username" string typestr="username" default="" optional option "server_port" p "port to connect" int typestr="port" default="2990" optional diff --git a/client_common.c b/client_common.c index d8eaba66..9886cfe5 100644 --- a/client_common.c +++ b/client_common.c @@ -328,7 +328,9 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr) *ct_ptr = ct; ct->fd = -1; - ret = client_cmdline_parser(argc, argv, &ct->conf); + ret = -E_CLIENT_SYNTAX; + if (client_cmdline_parser(argc, argv, &ct->conf)) + goto out; HANDLE_VERSION_FLAG("client", ct->conf); ret = -E_CLIENT_SYNTAX; if (!ct->conf.inputs_num) @@ -353,10 +355,13 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr) .override = 0, .initialize = 0, .check_required = 0, - .check_ambiguity = 0 + .check_ambiguity = 0, + .print_errors = 0 }; - client_cmdline_parser_config_file(ct->config_file, - &ct->conf, ¶ms); + ret = -E_BAD_CONFIG; + if (client_cmdline_parser_config_file(ct->config_file, + &ct->conf, ¶ms)) + goto out; } ret = 1; PARA_INFO_LOG("loglevel: %d\n", ct->conf.loglevel_arg); @@ -374,4 +379,3 @@ out: } return ret; } - diff --git a/error.h b/error.h index 4674ec04..4cd12eb0 100644 --- a/error.h +++ b/error.h @@ -169,6 +169,7 @@ extern const char **para_errlist[]; PARA_ERROR(CLIENT_SYNTAX, "syntax error"), \ PARA_ERROR(INVALID_CHALLENGE, "did not receive valid challenge"), \ PARA_ERROR(NO_CONFIG, "config file not found"), \ + PARA_ERROR(BAD_CONFIG, "syntax error in config file"), \ PARA_ERROR(CLIENT_AUTH, "authentication failed"), \ PARA_ERROR(SERVER_EOF, "connection closed by para_server"), \