216afa2f11aeebc132d23ad2a96664daf9e384cd
2 * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file audioc.c the client program used to connect to para_audiod */
21 #include "audioc.cmdline.h"
30 struct audioc_args_info conf
;
33 INIT_STDERR_LOGGING(conf
.loglevel_arg
);
35 static char *concat_args(const int argc
, char * const *argv
)
37 int i
; char *buf
= NULL
;
38 for (i
= 0; i
< argc
; i
++) {
39 buf
= para_strcat(buf
, argv
[i
]);
41 buf
= para_strcat(buf
, "\n");
46 static char *configfile_exists(void)
48 static char *config_file
;
53 char *home
= para_homedir();
54 config_file
= make_message("%s/.paraslash/audioc.conf", home
);
57 if (!stat(config_file
, &statbuf
))
62 int main(int argc
, char *argv
[])
64 struct sockaddr_un unix_addr
;
65 int ret
= -E_AUDIOC_SYNTAX
, fd
, loaded
= 0;
66 char *cf
, *socket_name
, *randname
= para_tmpname(), *tmpsocket_name
= NULL
,
67 *buf
= NULL
, *hn
= para_hostname(), *args
, *home
= para_homedir();
70 if (audioc_cmdline_parser(argc
, argv
, &conf
))
72 HANDLE_VERSION_FLAG("audioc", conf
);
73 cf
= configfile_exists();
75 if (audioc_cmdline_parser_configfile(cf
, &conf
, 0, 0, 0)) {
76 fprintf(stderr
, "parse error in config file\n");
80 args
= conf
.inputs_num
?
81 concat_args(conf
.inputs_num
, conf
.inputs
) :
83 buf
= para_malloc(conf
.bufsize_arg
);
84 if (conf
.socket_given
)
85 socket_name
= para_strdup(conf
.socket_arg
);
87 socket_name
= make_message(
88 "/var/paraslash/audiod_socket.%s", hn
);
89 if (conf
.tmpdir_given
)
90 tmpsocket_name
= make_message("%s/audioc.sock.%s.%s",
91 conf
.tmpdir_arg
, hn
, randname
);
93 tmpsocket_name
= make_message("%s/.paraslash/audioc_sock.%s.%s",
96 ret
= create_pf_socket(tmpsocket_name
, &unix_addr
, S_IRUSR
| S_IWUSR
);
97 unlink(tmpsocket_name
);
101 ret
= -E_INIT_SOCK_ADDR
;
102 if (init_unix_addr(&unix_addr
, socket_name
) < 0)
104 ret
= - E_AUDIOC_CONNECT
;
105 if (connect(fd
, (struct sockaddr
*)&unix_addr
, UNIX_PATH_MAX
) < 0)
107 ret
= send_cred_buffer(fd
, args
);
111 int max_fileno
= -1, check_write
= 0;
116 if (loaded
< conf
.bufsize_arg
)
117 para_fd_set(fd
, &rfd
, &max_fileno
);
119 para_fd_set(STDOUT_FILENO
, &wfd
, &max_fileno
);
122 ret
= -E_AUDIOC_OVERRUN
;
125 ret
= para_select(max_fileno
+ 1, &rfd
, &wfd
, NULL
);
128 if (loaded
< conf
.bufsize_arg
&& FD_ISSET(fd
, &rfd
)) {
129 len
= recv_bin_buffer(fd
, buf
+ loaded
,
130 conf
.bufsize_arg
- loaded
);
132 ret
= len
< 0? -E_AUDIOC_READ
: 0;
137 if (check_write
&& FD_ISSET(STDOUT_FILENO
, &wfd
)) {
138 ret
= write(STDOUT_FILENO
, buf
, loaded
);
140 ret
= -E_AUDIOC_WRITE
;
147 if (!ret
&& loaded
&& buf
)
148 ret
= write(STDOUT_FILENO
, buf
, loaded
);
150 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret
));
151 return ret
< 0? EXIT_FAILURE
: EXIT_SUCCESS
;