]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Implement better error diagnostics for para_client.
authorAndre Noll <maan@systemlinux.org>
Tue, 30 Sep 2008 20:23:18 +0000 (22:23 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 30 Sep 2008 20:23:18 +0000 (22:23 +0200)
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.

NEWS
client.c
client.ggo
client_common.c
error.h

diff --git a/NEWS b/NEWS
index 6eccc8af9c828651518522732f93d3dc306bd5eb..8487a6ad0840107b20f347132911ab96f3e03119 100644 (file)
--- 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"
index cf115e03c7ef639ace1f1de12c5387e1968d4058..4208579b5e756bbbee9ec03cd10613e13c9a596e 100644 (file)
--- 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);
index 702358cb977e2fffc1863aea6bdddc5cd7a81304..1d6b410d7b56847b6b2422e8d61d619f59210d11 100644 (file)
@@ -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="<current user>" optional
 option "server_port" p "port to connect" int typestr="port" default="2990" optional
index d8eaba66cc9b7d704f1479b80fab8709bc53f674..9886cfe5f93ef187f0f61fc0642a68b41f0b0619 100644 (file)
@@ -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, &params);
+               ret = -E_BAD_CONFIG;
+               if (client_cmdline_parser_config_file(ct->config_file,
+                       &ct->conf, &params))
+                       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 4674ec04de88f335e24cde3732af14f154216cd8..4cd12eb0ab17842a309b04374028bea04921f47e 100644 (file)
--- 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"), \