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>
39 #include <pulse/xmalloc.h>
41 #include <pulsecore/core-util.h>
42 #include <pulsecore/log.h>
43 #include <pulsecore/pid.h>
45 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
49 struct sockaddr_un sa;
50 char ibuf[256], obuf[256];
51 size_t ibuf_index, ibuf_length, obuf_index, obuf_length;
55 if (pa_pid_file_check_running(&pid, "pulseaudio") < 0) {
56 pa_log("no PulseAudio daemon running");
60 if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
61 pa_log("socket(PF_UNIX, SOCK_STREAM, 0): %s", strerror(errno));
65 memset(&sa, 0, sizeof(sa));
66 sa.sun_family = AF_UNIX;
68 cli = pa_runtime_path("cli");
69 pa_strlcpy(sa.sun_path, cli, sizeof(sa.sun_path));
72 for (i = 0; i < 5; i++) {
75 if ((r = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && (errno != ECONNREFUSED && errno != ENOENT)) {
76 pa_log("connect(): %s", strerror(errno));
83 if (pa_pid_file_kill(SIGUSR2, NULL, "pulseaudio") < 0) {
84 pa_log("failed to kill PulseAudio daemon.");
92 pa_log("daemon not responding.");
96 ibuf_index = ibuf_length = obuf_index = obuf_length = 0;
106 if (select(FD_SETSIZE, &ifds, &ofds, NULL, NULL) < 0) {
107 pa_log("select(): %s", strerror(errno));
111 if (FD_ISSET(0, &ifds)) {
113 assert(!ibuf_length);
115 if ((r = read(0, ibuf, sizeof(ibuf))) <= 0) {
119 pa_log("read(): %s", strerror(errno));
123 ibuf_length = (size_t) r;
127 if (FD_ISSET(fd, &ifds)) {
129 assert(!obuf_length);
131 if ((r = read(fd, obuf, sizeof(obuf))) <= 0) {
135 pa_log("read(): %s", strerror(errno));
139 obuf_length = (size_t) r;
143 if (FD_ISSET(1, &ofds)) {
147 if ((r = write(1, obuf + obuf_index, obuf_length)) < 0) {
148 pa_log("write(): %s", strerror(errno));
152 obuf_length -= (size_t) r;
153 obuf_index += obuf_index;
157 if (FD_ISSET(fd, &ofds)) {
161 if ((r = write(fd, ibuf + ibuf_index, ibuf_length)) < 0) {
162 pa_log("write(): %s", strerror(errno));
166 ibuf_length -= (size_t) r;
167 ibuf_index += obuf_index;
174 if (obuf_length <= 0)
179 if (ibuf_length <= 0)