2 * Copyright (C) 2005-2008 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 */
12 #include "audioc.cmdline.h"
21 /** the gengetopt structure containing command line args */
22 struct audioc_args_info conf
;
24 INIT_STDERR_LOGGING(conf
.loglevel_arg
);
26 static char *concat_args(unsigned argc
, char * const *argv
)
28 int i
; char *buf
= NULL
;
29 for (i
= 0; i
< argc
; i
++) {
30 buf
= para_strcat(buf
, argv
[i
]);
32 buf
= para_strcat(buf
, "\n");
37 static char *configfile_exists(void)
39 static char *config_file
;
44 char *home
= para_homedir();
45 config_file
= make_message("%s/.paraslash/audioc.conf", home
);
48 if (!stat(config_file
, &statbuf
))
54 * the client program to connect to para_audiod
56 * \param argc usual argument count
57 * \param argv usual argument vector
59 * It creates a temporary local socket in order to communicate with para_audiod.
60 * Authentication consists in sending a ucred buffer that contains the user id.
62 * Any output received through the local socket is sent to stdout.
64 * \return EXIT_SUCCESS or EXIT_FAILURE
66 * \sa send_cred_buffer(), para_audioc(1), para_audiod(1).
68 int main(int argc
, char *argv
[])
70 int ret
= -E_AUDIOC_SYNTAX
, fd
;
71 char *cf
, *buf
= NULL
, *args
;
72 size_t bufsize
, loaded
= 0;
74 if (audioc_cmdline_parser(argc
, argv
, &conf
))
76 HANDLE_VERSION_FLAG("audioc", conf
);
77 cf
= configfile_exists();
79 struct audioc_cmdline_parser_params params
= {
85 if (audioc_cmdline_parser_config_file(cf
, &conf
, ¶ms
)) {
86 fprintf(stderr
, "parse error in config file\n");
90 args
= conf
.inputs_num
?
91 concat_args(conf
.inputs_num
, conf
.inputs
) :
93 bufsize
= conf
.bufsize_arg
;
94 buf
= para_malloc(bufsize
);
96 if (conf
.socket_given
) {
97 ret
= create_remote_socket(conf
.socket_arg
);
99 char *hn
= para_hostname(),
100 *socket_name
= make_message("/var/paraslash/audiod_socket.%s", hn
);
102 ret
= create_remote_socket(socket_name
);
109 ret
= mark_fd_nonblocking(fd
);
112 ret
= mark_fd_nonblocking(STDOUT_FILENO
);
115 ret
= send_cred_buffer(fd
, args
);
119 int max_fileno
= -1, check_write
= 0;
124 if (loaded
< bufsize
)
125 para_fd_set(fd
, &rfd
, &max_fileno
);
127 para_fd_set(STDOUT_FILENO
, &wfd
, &max_fileno
);
130 ret
= -E_AUDIOC_OVERRUN
;
133 ret
= para_select(max_fileno
+ 1, &rfd
, &wfd
, NULL
);
136 if (loaded
< bufsize
&& FD_ISSET(fd
, &rfd
)) {
137 len
= recv_bin_buffer(fd
, buf
+ loaded
,
140 ret
= len
< 0? -E_AUDIOC_READ
: 0;
145 if (check_write
&& FD_ISSET(STDOUT_FILENO
, &wfd
)) {
146 ret
= write(STDOUT_FILENO
, buf
, loaded
);
148 ret
= -E_AUDIOC_WRITE
;
155 if (!ret
&& loaded
&& buf
)
156 ret
= write(STDOUT_FILENO
, buf
, loaded
);
158 PARA_ERROR_LOG("%s\n", para_strerror(-ret
));
159 return ret
< 0? EXIT_FAILURE
: EXIT_SUCCESS
;