]>
code.delx.au - pulseaudio/blob - src/utils/pacmd.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <sys/select.h>
29 #include <sys/socket.h>
35 #include <polyp/error.h>
36 #include <polyp/util.h>
38 #include <polypcore/core-util.h>
39 #include <polypcore/log.h>
40 #include <polypcore/pid.h>
42 int main(PA_GCC_UNUSED
int argc
, PA_GCC_UNUSED
char*argv
[]) {
46 struct sockaddr_un sa
;
47 char ibuf
[256], obuf
[256];
48 size_t ibuf_index
, ibuf_length
, obuf_index
, obuf_length
;
51 if (pa_pid_file_check_running(&pid
) < 0) {
52 pa_log(__FILE__
": no Polypaudio daemon running");
56 if ((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) < 0) {
57 pa_log(__FILE__
": socket(PF_UNIX, SOCK_STREAM, 0): %s", strerror(errno
));
61 memset(&sa
, 0, sizeof(sa
));
62 sa
.sun_family
= AF_UNIX
;
63 pa_runtime_path("cli", sa
.sun_path
, sizeof(sa
.sun_path
));
65 for (i
= 0; i
< 5; i
++) {
68 if ((r
= connect(fd
, (struct sockaddr
*) &sa
, sizeof(sa
))) < 0 && (errno
!= ECONNREFUSED
&& errno
!= ENOENT
)) {
69 pa_log(__FILE__
": connect(): %s", strerror(errno
));
76 if (pa_pid_file_kill(SIGUSR2
, NULL
) < 0) {
77 pa_log(__FILE__
": failed to kill Polypaudio daemon.");
85 pa_log(__FILE__
": daemon not responding.");
89 ibuf_index
= ibuf_length
= obuf_index
= obuf_length
= 0;
99 if (select(FD_SETSIZE
, &ifds
, &ofds
, NULL
, NULL
) < 0) {
100 pa_log(__FILE__
": select(): %s", strerror(errno
));
104 if (FD_ISSET(0, &ifds
)) {
106 assert(!ibuf_length
);
108 if ((r
= read(0, ibuf
, sizeof(ibuf
))) <= 0) {
112 pa_log(__FILE__
": read(): %s", strerror(errno
));
116 ibuf_length
= (size_t) r
;
120 if (FD_ISSET(fd
, &ifds
)) {
122 assert(!obuf_length
);
124 if ((r
= read(fd
, obuf
, sizeof(obuf
))) <= 0) {
128 pa_log(__FILE__
": read(): %s", strerror(errno
));
132 obuf_length
= (size_t) r
;
136 if (FD_ISSET(1, &ofds
)) {
140 if ((r
= write(1, obuf
+ obuf_index
, obuf_length
)) < 0) {
141 pa_log(__FILE__
": write(): %s", strerror(errno
));
145 obuf_length
-= (size_t) r
;
146 obuf_index
+= obuf_index
;
150 if (FD_ISSET(fd
, &ofds
)) {
154 if ((r
= write(fd
, ibuf
+ ibuf_index
, ibuf_length
)) < 0) {
155 pa_log(__FILE__
": write(): %s", strerror(errno
));
159 ibuf_length
-= (size_t) r
;
160 ibuf_index
+= obuf_index
;
167 if (obuf_length
<= 0)
172 if (ibuf_length
<= 0)