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 6eccc8a..8487a6a 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 cf115e0..4208579 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 702358c..1d6b410 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 d8eaba6..9886cfe 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 4674ec0..4cd12eb 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"), \