2 * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file audioc.c the client program used to connect to para_audiod */
10 #include <sys/types.h>
12 #include "audioc.cmdline.h"
21 /** The gengetopt structure containing command line args. */
22 static struct audioc_args_info conf;
25 INIT_STDERR_LOGGING(loglevel);
27 static char *concat_args(unsigned argc, char * const *argv)
29 int i; char *buf = NULL;
30 for (i = 0; i < argc; i++) {
31 buf = para_strcat(buf, argv[i]);
33 buf = para_strcat(buf, "\n");
38 static char *configfile_exists(void)
40 static char *config_file;
45 char *home = para_homedir();
46 config_file = make_message("%s/.paraslash/audioc.conf", home);
49 if (!stat(config_file, &statbuf))
55 * the client program to connect to para_audiod
57 * \param argc usual argument count
58 * \param argv usual argument vector
60 * It creates a temporary local socket in order to communicate with para_audiod.
61 * Authentication consists in sending a ucred buffer that contains the user id.
63 * Any output received through the local socket is sent to stdout.
65 * \return EXIT_SUCCESS or EXIT_FAILURE
67 * \sa send_cred_buffer(), para_audioc(1), para_audiod(1).
69 int main(int argc, char *argv[])
71 int ret = -E_AUDIOC_SYNTAX, fd;
72 char *cf, *buf = NULL, *args;
75 if (audioc_cmdline_parser(argc, argv, &conf))
77 HANDLE_VERSION_FLAG("audioc", conf);
78 cf = configfile_exists();
80 struct audioc_cmdline_parser_params params = {
86 if (audioc_cmdline_parser_config_file(cf, &conf, ¶ms)) {
87 fprintf(stderr, "parse error in config file\n");
91 loglevel = get_loglevel_by_name(conf.loglevel_arg);
92 args = conf.inputs_num?
93 concat_args(conf.inputs_num, conf.inputs) :
96 if (conf.socket_given)
97 ret = connect_local_socket(conf.socket_arg);
99 char *hn = para_hostname(), *socket_name = make_message(
100 "/var/paraslash/audiod_socket.%s", hn);
101 ret = connect_local_socket(socket_name);
106 PARA_EMERG_LOG("failed to connect to local socket\n");
110 ret = send_cred_buffer(fd, args);
113 bufsize = conf.bufsize_arg;
114 buf = para_malloc(bufsize);
116 size_t n = ret = recv_bin_buffer(fd, buf, bufsize);
119 ret = write_all(STDOUT_FILENO, buf, &n);
123 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
124 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;