X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audioc.c;h=5f6b5ae1195645e3a8b4c2b458559625a036701c;hp=6a8867182e42bb1a7d6041d4ae0e55fbcba1164d;hb=d1e6b28f66e243516d01916f9125baee75dd98d6;hpb=b01605d7062e4d1f005d5aaaaed158d8efe06d79 diff --git a/audioc.c b/audioc.c index 6a886718..5f6b5ae1 100644 --- a/audioc.c +++ b/audioc.c @@ -1,13 +1,18 @@ /* - * Copyright (C) 2005-2013 Andre Noll + * Copyright (C) 2005-2014 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ /** \file audioc.c The client program used to connect to para_audiod. */ +#include +#include #include #include +#include +#include +#include #include #include @@ -17,6 +22,7 @@ #include "net.h" #include "string.h" #include "fd.h" +#include "ggo.h" #include "version.h" INIT_AUDIOC_ERRLISTS; @@ -42,6 +48,25 @@ static char *concat_args(unsigned argc, char * const *argv) return buf; } +static int connect_audiod(const char *sname, char *args) +{ + int fd = -1, ret; + + ret = connect_local_socket(sname); + if (ret < 0) + goto fail; + fd = ret; + ret = send_cred_buffer(fd, args); + if (ret < 0) + goto fail; + return fd; +fail: + PARA_ERROR_LOG("could not connect %s\n", sname); + if (fd >= 0) + close(fd); + return ret; +} + #ifdef HAVE_READLINE #include "list.h" #include "sched.h" @@ -146,8 +171,6 @@ static int audioc_i9e_line_handler(char *line) { char *args = NULL; int ret; - if (!line || !*line) - return 0; PARA_DEBUG_LOG("line: %s\n", line); ret = create_argv(line, " ", &conf.inputs); @@ -156,15 +179,14 @@ static int audioc_i9e_line_handler(char *line) conf.inputs_num = ret; args = concat_args(conf.inputs_num, conf.inputs); free_argv(conf.inputs); + if (!args) + return 0; conf.inputs_num = 0; /* required for audioc_cmdline_parser_free() */ - ret = connect_local_socket(socket_name); + ret = connect_audiod(socket_name, args); if (ret < 0) goto out; at->fd = ret; ret = mark_fd_nonblocking(at->fd); - if (ret < 0) - goto close; - ret = send_cred_buffer(at->fd, args); if (ret < 0) goto close; free(args); @@ -194,7 +216,7 @@ __noreturn static void interactive_session(void) .loglevel = loglevel, .completers = audiod_completers, }; - PARA_NOTICE_LOG("\n%s\n", VERSION_TEXT("audioc")); + PARA_NOTICE_LOG("\n%s\n", version_text("audioc")); if (conf.history_file_given) history_file = para_strdup(conf.history_file_arg); else { @@ -263,6 +285,15 @@ static char *configfile_exists(void) return NULL; } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(audioc); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + /** * The client program to connect to para_audiod. * @@ -286,8 +317,10 @@ int main(int argc, char *argv[]) size_t bufsize; audioc_cmdline_parser(argc, argv, &conf); - HANDLE_VERSION_FLAG("audioc", conf); loglevel = get_loglevel_by_name(conf.loglevel_arg); + version_handle_flag("audioc", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); cf = configfile_exists(); if (cf) { struct audioc_cmdline_parser_params params = { @@ -318,21 +351,16 @@ int main(int argc, char *argv[]) interactive_session(); args = concat_args(conf.inputs_num, conf.inputs); - ret = connect_local_socket(socket_name); + ret = connect_audiod(socket_name, args); free(socket_name); - if (ret < 0) { - PARA_EMERG_LOG("failed to connect to local socket\n"); + if (ret < 0) goto out; - } fd = ret; - ret = send_cred_buffer(fd, args); + ret = mark_fd_blocking(STDOUT_FILENO); if (ret < 0) goto out; bufsize = conf.bufsize_arg; buf = para_malloc(bufsize); - ret = mark_fd_blocking(STDOUT_FILENO); - if (ret < 0) - goto out; do { size_t n = ret = recv_bin_buffer(fd, buf, bufsize); if (ret <= 0)