X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audioc.c;h=6a8867182e42bb1a7d6041d4ae0e55fbcba1164d;hp=84c2a39472f6fcf58f7c6fecf62e752d35d1a098;hb=b01605d7062e4d1f005d5aaaaed158d8efe06d79;hpb=f0e41e36c3f1a3a5bb6ff66d92d2814391d8f908 diff --git a/audioc.c b/audioc.c index 84c2a394..6a886718 100644 --- a/audioc.c +++ b/audioc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Andre Noll + * Copyright (C) 2005-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -106,7 +106,7 @@ static void audioc_pre_select(struct sched *s, struct task *t) para_fd_set(at->fd, &s->rfds, &s->max_fileno); } -static void audioc_post_select(struct sched *s, struct task *t) +static int audioc_post_select(struct sched *s, struct task *t) { char *buf = NULL; struct audioc_task *at = container_of(t, struct audioc_task, task); @@ -115,7 +115,7 @@ static void audioc_post_select(struct sched *s, struct task *t) if (ret < 0) goto out; if (!FD_ISSET(at->fd, &s->rfds)) - return; + return 0; buf = para_malloc(conf.bufsize_arg); ret = recv_bin_buffer(at->fd, buf, conf.bufsize_arg); PARA_DEBUG_LOG("recv: %d\n", ret); @@ -124,16 +124,14 @@ static void audioc_post_select(struct sched *s, struct task *t) if (ret < 0) goto out; btr_add_output(buf, ret, at->btrn); - return; + return 0; out: if (ret < 0) { free(buf); - btr_remove_node(at->btrn); - btr_free_node(at->btrn); - at->btrn = NULL; + btr_remove_node(&at->btrn); close(at->fd); } - t->error = ret; + return ret; } static struct audioc_task audioc_task = { @@ -253,16 +251,15 @@ __noreturn static void print_completions(void) static char *configfile_exists(void) { - static char *config_file; + char *config_file; struct stat statbuf; + char *home = para_homedir(); - if (!config_file) { - char *home = para_homedir(); - config_file = make_message("%s/.paraslash/audioc.conf", home); - free(home); - } + config_file = make_message("%s/.paraslash/audioc.conf", home); + free(home); if (!stat(config_file, &statbuf)) return config_file; + free(config_file); return NULL; } @@ -272,10 +269,11 @@ static char *configfile_exists(void) * \param argc Usual argument count. * \param argv Usual argument vector. * - * It creates a temporary local socket in order to communicate with para_audiod. - * Authentication consists in sending a ucred buffer that contains the user id. + * It connects to the "well-known" local socket to communicate with + * para_audiod. Authentication is performed by sending a ucred buffer + * containing the user id to the local socket. * - * Any output received through the local socket is sent to stdout. + * Any data received from the socket is written to stdout. * * \return EXIT_SUCCESS or EXIT_FAILURE. * @@ -283,27 +281,27 @@ static char *configfile_exists(void) */ int main(int argc, char *argv[]) { - int ret = -E_AUDIOC_SYNTAX, fd; - char *cf, *buf = NULL, *args; + int ret, fd; + char *cf, *buf = NULL, *args = NULL; size_t bufsize; - if (audioc_cmdline_parser(argc, argv, &conf)) - goto out; + audioc_cmdline_parser(argc, argv, &conf); HANDLE_VERSION_FLAG("audioc", conf); + loglevel = get_loglevel_by_name(conf.loglevel_arg); cf = configfile_exists(); if (cf) { struct audioc_cmdline_parser_params params = { .override = 0, .initialize = 0, .check_required = 0, - .check_ambiguity = 0 + .check_ambiguity = 0, + .print_errors = 1, + }; - if (audioc_cmdline_parser_config_file(cf, &conf, ¶ms)) { - fprintf(stderr, "parse error in config file\n"); - exit(EXIT_FAILURE); - } + audioc_cmdline_parser_config_file(cf, &conf, ¶ms); + free(cf); + loglevel = get_loglevel_by_name(conf.loglevel_arg); } - loglevel = get_loglevel_by_name(conf.loglevel_arg); if (conf.socket_given) socket_name = para_strdup(conf.socket_arg); else { @@ -342,6 +340,8 @@ int main(int argc, char *argv[]) ret = write_all(STDOUT_FILENO, buf, n); } while (ret >= 0); out: + free(buf); + free(args); if (ret < 0) PARA_ERROR_LOG("%s\n", para_strerror(-ret)); return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;