X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audioc.c;h=d3e092e29301f71e02948259483623e56967966f;hp=73bc2cf36bc0bbd51f43490548c2241e65bf13b0;hb=b1bf3612a6a5f0381fe6c12b96c73d1bbcbe7d56;hpb=a535ae69516f69b594eb7199175f7f4559152a4e diff --git a/audioc.c b/audioc.c index 73bc2cf3..d3e092e2 100644 --- a/audioc.c +++ b/audioc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Andre Noll + * Copyright (C) 2005-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -9,6 +9,7 @@ #include #include #include +#include #include "audioc.cmdline.h" #include "para.h" @@ -252,16 +253,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; } @@ -271,10 +271,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,7 +284,7 @@ static char *configfile_exists(void) int main(int argc, char *argv[]) { int ret = -E_AUDIOC_SYNTAX, fd; - char *cf, *buf = NULL, *args; + char *cf, *buf = NULL, *args = NULL; size_t bufsize; if (audioc_cmdline_parser(argc, argv, &conf)) @@ -297,7 +298,9 @@ int main(int argc, char *argv[]) .check_required = 0, .check_ambiguity = 0 }; - if (audioc_cmdline_parser_config_file(cf, &conf, ¶ms)) { + ret = audioc_cmdline_parser_config_file(cf, &conf, ¶ms); + free(cf); + if (ret) { fprintf(stderr, "parse error in config file\n"); exit(EXIT_FAILURE); } @@ -331,13 +334,18 @@ int main(int argc, char *argv[]) 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) break; - ret = write_all(STDOUT_FILENO, buf, &n); + 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;