From cf39e478f5379506a003ab8a0a2f14ee8fcf98e4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 2 Apr 2013 02:02:21 +0000 Subject: [PATCH] audioc: Abstract out connection code. This way we get a nice error message in interactive mode when para_audiod is down. Before: para_audioc> help i9e_line_handler: No such file or directory After: para_audioc> help connect_audiod: could not connect /var/paraslash/audiod_socket.schubert i9e_line_handler: No such file or directory --- audioc.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/audioc.c b/audioc.c index 74fb11cb..f68aee54 100644 --- a/audioc.c +++ b/audioc.c @@ -42,6 +42,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" @@ -157,14 +176,11 @@ static int audioc_i9e_line_handler(char *line) args = concat_args(conf.inputs_num, conf.inputs); free_argv(conf.inputs); 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); @@ -320,21 +336,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) -- 2.39.5