README.afs: Update the Troubles section.
[paraslash.git] / audioc.c
index 0036da83144bc180d1f3df104f93e4276caaf1b7..fa1768b52f26eb69b6806f18c42d098a0267259e 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -1,11 +1,12 @@
 /*
- * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file audioc.c the client program used to connect to para_audiod */
 
+#include <regex.h>
 #include <sys/types.h>
 #include <dirent.h>
 
 
 INIT_AUDIOC_ERRLISTS;
 
-/** the gengetopt structure containing command line args */
-struct audioc_args_info conf;
+/** The gengetopt structure containing command line args. */
+static struct audioc_args_info conf;
 
-INIT_STDERR_LOGGING(conf.loglevel_arg);
+static int loglevel;
+INIT_STDERR_LOGGING(loglevel);
 
 static char *concat_args(unsigned argc, char * const *argv)
 {
@@ -70,7 +72,6 @@ int main(int argc, char *argv[])
        int ret = -E_AUDIOC_SYNTAX, fd;
        char *cf, *buf = NULL, *args;
        size_t bufsize, loaded = 0;
-       struct sockaddr_un unix_addr;
 
        if (audioc_cmdline_parser(argc, argv, &conf))
                goto out;
@@ -88,27 +89,30 @@ int main(int argc, char *argv[])
                        exit(EXIT_FAILURE);
                }
        }
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        args = conf.inputs_num?
                concat_args(conf.inputs_num, conf.inputs) :
                para_strdup("stat");
        bufsize = conf.bufsize_arg;
        buf = para_malloc(bufsize);
-       ret = get_stream_socket(PF_UNIX);
-       if (ret < 0)
-               goto out;
-       fd = ret;
-       if (conf.socket_given)
-               ret = init_unix_addr(&unix_addr, conf.socket_arg);
-       else {
-               char *hn = para_hostname(), *socket_name = make_message(
-                       "/var/paraslash/audiod_socket.%s", hn);
+
+       if (conf.socket_given) {
+               ret = create_remote_socket(conf.socket_arg);
+       } else {
+               char *hn = para_hostname(),
+                    *socket_name = make_message("/var/paraslash/audiod_socket.%s", hn);
+
+               ret = create_remote_socket(socket_name);
                free(hn);
-               ret = init_unix_addr(&unix_addr, socket_name);
                free(socket_name);
        }
        if (ret < 0)
                goto out;
-       ret = PARA_CONNECT(fd, &unix_addr);
+       fd = ret;
+       ret = mark_fd_nonblocking(fd);
+       if (ret < 0)
+               goto out;
+       ret = mark_fd_nonblocking(STDOUT_FILENO);
        if (ret < 0)
                goto out;
        ret = send_cred_buffer(fd, args);
@@ -148,12 +152,14 @@ int main(int argc, char *argv[])
                                goto out;
                        }
                        loaded -= ret;
+                       if (loaded && ret)
+                               memmove(buf, buf + ret, loaded);
                }
        }
 out:
        if (!ret && loaded && buf)
                ret = write(STDOUT_FILENO, buf, loaded);
        if (ret < 0)
-               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+               PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
 }