audioc: use the error subsystem
authorAndre <maan@p133.(none)>
Sun, 11 Jun 2006 08:03:30 +0000 (10:03 +0200)
committerAndre <maan@p133.(none)>
Sun, 11 Jun 2006 08:03:30 +0000 (10:03 +0200)
and provide a non-empty log-function.

Makefile.in
NEWS
audioc.c
configure.ac
error.h

index 2bb28e9..bf571ef 100644 (file)
@@ -101,7 +101,6 @@ dbadm_objs = dbadm.o exec.o close_on_fork.o string.o
 fade_objs = fade.cmdline.o fade.o exec.o close_on_fork.o string.o fd.o
 krell_objs = krell.o string.o
 slider_objs = slider.o string.o
-audioc_objs = audioc.cmdline.o audioc.o string.o net.o fd.o
 
 *.o: para.h config.h gcc-compat.h
 
@@ -188,8 +187,8 @@ para_gui: @gui_objs@
 para_audiod: @audiod_objs@
        $(CC) -o $@ @audiod_objs@ @audiod_ldflags@
 
-para_audioc: $(audioc_objs)
-       $(CC) -o $@ $(audioc_objs)
+para_audioc: @audioc_objs@
+       $(CC) -o $@ @audioc_objs@
 
 para_dbadm: $(dbadm_objs)
        $(CC) -o $@ $(dbadm_objs) -lncurses -lmenu
diff --git a/NEWS b/NEWS
index 8b38cf4..4a2941f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,7 @@ A bunch of new features and core changes.
          just like para_recv and para_filter.
        - random/playlist selector: improved info strings
        - new audiod commands: tasks, kill
-       - para_client uses the error subsystem
+       - para_client/para_audioc use the error subsystem
 
 
 ------------------------------------------
index 7d472a6..afff14a 100644 (file)
--- a/audioc.c
+++ b/audioc.c
 #include "net.h"
 #include "string.h"
 #include "fd.h"
+#include "error.h"
+
+INIT_AUDIOC_ERRLISTS;
 
 struct gengetopt_args_info conf;
 char *tmpfifo;
-enum {E_SYNTAX, E_READ, E_WRITE, E_SOCKET, E_INIT_SOCK_ADDR, E_CONNECT, E_CREDENTIALS, E_SELECT, E_OVERRUN};
 
 
-void para_log(__a_unused int ll, __a_unused const char* fmt,...) /* no logging */
+/*
+ * client log function
+ */
+void para_log(int ll, const char* fmt,...)
 {
+       va_list argp;
+
+       /* ignore log message if loglevel is not high enough */
+       if (ll < conf.loglevel_arg)
+               return;
+       va_start(argp, fmt);
+       vfprintf(stderr, fmt, argp);
+       va_end(argp);
 }
 
 /* audioc does not use encryption */
@@ -67,7 +80,7 @@ static char *configfile_exists(void)
 int main(int argc, char *argv[])
 {
        struct sockaddr_un unix_addr;
-       int ret = -E_SYNTAX, fd, loaded = 0;
+       int ret = -E_AUDIOC_SYNTAX, fd, loaded = 0;
        char *cf, *socket_name, *randname = para_tmpname(), *tmpsocket_name = NULL,
                *buf = NULL, *hn = para_hostname(), *args, *home = para_homedir();
 
@@ -97,17 +110,18 @@ int main(int argc, char *argv[])
                tmpsocket_name = make_message("%s/.paraslash/audioc_sock.%s.%s",
                        home, hn, randname);
 
-       ret = -E_SOCKET;
-       fd = create_pf_socket(tmpsocket_name, &unix_addr, S_IRUSR | S_IWUSR);
+       ret = create_pf_socket(tmpsocket_name, &unix_addr, S_IRUSR | S_IWUSR);
        unlink(tmpsocket_name);
-       if (fd < 0)
+       if (ret < 0)
                goto out;
+       fd = ret;
        ret = -E_INIT_SOCK_ADDR;
        if (init_unix_addr(&unix_addr, socket_name) < 0)
                goto out;
-       ret = - E_CONNECT;
+       ret = - E_AUDIOC_CONNECT;
        if (connect(fd, (struct sockaddr *)&unix_addr, UNIX_PATH_MAX) < 0)
                goto out;
+       fprintf(stderr, "loaded: %d\n", loaded);
        ret = -E_CREDENTIALS;
        if (send_cred_buffer(fd, args) < 0)
                goto out;
@@ -125,19 +139,17 @@ int main(int argc, char *argv[])
                        para_fd_set(STDOUT_FILENO, &wfd, &max_fileno);
                        check_write = 1;
                }
-               ret = -E_OVERRUN;
+               ret = -E_AUDIOC_OVERRUN;
                if (max_fileno < 0)
                        goto out;
                ret = para_select(max_fileno + 1, &rfd, &wfd, NULL);
-               if (ret < 0) {
-                       ret = -E_SELECT;
+               if (ret < 0)
                        goto out;
-               }
                if (loaded < conf.bufsize_arg && FD_ISSET(fd, &rfd)) {
                        len = recv_bin_buffer(fd, buf + loaded,
                                conf.bufsize_arg - loaded);
                        if (len <= 0) {
-                               ret = len < 0? -E_READ : 0;
+                               ret = len < 0? -E_AUDIOC_READ : 0;
                                goto out;
                        }
                        loaded += len;
@@ -145,7 +157,7 @@ int main(int argc, char *argv[])
                if (check_write && FD_ISSET(STDOUT_FILENO, &wfd)) {
                        ret = write(STDOUT_FILENO, buf, loaded);
                        if (ret < 0) {
-                               ret = -E_WRITE;
+                               ret = -E_AUDIOC_WRITE;
                                goto out;
                        }
                        loaded -= ret;
@@ -154,5 +166,7 @@ int main(int argc, char *argv[])
 out:
        if (!ret && loaded && buf)
                ret = write(STDOUT_FILENO, buf, loaded);
-       return ret < 0? -ret : EXIT_SUCCESS;
+       if (ret < 0)
+               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+       return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
 }
index 3c2f4ec..dc48c03 100644 (file)
@@ -64,6 +64,9 @@ filter_cmdline_objs="filter.cmdline compress_filter.cmdline"
 filter_errlist_objs="filter_chain wav compress filter string stdin stdout sched fd"
 filter_ldflags=""
 
+audioc_cmdline_objs="audioc.cmdline"
+audioc_errlist_objs="audioc string net fd"
+
 audiod_cmdline_objs="audiod.cmdline grab_client.cmdline compress_filter.cmdline
        http_recv.cmdline dccp_recv.cmdline file_write.cmdline"
 audiod_errlist_objs="audiod exec close_on_fork signal string daemon stat net
@@ -358,6 +361,7 @@ audiod_objs="$audiod_cmdline_objs $audiod_errlist_objs"
 server_objs="$server_cmdline_objs $server_errlist_objs"
 write_objs="$write_cmdline_objs $write_errlist_objs"
 client_objs="$client_cmdline_objs $client_errlist_objs"
+audioc_objs="$audioc_cmdline_objs $audioc_errlist_objs"
 
 AC_SUBST(recv_objs, add_dot_o($recv_objs))
 AC_SUBST(recv_ldflags, $recv_ldflags)
@@ -389,6 +393,10 @@ AC_SUBST(client_ldflags, $client_ldflags)
 AC_DEFINE_UNQUOTED(INIT_CLIENT_ERRLISTS,
        objlist_to_errlist($client_errlist_objs), errors used by para_client)
 
+AC_SUBST(audioc_objs, add_dot_o($audioc_objs))
+AC_DEFINE_UNQUOTED(INIT_AUDIOC_ERRLISTS,
+       objlist_to_errlist($audioc_errlist_objs), errors used by para_audioc)
+
 enum="$(for i in $write_writers; do printf "${i}_WRITE, " | tr '[a-z]' '[A-Z]'; done)"
 AC_DEFINE_UNQUOTED(WRITER_ENUM, $enum NUM_SUPPORTED_WRITERS,
        enum of supported writers)
diff --git a/error.h b/error.h
index 983f653..285191c 100644 (file)
--- a/error.h
+++ b/error.h
@@ -20,8 +20,6 @@
 
 /** \cond list of all subsystems that support the shiny error facility */
 enum para_subsystem {
-       SS_CLIENT,
-       SS_SCHED,
        SS_GUI,
        SS_TIME,
        SS_WAV,
@@ -33,6 +31,9 @@ enum para_subsystem {
        SS_RECV,
        SS_NET,
        SS_ORTP_RECV,
+       SS_CLIENT,
+       SS_AUDIOC,
+       SS_SCHED,
        SS_AUDIOD,
        SS_AUDIOD_COMMAND,
        SS_EXEC,
@@ -90,6 +91,16 @@ enum para_subsystem {
 extern const char **para_errlist[];
 /** \endcond */
 
+#define AUDIOC_ERRORS \
+       PARA_ERROR(AUDIOC_SYNTAX, "audioc syntax error"), \
+       PARA_ERROR(AUDIOC_READ, "audioc read error"), \
+       PARA_ERROR(AUDIOC_WRITE, "audioc write error"), \
+       PARA_ERROR(INIT_SOCK_ADDR, "can not init socket"), \
+       PARA_ERROR(AUDIOC_CONNECT, "audioc connect error"), \
+       PARA_ERROR(CREDENTIALS, "failed to send unix socket credentials"), \
+       PARA_ERROR(AUDIOC_OVERRUN, "audioc buffer overrun"), \
+
+
 #define CLIENT_ERRORS \
        PARA_ERROR(CLIENT_SYNTAX, "syntax error"), \
        PARA_ERROR(INVALID_CHALLENGE, "did not receive valid challenge"), \
@@ -538,6 +549,7 @@ SS_ENUM(ALSA_WRITER);
 SS_ENUM(FILE_WRITER);
 SS_ENUM(RINGBUFFER);
 SS_ENUM(CLIENT);
+SS_ENUM(AUDIOC);
 /** \endcond */
 #undef PARA_ERROR
 /* rest of the world only sees the error text */