4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <sys/select.h>
31 #include <sys/socket.h>
37 #include <pulse/error.h>
38 #include <pulse/util.h>
40 #include <pulsecore/core-util.h>
41 #include <pulsecore/log.h>
42 #include <pulsecore/pid.h>
44 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
48 struct sockaddr_un sa;
49 char ibuf[256], obuf[256];
50 size_t ibuf_index, ibuf_length, obuf_index, obuf_length;
53 if (pa_pid_file_check_running(&pid) < 0) {
54 pa_log("no PulseAudio daemon running");
58 if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
59 pa_log("socket(PF_UNIX, SOCK_STREAM, 0): %s", strerror(errno));
63 memset(&sa, 0, sizeof(sa));
64 sa.sun_family = AF_UNIX;
65 pa_runtime_path("cli", sa.sun_path, sizeof(sa.sun_path));
67 for (i = 0; i < 5; i++) {
70 if ((r = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && (errno != ECONNREFUSED && errno != ENOENT)) {
71 pa_log("connect(): %s", strerror(errno));
78 if (pa_pid_file_kill(SIGUSR2, NULL) < 0) {
79 pa_log("failed to kill PulseAudio daemon.");
87 pa_log("daemon not responding.");
91 ibuf_index = ibuf_length = obuf_index = obuf_length = 0;
101 if (select(FD_SETSIZE, &ifds, &ofds, NULL, NULL) < 0) {
102 pa_log("select(): %s", strerror(errno));
106 if (FD_ISSET(0, &ifds)) {
108 assert(!ibuf_length);
110 if ((r = read(0, ibuf, sizeof(ibuf))) <= 0) {
114 pa_log("read(): %s", strerror(errno));
118 ibuf_length = (size_t) r;
122 if (FD_ISSET(fd, &ifds)) {
124 assert(!obuf_length);
126 if ((r = read(fd, obuf, sizeof(obuf))) <= 0) {
130 pa_log("read(): %s", strerror(errno));
134 obuf_length = (size_t) r;
138 if (FD_ISSET(1, &ofds)) {
142 if ((r = write(1, obuf + obuf_index, obuf_length)) < 0) {
143 pa_log("write(): %s", strerror(errno));
147 obuf_length -= (size_t) r;
148 obuf_index += obuf_index;
152 if (FD_ISSET(fd, &ofds)) {
156 if ((r = write(fd, ibuf + ibuf_index, ibuf_length)) < 0) {
157 pa_log("write(): %s", strerror(errno));
161 ibuf_length -= (size_t) r;
162 ibuf_index += obuf_index;
169 if (obuf_length <= 0)
174 if (ibuf_length <= 0)