summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-09-05 00:03:16 +0000
committerLennart Poettering <lennart@poettering.net>2004-09-05 00:03:16 +0000
commit6c4fd620408b3f14a1d4164d58db70df7a252674 (patch)
tree3767a0fb76a3941267f9b6980075149dc31cb6bc
parent57e473b61cf373f8d9befb03d359b999eca4262b (diff)
implement proper logging
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@179 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--configure.ac5
-rw-r--r--doc/todo1
-rw-r--r--polyp/Makefile.am9
-rw-r--r--polyp/authkey.c5
-rw-r--r--polyp/cli.c5
-rw-r--r--polyp/client.c7
-rw-r--r--polyp/cmdline.c20
-rw-r--r--polyp/cmdline.h13
-rw-r--r--polyp/core.h1
-rw-r--r--polyp/cpulimit.c3
-rw-r--r--polyp/gcc-printf.h10
-rw-r--r--polyp/log.c48
-rw-r--r--polyp/log.h17
-rw-r--r--polyp/main.c39
-rw-r--r--polyp/mainloop-signal.c7
-rw-r--r--polyp/mainloop.c5
-rw-r--r--polyp/memblockq.c7
-rw-r--r--polyp/module-alsa-sink.c23
-rw-r--r--polyp/module-alsa-source.c21
-rw-r--r--polyp/module-cli.c5
-rw-r--r--polyp/module-native-protocol-fd.c5
-rw-r--r--polyp/module-oss-mmap.c39
-rw-r--r--polyp/module-oss.c25
-rw-r--r--polyp/module-pipe-sink.c15
-rw-r--r--polyp/module-protocol-stub.c13
-rw-r--r--polyp/module-sine.c7
-rw-r--r--polyp/module-x11-bell.c13
-rw-r--r--polyp/module.c10
-rw-r--r--polyp/oss-util.c17
-rw-r--r--polyp/pdispatch.c5
-rwxr-xr-xpolyp/polypaudio.pa2
-rw-r--r--polyp/polyplib-context.c11
-rw-r--r--polyp/polyplib-simple.c3
-rw-r--r--polyp/protocol-esound.c23
-rw-r--r--polyp/protocol-native.c27
-rw-r--r--polyp/protocol-simple.c21
-rw-r--r--polyp/pstream.c7
-rw-r--r--polyp/sink-input.c5
-rw-r--r--polyp/sink.c5
-rw-r--r--polyp/socket-client.c15
-rw-r--r--polyp/socket-server.c17
-rw-r--r--polyp/socket-util.c7
-rw-r--r--polyp/sound-file-stream.c5
-rw-r--r--polyp/sound-file.c9
-rw-r--r--polyp/source-output.c3
-rw-r--r--polyp/source.c5
-rw-r--r--polyp/strbuf.h4
-rw-r--r--polyp/subscribe.c25
-rw-r--r--polyp/util.c41
-rw-r--r--polyp/util.h6
50 files changed, 416 insertions, 225 deletions
diff --git a/configure.ac b/configure.ac
index 7aa6c5d4..f221689d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,7 @@ AM_CONDITIONAL(X_DISPLAY_MISSING, test "x$X_DISPLAY_MISSING" != "x")
AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
+AC_TYPE_OFF_T
AC_HEADER_TIME
# Checks for library functions.
@@ -65,7 +66,9 @@ AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_SETPGRP
AC_TYPE_SIGNAL
-AC_CHECK_FUNCS([gethostname gettimeofday memchr memmove memset mkdir mkfifo munmap rmdir socket strcspn strerror strrchr strspn strstr strtol strtoul])
+AC_CHECK_FUNCS([gethostname gettimeofday memchr memmove memset mkdir mkfifo munmap rmdir socket strcspn strerror strrchr strspn strstr strtol strtoul pow strcasecmp])
+AC_FUNC_STAT
+AC_HEADER_SYS_WAIT
AC_C_BIGENDIAN
diff --git a/doc/todo b/doc/todo
index 5a1a247c..8ae9e739 100644
--- a/doc/todo
+++ b/doc/todo
@@ -9,7 +9,6 @@
kill client/...
autoload management
- more complete pactl
-- logging
- add sample directory
- add timing parameter to write callback of stream in client API
diff --git a/polyp/Makefile.am b/polyp/Makefile.am
index 33b052f3..335fa99a 100644
--- a/polyp/Makefile.am
+++ b/polyp/Makefile.am
@@ -143,7 +143,9 @@ polypaudio_SOURCES = idxset.c idxset.h \
subscribe.h subscribe.c \
debug.h \
sound-file-stream.c sound-file-stream.h \
- cpulimit.c cpulimit.h
+ cpulimit.c cpulimit.h \
+ log.c log.h \
+ gcc-printf.h
polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSNDFILE_CFLAGS)
polypaudio_INCLUDES = $(INCLTDL)
@@ -329,7 +331,10 @@ libpolyp_la_SOURCES = polyplib.h \
polyplib-subscribe.c polyplib-subscribe.h \
polyplib-internal.h \
cdecl.h \
- llist.h
+ llist.h \
+ log.c log.h \
+ gcc-printf.h
+
libpolyp_la_CFLAGS = $(AM_CFLAGS)
libpolyp_la_LDFLAGS = -version-info 0:0:0
diff --git a/polyp/authkey.c b/polyp/authkey.c
index 3180b8fd..bbc45c37 100644
--- a/polyp/authkey.c
+++ b/polyp/authkey.c
@@ -36,6 +36,7 @@
#include "authkey.h"
#include "util.h"
+#include "log.h"
#define RANDOM_DEVICE "/dev/urandom"
@@ -80,7 +81,7 @@ static int generate(const char *fn, void *data, size_t length) {
} else {
uint8_t *p;
size_t l;
- fprintf(stderr, "WARNING: Failed to open entropy device '"RANDOM_DEVICE"': %s, falling back to unsecure pseudo RNG.\n", strerror(errno));
+ pa_log(__FILE__": WARNING: Failed to open entropy device '"RANDOM_DEVICE"': %s, falling back to unsecure pseudo RNG.\n", strerror(errno));
srandom(time(NULL));
@@ -122,7 +123,7 @@ int pa_authkey_load(const char *path, void *data, size_t length) {
}
if (ret < 0)
- fprintf(stderr, "Failed to load authorization key '%s': %s\n", path, (ret == -1) ? strerror(errno) : "file corrupt");
+ pa_log(__FILE__": Failed to load authorization key '%s': %s\n", path, (ret == -1) ? strerror(errno) : "file corrupt");
return ret;
}
diff --git a/polyp/cli.c b/polyp/cli.c
index 6fd2c238..09e9855d 100644
--- a/polyp/cli.c
+++ b/polyp/cli.c
@@ -42,6 +42,7 @@
#include "cli-text.h"
#include "cli-command.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_cli {
struct pa_core *core;
@@ -103,7 +104,7 @@ static void client_kill(struct pa_client *client) {
assert(client && client->userdata);
c = client->userdata;
- fprintf(stderr, "CLI client killed.\n");
+ pa_log(__FILE__": CLI client killed.\n");
if (c->defer_kill)
c->kill_requested = 1;
else {
@@ -119,7 +120,7 @@ static void line_callback(struct pa_ioline *line, const char *s, void *userdata)
assert(line && c);
if (!s) {
- fprintf(stderr, "CLI got EOF from user.\n");
+ pa_log(__FILE__": CLI got EOF from user.\n");
if (c->eof_callback)
c->eof_callback(c, c->userdata);
diff --git a/polyp/client.c b/polyp/client.c
index c7fb1e07..a544b4fe 100644
--- a/polyp/client.c
+++ b/polyp/client.c
@@ -31,6 +31,7 @@
#include "client.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
struct pa_client *pa_client_new(struct pa_core *core, const char *protocol_name, char *name) {
struct pa_client *c;
@@ -49,7 +50,7 @@ struct pa_client *pa_client_new(struct pa_core *core, const char *protocol_name,
r = pa_idxset_put(core->clients, c, &c->index);
assert(c->index != PA_IDXSET_INVALID && r >= 0);
- fprintf(stderr, "client: created %u \"%s\"\n", c->index, c->name);
+ pa_log(__FILE__": created %u \"%s\"\n", c->index, c->name);
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
pa_core_check_quit(core);
@@ -64,7 +65,7 @@ void pa_client_free(struct pa_client *c) {
pa_core_check_quit(c->core);
- fprintf(stderr, "client: freed %u \"%s\"\n", c->index, c->name);
+ pa_log(__FILE__": freed %u \"%s\"\n", c->index, c->name);
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
pa_xfree(c->name);
pa_xfree(c);
@@ -74,7 +75,7 @@ void pa_client_free(struct pa_client *c) {
void pa_client_kill(struct pa_client *c) {
assert(c);
if (!c->kill) {
- fprintf(stderr, "kill() operation not implemented for client %u\n", c->index);
+ pa_log(__FILE__": kill() operation not implemented for client %u\n", c->index);
return;
}
diff --git a/polyp/cmdline.c b/polyp/cmdline.c
index aba20af1..1d650185 100644
--- a/polyp/cmdline.c
+++ b/polyp/cmdline.c
@@ -77,6 +77,7 @@ void pa_cmdline_help(const char *argv0) {
" -v Verbose startup\n"
" -X SECS Terminate the daemon after the last client quit and this time passed\n"
" -h Show this help\n"
+ " -l TARGET Specify the log target (syslog, stderr, auto)\n"
" -V Show version\n", e, cfg);
pa_xfree(cfg);
@@ -97,13 +98,14 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
cmdline->stay_root =
cmdline->version =
cmdline->disallow_module_loading = 0;
- cmdline->fail = 1;
+ cmdline->fail = cmdline->auto_log_target = 1;
cmdline->quit_after_last_client_time = -1;
+ cmdline->log_target = -1;
buf = pa_strbuf_new();
assert(buf);
- while ((c = getopt(argc, argv, "L:F:CDhfvrRVndX:")) != -1) {
+ while ((c = getopt(argc, argv, "L:F:CDhfvrRVndX:l:")) != -1) {
switch (c) {
case 'L':
pa_strbuf_printf(buf, "load %s\n", optarg);
@@ -144,6 +146,20 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
case 'X':
cmdline->quit_after_last_client_time = atoi(optarg);
break;
+ case 'l':
+ if (!strcmp(optarg, "syslog")) {
+ cmdline->auto_log_target = 0;
+ cmdline->log_target = PA_LOG_SYSLOG;
+ } else if (!strcmp(optarg, "stderr")) {
+ cmdline->auto_log_target = 0;
+ cmdline->log_target = PA_LOG_STDERR;
+ } else if (!strcmp(optarg, "auto"))
+ cmdline->auto_log_target = 1;
+ else {
+ pa_log(__FILE__": Invalid log target: use either 'syslog', 'stderr' or 'auto'.\n");
+ goto fail;
+ }
+ break;
default:
goto fail;
}
diff --git a/polyp/cmdline.h b/polyp/cmdline.h
index d1c438d1..d49b65fb 100644
--- a/polyp/cmdline.h
+++ b/polyp/cmdline.h
@@ -22,10 +22,21 @@
USA.
***/
+#include "log.h"
struct pa_cmdline {
- int daemonize, help, fail, verbose, high_priority, stay_root, version, disallow_module_loading, quit_after_last_client_time;
+ int daemonize,
+ help,
+ fail,
+ verbose,
+ high_priority,
+ stay_root,
+ version,
+ disallow_module_loading,
+ quit_after_last_client_time,
+ auto_log_target;
char *cli_commands;
+ enum pa_log_target log_target;
};
struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []);
diff --git a/polyp/core.h b/polyp/core.h
index 513d8172..ca37507c 100644
--- a/polyp/core.h
+++ b/polyp/core.h
@@ -51,7 +51,6 @@ struct pa_core {
int quit_after_last_client_time;
struct pa_time_event *quit_event;
-
};
struct pa_core* pa_core_new(struct pa_mainloop_api *m);
diff --git a/polyp/cpulimit.c b/polyp/cpulimit.c
index 7d6fa861..fc49f5bb 100644
--- a/polyp/cpulimit.c
+++ b/polyp/cpulimit.c
@@ -30,6 +30,7 @@
#include "cpulimit.h"
#include "util.h"
+#include "log.h"
/* Utilize this much CPU time at maximum */
#define CPUTIME_PERCENT 70
@@ -126,7 +127,7 @@ int pa_cpu_limit_init(struct pa_mainloop_api *m) {
time(&last_time);
if (pipe(the_pipe) < 0) {
- fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": pipe() failed: %s\n", strerror(errno));
return -1;
}
diff --git a/polyp/gcc-printf.h b/polyp/gcc-printf.h
new file mode 100644
index 00000000..224552af
--- /dev/null
+++ b/polyp/gcc-printf.h
@@ -0,0 +1,10 @@
+#ifndef foogccprintfhfoo
+#define foogccprintfhfoo
+
+#ifdef __GNUC__
+#define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
+#else
+#define PA_GCC_PRINTF_ATTR(a,b)
+#endif
+
+#endif
diff --git a/polyp/log.c b/polyp/log.c
new file mode 100644
index 00000000..413266df
--- /dev/null
+++ b/polyp/log.c
@@ -0,0 +1,48 @@
+#include <assert.h>
+#include <stdarg.h>
+#include <syslog.h>
+#include <stdio.h>
+
+#include "log.h"
+#include "xmalloc.h"
+#include "util.h"
+
+static char *log_ident = NULL;
+static enum pa_log_target log_target = PA_LOG_STDERR;
+static void (*user_log_func)(const char *s) = NULL;
+
+void pa_log_set_ident(const char *p) {
+ if (log_ident)
+ pa_xfree(log_ident);
+
+ log_ident = pa_xstrdup(p);
+}
+
+void pa_log_set_target(enum pa_log_target t, void (*func)(const char*s)) {
+ assert(t == PA_LOG_USER || !func);
+ log_target = t;
+ user_log_func = func;
+}
+
+void pa_log(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+
+ switch (log_target) {
+ case PA_LOG_STDERR:
+ vfprintf(stderr, format, ap);
+ break;
+ case PA_LOG_SYSLOG:
+ openlog(log_ident ? log_ident : "???", LOG_PID, LOG_USER);
+ vsyslog(LOG_INFO, format, ap);
+ closelog();
+ break;
+ case PA_LOG_USER: {
+ char *t = pa_vsprintf_malloc(format, ap);
+ assert(user_log_func);
+ user_log_func(t);
+ }
+ }
+
+ va_end(ap);
+}
diff --git a/polyp/log.h b/polyp/log.h
new file mode 100644
index 00000000..1f2c74ef
--- /dev/null
+++ b/polyp/log.h
@@ -0,0 +1,17 @@
+#ifndef foologhfoo
+#define foologhfoo
+
+#include "gcc-printf.h"
+
+enum pa_log_target {
+ PA_LOG_SYSLOG,
+ PA_LOG_STDERR,
+ PA_LOG_USER,
+};
+
+void pa_log_set_ident(const char *p);
+void pa_log_set_target(enum pa_log_target t, void (*func)(const char*s));
+
+void pa_log(const char *format, ...) PA_GCC_PRINTF_ATTR(1,2);
+
+#endif
diff --git a/polyp/main.c b/polyp/main.c
index 0f88a76e..29a7b548 100644
--- a/polyp/main.c
+++ b/polyp/main.c
@@ -44,12 +44,13 @@
#include "sioman.h"
#include "xmalloc.h"
#include "cpulimit.h"
+#include "log.h"
static struct pa_mainloop *mainloop;
static void drop_root(void) {
if (getuid() != 0 && geteuid() == 0) {
- fprintf(stderr, __FILE__": started SUID root, dropping root rights.\n");
+ pa_log(__FILE__": Started SUID root, dropping root rights.\n");
setuid(getuid());
seteuid(getuid());
}
@@ -68,7 +69,7 @@ static const char* signal_name(int s) {
}
static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
- fprintf(stderr, __FILE__": got signal %s.\n", signal_name(sig));
+ pa_log(__FILE__": Got signal %s.\n", signal_name(sig));
switch (sig) {
case SIGUSR1:
@@ -82,7 +83,7 @@ static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e,
case SIGINT:
case SIGTERM:
default:
- fprintf(stderr, "Exiting.\n");
+ pa_log(__FILE__": Exiting.\n");
m->quit(m, 1);
return;
}
@@ -104,11 +105,15 @@ int main(int argc, char *argv[]) {
int r, retval = 1;
int daemon_pipe[2] = { -1, -1 };
+ pa_log_set_ident("polypaudio");
+
if (!(cmdline = pa_cmdline_parse(argc, argv))) {
- fprintf(stderr, __FILE__": failed to parse command line.\n");
+ pa_log(__FILE__": failed to parse command line.\n");
goto finish;
}
+ pa_log_set_target(cmdline->auto_log_target ? PA_LOG_STDERR : cmdline->log_target, NULL);
+
if (cmdline->help) {
pa_cmdline_help(argv[0]);
retval = 0;
@@ -131,17 +136,17 @@ int main(int argc, char *argv[]) {
pid_t child;
if (pa_stdio_acquire() < 0) {
- fprintf(stderr, __FILE__": failed to acquire stdio.\n");
+ pa_log(__FILE__": failed to acquire stdio.\n");
goto finish;
}
if (pipe(daemon_pipe) < 0) {
- fprintf(stderr, __FILE__": failed to create pipe.\n");
+ pa_log(__FILE__": failed to create pipe.\n");
goto finish;
}
if ((child = fork()) < 0) {
- fprintf(stderr, __FILE__": fork() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": fork() failed: %s\n", strerror(errno));
goto finish;
}
@@ -152,7 +157,7 @@ int main(int argc, char *argv[]) {
daemon_pipe[1] = -1;
if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval)) != sizeof(retval)) {
- fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", strerror(errno));
retval = 1;
}
@@ -162,6 +167,10 @@ int main(int argc, char *argv[]) {
close(daemon_pipe[0]);
daemon_pipe[0] = -1;
+
+ if (cmdline->auto_log_target)
+ pa_log_set_target(PA_LOG_SYSLOG, NULL);
+
setsid();
setpgrp();
@@ -196,15 +205,15 @@ int main(int argc, char *argv[]) {
buf = pa_strbuf_new();
assert(buf);
r = pa_cli_command_execute(c, cmdline->cli_commands, buf, &cmdline->fail, &cmdline->verbose);
- fprintf(stderr, s = pa_strbuf_tostring_free(buf));
+ pa_log(s = pa_strbuf_tostring_free(buf));
pa_xfree(s);
if (r < 0 && cmdline->fail) {
- fprintf(stderr, __FILE__": failed to initialize daemon.\n");
+ pa_log(__FILE__": failed to initialize daemon.\n");
if (cmdline->daemonize)
pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
} else if (!c->modules || pa_idxset_ncontents(c->modules) == 0) {
- fprintf(stderr, __FILE__": daemon startup without any loaded modules, refusing to work.\n");
+ pa_log(__FILE__": daemon startup without any loaded modules, refusing to work.\n");
if (cmdline->daemonize)
pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
} else {
@@ -215,10 +224,10 @@ int main(int argc, char *argv[]) {
c->disallow_module_loading = cmdline->disallow_module_loading;
c->quit_after_last_client_time = cmdline->quit_after_last_client_time;
- fprintf(stderr, __FILE__": mainloop entry.\n");
+ pa_log(__FILE__": Daemon startup complete.\n");
if (pa_mainloop_run(mainloop, &retval) < 0)
retval = 1;
- fprintf(stderr, __FILE__": mainloop exit.\n");
+ pa_log(__FILE__": Daemon shutdown initiated.\n");
}
pa_core_free(c);
@@ -229,12 +238,14 @@ int main(int argc, char *argv[]) {
lt_dlexit();
+ pa_log(__FILE__": Daemon terminated.\n");
+
finish:
if (cmdline)
pa_cmdline_free(cmdline);
close_pipe(daemon_pipe);
-
+
return retval;
}
diff --git a/polyp/mainloop-signal.c b/polyp/mainloop-signal.c
index 4746837b..d7ee5010 100644
--- a/polyp/mainloop-signal.c
+++ b/polyp/mainloop-signal.c
@@ -34,6 +34,7 @@
#include "mainloop-signal.h"
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_signal_event {
int sig;
@@ -64,12 +65,12 @@ static void callback(struct pa_mainloop_api*a, struct pa_io_event*e, int fd, enu
if (errno == EAGAIN)
return;
- fprintf(stderr, "signal.c: read(): %s\n", strerror(errno));
+ pa_log(__FILE__": read(): %s\n", strerror(errno));
return;
}
if (r != sizeof(sig)) {
- fprintf(stderr, "signal.c: short read()\n");
+ pa_log(__FILE__": short read()\n");
return;
}
@@ -85,7 +86,7 @@ int pa_signal_init(struct pa_mainloop_api *a) {
assert(!api && a && signal_pipe[0] == -1 && signal_pipe[1] == -1 && !io_event);
if (pipe(signal_pipe) < 0) {
- fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": pipe() failed: %s\n", strerror(errno));
return -1;
}
diff --git a/polyp/mainloop.c b/polyp/mainloop.c
index 83f0b1e8..22cd85c8 100644
--- a/polyp/mainloop.c
+++ b/polyp/mainloop.c
@@ -37,6 +37,7 @@
#include "util.h"
#include "idxset.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_io_event {
struct pa_mainloop *mainloop;
@@ -502,7 +503,7 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) {
do {
int t = block ? calc_next_timeout(m) : 0;
- /*fprintf(stderr, "%u\n", t);*/
+ /*pa_log(__FILE__": %u\n", t);*/
r = poll(m->pollfds, m->n_pollfds, t);
} while (r < 0 && errno == EINTR);
@@ -511,7 +512,7 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) {
if (r > 0)
dispatch_pollfds(m);
else if (r < 0)
- fprintf(stderr, "select(): %s\n", strerror(errno));
+ pa_log(__FILE__": select(): %s\n", strerror(errno));
m->running = 0;
return r < 0 ? -1 : 0;
diff --git a/polyp/memblockq.c b/polyp/memblockq.c
index 7feb4685..0bba6581 100644
--- a/polyp/memblockq.c
+++ b/polyp/memblockq.c
@@ -32,6 +32,7 @@
#include "memblockq.h"
#include "xmalloc.h"
+#include "log.h"
struct memblock_list {
struct memblock_list *next, *prev;
@@ -56,7 +57,7 @@ struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t tlength, size_t b
bq->current_length = 0;
- /*fprintf(stderr, "memblockq requested: maxlength=%u, tlength=%u, base=%u, prebuf=%u, minreq=%u\n", maxlength, tlength, base, prebuf, minreq);*/
+ /*pa_log(__FILE__": memblockq requested: maxlength=%u, tlength=%u, base=%u, prebuf=%u, minreq=%u\n", maxlength, tlength, base, prebuf, minreq);*/
bq->base = base;
@@ -76,7 +77,7 @@ struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t tlength, size_t b
if (bq->minreq == 0)
bq->minreq = 1;
- fprintf(stderr, "memblockq sanitized: maxlength=%u, tlength=%u, base=%u, prebuf=%u, minreq=%u\n", bq->maxlength, bq->tlength, bq->base, bq->prebuf, bq->minreq);
+ pa_log(__FILE__": memblockq sanitized: maxlength=%u, tlength=%u, base=%u, prebuf=%u, minreq=%u\n", bq->maxlength, bq->tlength, bq->base, bq->prebuf, bq->minreq);
bq->mcalign = NULL;
@@ -206,7 +207,7 @@ void pa_memblockq_shorten(struct pa_memblockq *bq, size_t length) {
if (bq->current_length <= length)
return;
- fprintf(stderr, "Warning! pa_memblockq_shorten()\n");
+ pa_log(__FILE__": Warning! pa_memblockq_shorten()\n");
l = bq->current_length - length;
l /= bq->base;
diff --git a/polyp/module-alsa-sink.c b/polyp/module-alsa-sink.c
index 0c9d77b8..9c75ff98 100644
--- a/polyp/module-alsa-sink.c
+++ b/polyp/module-alsa-sink.c
@@ -38,6 +38,7 @@
#include "sample-util.h"
#include "alsa-util.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
snd_pcm_t *pcm_handle;
@@ -73,10 +74,10 @@ static void update_usage(struct userdata *u) {
static void xrun_recovery(struct userdata *u) {
assert(u);
- fprintf(stderr, "*** ALSA-XRUN (playback) ***\n");
+ pa_log(__FILE__": *** ALSA-XRUN (playback) ***\n");
if (snd_pcm_prepare(u->pcm_handle) < 0)
- fprintf(stderr, "snd_pcm_prepare() failed\n");
+ pa_log(__FILE__": snd_pcm_prepare() failed\n");
}
static void do_write(struct userdata *u) {
@@ -108,7 +109,7 @@ static void do_write(struct userdata *u) {
continue;
}
- fprintf(stderr, "snd_pcm_writei() failed\n");
+ pa_log(__FILE__": snd_pcm_writei() failed\n");
return;
}
@@ -144,7 +145,7 @@ static uint32_t sink_get_latency_cb(struct pa_sink *s) {
assert(s && u && u->sink);
if (snd_pcm_delay(u->pcm_handle, &frames) < 0) {
- fprintf(stderr, __FILE__": failed to get delay\n");
+ pa_log(__FILE__": failed to get delay\n");
s->get_latency = NULL;
return 0;
}
@@ -166,13 +167,13 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
size_t frame_size;
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments\n");
+ pa_log(__FILE__": failed to parse module arguments\n");
goto fail;
}
ss = c->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
- fprintf(stderr, __FILE__": failed to parse sample specification\n");
+ pa_log(__FILE__": failed to parse sample specification\n");
goto fail;
}
frame_size = pa_frame_size(&ss);
@@ -180,7 +181,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
periods = 12;
fragsize = 1024;
if (pa_modargs_get_value_u32(ma, "fragments", &periods) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &fragsize) < 0) {
- fprintf(stderr, __FILE__": failed to parse buffer metrics\n");
+ pa_log(__FILE__": failed to parse buffer metrics\n");
goto fail;
}
buffer_size = fragsize/frame_size*periods;
@@ -190,12 +191,12 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->module = m;
if (snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) {
- fprintf(stderr, __FILE__": Error opening PCM device %s\n", dev);
+ pa_log(__FILE__": Error opening PCM device %s\n", dev);
goto fail;
}
if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &buffer_size) < 0) {
- fprintf(stderr, __FILE__": Failed to set hardware parameters\n");
+ pa_log(__FILE__": Failed to set hardware parameters\n");
goto fail;
}
@@ -208,14 +209,14 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->sink->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
if (pa_create_io_events(u->pcm_handle, c->mainloop, &u->io_events, &u->n_io_events, io_callback, u) < 0) {
- fprintf(stderr, __FILE__": failed to obtain file descriptors\n");
+ pa_log(__FILE__": failed to obtain file descriptors\n");
goto fail;
}
u->frame_size = frame_size;
u->fragment_size = buffer_size*u->frame_size/periods;
- fprintf(stderr, __FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
+ pa_log(__FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
u->silence.memblock = pa_memblock_new(u->silence.length = u->fragment_size, c->memblock_stat);
assert(u->silence.memblock);
diff --git a/polyp/module-alsa-source.c b/polyp/module-alsa-source.c
index 13df9f96..520b6830 100644
--- a/polyp/module-alsa-source.c
+++ b/polyp/module-alsa-source.c
@@ -38,6 +38,7 @@
#include "sample-util.h"
#include "alsa-util.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
snd_pcm_t *pcm_handle;
@@ -72,10 +73,10 @@ static void update_usage(struct userdata *u) {
static void xrun_recovery(struct userdata *u) {
assert(u);
- fprintf(stderr, "*** ALSA-XRUN (capture) ***\n");
+ pa_log(__FILE__": *** ALSA-XRUN (capture) ***\n");
if (snd_pcm_prepare(u->pcm_handle) < 0)
- fprintf(stderr, "snd_pcm_prepare() failed\n");
+ pa_log(__FILE__": snd_pcm_prepare() failed\n");
}
static void do_read(struct userdata *u) {
@@ -104,7 +105,7 @@ static void do_read(struct userdata *u) {
continue;
}
- fprintf(stderr, "snd_pcm_readi() failed: %s\n", strerror(-frames));
+ pa_log(__FILE__": snd_pcm_readi() failed: %s\n", strerror(-frames));
return;
}
@@ -149,13 +150,13 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
size_t frame_size;
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments\n");
+ pa_log(__FILE__": failed to parse module arguments\n");
goto fail;
}
ss = c->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
- fprintf(stderr, __FILE__": failed to parse sample specification\n");
+ pa_log(__FILE__": failed to parse sample specification\n");
goto fail;
}
frame_size = pa_frame_size(&ss);
@@ -163,7 +164,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
periods = 12;
fragsize = 1024;
if (pa_modargs_get_value_u32(ma, "fragments", &periods) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &fragsize) < 0) {
- fprintf(stderr, __FILE__": failed to parse buffer metrics\n");
+ pa_log(__FILE__": failed to parse buffer metrics\n");
goto fail;
}
buffer_size = fragsize/frame_size*periods;
@@ -173,12 +174,12 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->module = m;
if (snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK) < 0) {
- fprintf(stderr, __FILE__": Error opening PCM device %s\n", dev);
+ pa_log(__FILE__": Error opening PCM device %s\n", dev);
goto fail;
}
if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &buffer_size) < 0) {
- fprintf(stderr, __FILE__": Failed to set hardware parameters\n");
+ pa_log(__FILE__": Failed to set hardware parameters\n");
goto fail;
}
@@ -190,14 +191,14 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->source->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
if (pa_create_io_events(u->pcm_handle, c->mainloop, &u->io_events, &u->n_io_events, io_callback, u) < 0) {
- fprintf(stderr, __FILE__": failed to obtain file descriptors\n");
+ pa_log(__FILE__": failed to obtain file descriptors\n");
goto fail;
}
u->frame_size = frame_size;
u->fragment_size = buffer_size*u->frame_size/periods;
- fprintf(stderr, __FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
+ pa_log(__FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
u->memchunk.memblock = NULL;
u->memchunk.index = u->memchunk.length = 0;
diff --git a/polyp/module-cli.c b/polyp/module-cli.c
index 8897c9c6..9a08a00d 100644
--- a/polyp/module-cli.c
+++ b/polyp/module-cli.c
@@ -31,6 +31,7 @@
#include "iochannel.h"
#include "cli.h"
#include "sioman.h"
+#include "log.h"
static void eof_cb(struct pa_cli*c, void *userdata) {
struct pa_module *m = userdata;
@@ -44,12 +45,12 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
assert(c && m);
if (m->argument) {
- fprintf(stderr, __FILE__": module doesn't accept arguments.\n");
+ pa_log(__FILE__": module doesn't accept arguments.\n");
return -1;
}
if (pa_stdio_acquire() < 0) {
- fprintf(stderr, __FILE__": STDIN/STDUSE already in use.\n");
+ pa_log(__FILE__": STDIN/STDUSE already in use.\n");
return -1;
}
diff --git a/polyp/module-native-protocol-fd.c b/polyp/module-native-protocol-fd.c
index 213e291e..632a3d71 100644
--- a/polyp/module-native-protocol-fd.c
+++ b/polyp/module-native-protocol-fd.c
@@ -31,6 +31,7 @@
#include "iochannel.h"
#include "modargs.h"
#include "protocol-native.h"
+#include "log.h"
static const char* const valid_modargs[] = {
"fd",
@@ -46,12 +47,12 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
assert(c && m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments.\n");
+ pa_log(__FILE__": failed to parse module arguments.\n");
goto finish;
}
if (pa_modargs_get_value_s32(ma, "fd", &fd) < 0) {
- fprintf(stderr, __FILE__": invalid file descriptor.\n");
+ pa_log(__FILE__": invalid file descriptor.\n");
goto finish;
}
diff --git a/polyp/module-oss-mmap.c b/polyp/module-oss-mmap.c
index 8a0dd9a4..8151a13a 100644
--- a/polyp/module-oss-mmap.c
+++ b/polyp/module-oss-mmap.c
@@ -45,6 +45,7 @@
#include "util.h"
#include "modargs.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
struct pa_sink *sink;
@@ -122,7 +123,7 @@ static void do_write(struct userdata *u) {
update_usage(u);
if (ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
- fprintf(stderr, "SNDCTL_DSP_GETOPTR: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETOPTR: %s\n", strerror(errno));
return;
}
@@ -184,7 +185,7 @@ static void do_read(struct userdata *u) {
update_usage(u);
if (ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
- fprintf(stderr, "SNDCTL_DSP_GETIPTR: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETIPTR: %s\n", strerror(errno));
return;
}
@@ -230,17 +231,17 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->core = c;
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments.\n");
+ pa_log(__FILE__": failed to parse module arguments.\n");
goto fail;
}
if (pa_modargs_get_value_boolean(ma, "record", &record) < 0 || pa_modargs_get_value_boolean(ma, "playback", &playback) < 0) {
- fprintf(stderr, __FILE__": record= and playback= expect numeric arguments.\n");
+ pa_log(__FILE__": record= and playback= expect numeric arguments.\n");
goto fail;
}
if (!playback && !record) {
- fprintf(stderr, __FILE__": neither playback nor record enabled for device.\n");
+ pa_log(__FILE__": neither playback nor record enabled for device.\n");
goto fail;
}
@@ -249,13 +250,13 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
nfrags = 12;
frag_size = 1024;
if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || nfrags < 2 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0 || frag_size < 1) {
- fprintf(stderr, __FILE__": failed to parse fragments arguments\n");
+ pa_log(__FILE__": failed to parse fragments arguments\n");
goto fail;
}
u->sample_spec = c->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &u->sample_spec) < 0) {
- fprintf(stderr, __FILE__": failed to parse sample specification\n");
+ pa_log(__FILE__": failed to parse sample specification\n");
goto fail;
}
@@ -263,11 +264,11 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
goto fail;
if (!(caps & DSP_CAP_MMAP) || !(caps & DSP_CAP_REALTIME) || !(caps & DSP_CAP_TRIGGER)) {
- fprintf(stderr, "OSS device not mmap capable.\n");
+ pa_log(__FILE__": OSS device not mmap capable.\n");
goto fail;
}
- fprintf(stderr, "module-oss: device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
+ pa_log(__FILE__": device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
if (pa_oss_set_fragments(u->fd, nfrags, frag_size) < 0)
goto fail;
@@ -277,19 +278,19 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
if (mode != O_WRONLY) {
if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
- fprintf(stderr, "SNDCTL_DSP_GETISPACE: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETISPACE: %s\n", strerror(errno));
goto fail;
}
- fprintf(stderr, "module-oss-mmap: input -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
+ pa_log(__FILE__": input -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
u->in_mmap_length = (u->in_fragment_size = info.fragsize) * (u->in_fragments = info.fragstotal);
if ((u->in_mmap = mmap(NULL, u->in_mmap_length, PROT_READ, MAP_SHARED, u->fd, 0)) == MAP_FAILED) {
if (mode == O_RDWR) {
- fprintf(stderr, "module-oss-mmap: mmap failed for input. Changing to O_WRONLY mode.\n");
+ pa_log(__FILE__": mmap failed for input. Changing to O_WRONLY mode.\n");
mode = O_WRONLY;
} else {
- fprintf(stderr, "modeule-oss-mmap: mmap(): %s\n", strerror(errno));
+ pa_log(__FILE__": mmap(): %s\n", strerror(errno));
goto fail;
}
} else {
@@ -308,19 +309,19 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
if (mode != O_RDONLY) {
if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
- fprintf(stderr, "SNDCTL_DSP_GETOSPACE: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETOSPACE: %s\n", strerror(errno));
goto fail;
}
- fprintf(stderr, "module-oss: output -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
+ pa_log(__FILE__": output -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
u->out_mmap_length = (u->out_fragment_size = info.fragsize) * (u->out_fragments = info.fragstotal);
if ((u->out_mmap = mmap(NULL, u->out_mmap_length, PROT_WRITE, MAP_SHARED, u->fd, 0)) == MAP_FAILED) {
if (mode == O_RDWR) {
- fprintf(stderr, "module-oss-mmap: mmap filed for output. Changing to O_RDONLY mode.\n");
+ pa_log(__FILE__": mmap filed for output. Changing to O_RDONLY mode.\n");
mode = O_RDONLY;
} else {
- fprintf(stderr, "module-oss-mmap: mmap(): %s\n", strerror(errno));
+ pa_log(__FILE__": mmap(): %s\n", strerror(errno));
goto fail;
}
} else {
@@ -341,12 +342,12 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
zero = 0;
if (ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &zero) < 0) {
- fprintf(stderr, "SNDCTL_DSP_SETTRIGGER: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_SETTRIGGER: %s\n", strerror(errno));
goto fail;
}
if (ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) < 0) {
- fprintf(stderr, "SNDCTL_DSP_SETTRIGGER: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_SETTRIGGER: %s\n", strerror(errno));
goto fail;
}
diff --git a/polyp/module-oss.c b/polyp/module-oss.c
index 4fd79624..53f1f994 100644
--- a/polyp/module-oss.c
+++ b/polyp/module-oss.c
@@ -44,6 +44,7 @@
#include "util.h"
#include "modargs.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
struct pa_sink *sink;
@@ -105,7 +106,7 @@ static void do_write(struct userdata *u) {
assert(memchunk->length);
if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
- fprintf(stderr, "write() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": write() failed: %s\n", strerror(errno));
return;
}
@@ -137,7 +138,7 @@ static void do_read(struct userdata *u) {
if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
pa_memblock_unref(memchunk.memblock);
if (errno != EAGAIN)
- fprintf(stderr, "read() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", strerror(errno));
return;
}
@@ -162,7 +163,7 @@ static uint32_t sink_get_latency_cb(struct pa_sink *s) {
assert(s && u && u->sink);
if (ioctl(u->fd, SNDCTL_DSP_GETODELAY, &arg) < 0) {
- fprintf(stderr, "module-oss: device doesn't support SNDCTL_DSP_GETODELAY.\n");
+ pa_log(__FILE__": device doesn't support SNDCTL_DSP_GETODELAY.\n");
s->get_latency = NULL;
return 0;
}
@@ -183,17 +184,17 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
assert(c && m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments.\n");
+ pa_log(__FILE__": failed to parse module arguments.\n");
goto fail;
}
if (pa_modargs_get_value_boolean(ma, "record", &record) < 0 || pa_modargs_get_value_boolean(ma, "playback", &playback) < 0) {
- fprintf(stderr, __FILE__": record= and playback= expect numeric argument.\n");
+ pa_log(__FILE__": record= and playback= expect numeric argument.\n");
goto fail;
}
if (!playback && !record) {
- fprintf(stderr, __FILE__": neither playback nor record enabled for device.\n");
+ pa_log(__FILE__": neither playback nor record enabled for device.\n");
goto fail;
}
@@ -202,20 +203,20 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
nfrags = 12;
frag_size = 1024;
if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || nfrags < 2 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0 || frag_size < 1) {
- fprintf(stderr, __FILE__": failed to parse fragments arguments\n");
+ pa_log(__FILE__": failed to parse fragments arguments\n");
goto fail;
}
ss = c->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
- fprintf(stderr, __FILE__": failed to parse sample specification\n");
+ pa_log(__FILE__": failed to parse sample specification\n");
goto fail;
}
if ((fd = pa_oss_open(p = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, NULL)) < 0)
goto fail;
- fprintf(stderr, "module-oss: device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
+ pa_log(__FILE__": device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
if (pa_oss_set_fragments(fd, nfrags, frag_size) < 0)
goto fail;
@@ -224,19 +225,19 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
goto fail;
if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
- fprintf(stderr, "SNDCTL_DSP_GETBLKSIZE: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETBLKSIZE: %s\n", strerror(errno));
goto fail;
}
assert(frag_size);
in_frag_size = out_frag_size = frag_size;
if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
- fprintf(stderr, "module-oss: input -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
+ pa_log(__FILE__": input -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
in_frag_size = info.fragsize;
}
if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
- fprintf(stderr, "module-oss: output -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
+ pa_log(__FILE__": output -- %u fragments of size %u.\n", info.fragstotal, info.fragsize);
out_frag_size = info.fragsize;
}
diff --git a/polyp/module-pipe-sink.c b/polyp/module-pipe-sink.c
index 088ed405..5f1ced03 100644
--- a/polyp/module-pipe-sink.c
+++ b/polyp/module-pipe-sink.c
@@ -39,6 +39,7 @@
#include "util.h"
#include "modargs.h"
#include "xmalloc.h"
+#include "log.h"
#define DEFAULT_FIFO_NAME "/tmp/musicfifo"
#define DEFAULT_SINK_NAME "fifo_output"
@@ -83,7 +84,7 @@ static void do_write(struct userdata *u) {
assert(u->memchunk.memblock && u->memchunk.length);
if ((r = pa_iochannel_write(u->io, (uint8_t*) u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length)) < 0) {
- fprintf(stderr, "write() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": write() failed: %s\n", strerror(errno));
return;
}
@@ -126,32 +127,32 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
assert(c && m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments\n");
+ pa_log(__FILE__": failed to parse module arguments\n");
goto fail;
}
ss = c->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
- fprintf(stderr, __FILE__": invalid sample format specification\n");
+ pa_log(__FILE__": invalid sample format specification\n");
goto fail;
}
mkfifo(p = pa_modargs_get_value(ma, "file", DEFAULT_FIFO_NAME), 0777);
if ((fd = open(p, O_RDWR)) < 0) {
- fprintf(stderr, __FILE__": open('%s'): %s\n", p, strerror(errno));
+ pa_log(__FILE__": open('%s'): %s\n", p, strerror(errno));
goto fail;
}
pa_fd_set_cloexec(fd, 1);
if (fstat(fd, &st) < 0) {
- fprintf(stderr, __FILE__": fstat('%s'): %s\n", p, strerror(errno));
+ pa_log(__FILE__": fstat('%s'): %s\n", p, strerror(errno));
goto fail;
}
if (!S_ISFIFO(st.st_mode)) {
- fprintf(stderr, __FILE__": '%s' is not a FIFO.\n", p);
+ pa_log(__FILE__": '%s' is not a FIFO.\n", p);
goto fail;
}
@@ -161,7 +162,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->core = c;
if (!(u->sink = pa_sink_new(c, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss))) {
- fprintf(stderr, __FILE__": failed to create sink.\n");
+ pa_log(__FILE__": failed to create sink.\n");
goto fail;
}
u->sink->notify = notify_cb;
diff --git a/polyp/module-protocol-stub.c b/polyp/module-protocol-stub.c
index 4d86c28e..686e2129 100644
--- a/polyp/module-protocol-stub.c
+++ b/polyp/module-protocol-stub.c
@@ -35,6 +35,7 @@
#include "socket-util.h"
#include "util.h"
#include "modargs.h"
+#include "log.h"
#if defined(USE_PROTOCOL_SIMPLE)
#include "protocol-simple.h"
@@ -87,12 +88,12 @@ static struct pa_socket_server *create_socket_server(struct pa_core *c, struct p
uint32_t port = IPV4_PORT;
if (pa_modargs_get_value_boolean(ma, "loopback", &loopback) < 0) {
- fprintf(stderr, "loopback= expects a numerical argument.\n");
+ pa_log(__FILE__": loopback= expects a numerical argument.\n");
return NULL;
}
if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
- fprintf(stderr, "port= expects a numerical argument between 1 and 65535.\n");
+ pa_log(__FILE__": port= expects a numerical argument between 1 and 65535.\n");
return NULL;
}
@@ -106,17 +107,17 @@ static struct pa_socket_server *create_socket_server(struct pa_core *c, struct p
assert(p);
if (pa_unix_socket_make_secure_dir(p) < 0) {
- fprintf(stderr, "Failed to create secure socket directory.\n");
+ pa_log(__FILE__": Failed to create secure socket directory.\n");
return NULL;
}
if ((r = pa_unix_socket_remove_stale(p)) < 0) {
- fprintf(stderr, "Failed to remove stale UNIX socket '%s': %s\n", p, strerror(errno));
+ pa_log(__FILE__": Failed to remove stale UNIX socket '%s': %s\n", p, strerror(errno));
return NULL;
}
if (r)
- fprintf(stderr, "Removed stale UNIX socket '%s'.", p);
+ pa_log(__FILE__": Removed stale UNIX socket '%s'.", p);
if (!(s = pa_socket_server_new_unix(c->mainloop, p)))
return NULL;
@@ -132,7 +133,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
assert(c && m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, "Failed to parse module arguments\n");
+ pa_log(__FILE__": Failed to parse module arguments\n");
goto finish;
}
diff --git a/polyp/module-sine.c b/polyp/module-sine.c
index 364cc64c..868f63c6 100644
--- a/polyp/module-sine.c
+++ b/polyp/module-sine.c
@@ -32,6 +32,7 @@
#include "modargs.h"
#include "xmalloc.h"
#include "namereg.h"
+#include "log.h"
struct userdata {
struct pa_core *core;
@@ -98,7 +99,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
char t[256];
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": Failed to parse module arguments\n");
+ pa_log(__FILE__": Failed to parse module arguments\n");
goto fail;
}
@@ -110,7 +111,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
sink_name = pa_modargs_get_value(ma, "sink", NULL);
if (!(sink = pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
- fprintf(stderr, __FILE__": No such sink\n");
+ pa_log(__FILE__": No such sink.\n");
goto fail;
}
@@ -120,7 +121,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
frequency = 440;
if (pa_modargs_get_value_u32(ma, "frequency", &frequency) < 0 || frequency < 1 || frequency > ss.rate/2) {
- fprintf(stderr, __FILE__": Invalid frequency specification\n");
+ pa_log(__FILE__": Invalid frequency specification\n");
goto fail;
}
diff --git a/polyp/module-x11-bell.c b/polyp/module-x11-bell.c
index ae889b22..d8ec978b 100644
--- a/polyp/module-x11-bell.c
+++ b/polyp/module-x11-bell.c
@@ -37,6 +37,7 @@
#include "modargs.h"
#include "xmalloc.h"
#include "namereg.h"
+#include "log.h"
struct x11_source {
struct pa_io_event *io_event;
@@ -65,7 +66,7 @@ static int ring_bell(struct userdata *u, int percent) {
assert(u);
if (!(s = pa_namereg_get(u->core, u->sink_name, PA_NAMEREG_SINK, 1))) {
- fprintf(stderr, __FILE__": Invalid sink\n");
+ pa_log(__FILE__": Invalid sink\n");
return -1;
}
@@ -88,7 +89,7 @@ static void io_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd,
bne = ((XkbBellNotifyEvent*) &e);
if (ring_bell(u, bne->percent) < 0) {
- fprintf(stderr, __FILE__": Ringing bell failed, reverting to X11 device bell.\n");
+ pa_log(__FILE__": Ringing bell failed, reverting to X11 device bell.\n");
XkbForceDeviceBell(u->display, bne->device, bne->bell_class, bne->bell_id, bne->percent);
}
}
@@ -112,7 +113,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
assert(c && m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- fprintf(stderr, __FILE__": failed to parse module arguments\n");
+ pa_log(__FILE__": failed to parse module arguments\n");
goto fail;
}
@@ -124,7 +125,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
if (!(u->display = XOpenDisplay(pa_modargs_get_value(ma, "display", NULL)))) {
- fprintf(stderr, __FILE__": XOpenDisplay() failed\n");
+ pa_log(__FILE__": XOpenDisplay() failed\n");
goto fail;
}
@@ -134,7 +135,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
minor = XkbMinorVersion;
if (!XkbLibraryVersion(&major, &minor)) {
- fprintf(stderr, __FILE__": XkbLibraryVersion() failed\n");
+ pa_log(__FILE__": XkbLibraryVersion() failed\n");
goto fail;
}
@@ -142,7 +143,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
minor = XkbMinorVersion;
if (!XkbQueryExtension(u->display, NULL, &u->xkb_event_base, NULL, &major, &minor)) {
- fprintf(stderr, __FILE__": XkbQueryExtension() failed\n");
+ pa_log(__FILE__": XkbQueryExtension() failed\n");
goto fail;
}
diff --git a/polyp/module.c b/polyp/module.c
index a06b2754..6eec499b 100644
--- a/polyp/module.c
+++ b/polyp/module.c
@@ -33,6 +33,7 @@
#include "module.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
#define UNLOAD_POLL_TIME 10
@@ -56,6 +57,8 @@ struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char
if (c->disallow_module_loading)
goto fail;
+
+ pa_log(__FILE__": Trying to load \"%s\" with argument \"%s\".\n", name, argument);
m = pa_xmalloc(sizeof(struct pa_module));
@@ -95,13 +98,16 @@ struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char
r = pa_idxset_put(c->modules, m, &m->index);
assert(r >= 0 && m->index != PA_IDXSET_INVALID);
- fprintf(stderr, "module: loaded %u \"%s\" with argument \"%s\".\n", m->index, m->name, m->argument);
+ pa_log(__FILE__": Loaded \"%s\" (index: #%u) with argument \"%s\".\n", m->name, m->index, m->argument);
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_NEW, m->index);
return m;
fail:
+
+ pa_log(__FILE__": Failed to load \"%s\" with argument \"%s\".\n", name, argument);
+
if (m) {
pa_xfree(m->argument);
pa_xfree(m->name);
@@ -125,7 +131,7 @@ static void pa_module_free(struct pa_module *m) {
lt_dlclose(m->dl);
- fprintf(stderr, "module: unloaded %u \"%s\".\n", m->index, m->name);
+ pa_log(__FILE__": Unloaded \"%s\" (index: #%u).\n", m->name, m->index);
pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_REMOVE, m->index);
diff --git a/polyp/oss-util.c b/polyp/oss-util.c
index b28c3dc9..613cda47 100644
--- a/polyp/oss-util.c
+++ b/polyp/oss-util.c
@@ -36,6 +36,7 @@
#include "oss-util.h"
#include "util.h"
+#include "log.h"
int pa_oss_open(const char *device, int *mode, int* pcaps) {
int fd = -1;
@@ -49,7 +50,7 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) {
tcaps = pcaps ? pcaps : &dcaps;
if (ioctl(fd, SNDCTL_DSP_GETCAPS, tcaps) < 0) {
- fprintf(stderr, __FILE__": SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
goto fail;
}
@@ -61,20 +62,20 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) {
if ((fd = open(device, (*mode = O_WRONLY)|O_NDELAY)) < 0) {
if ((fd = open(device, (*mode = O_RDONLY)|O_NDELAY)) < 0) {
- fprintf(stderr, __FILE__": open('%s'): %s\n", device, strerror(errno));
+ pa_log(__FILE__": open('%s'): %s\n", device, strerror(errno));
goto fail;
}
}
} else {
if ((fd = open(device, *mode|O_NDELAY)) < 0) {
- fprintf(stderr, __FILE__": open('%s'): %s\n", device, strerror(errno));
+ pa_log(__FILE__": open('%s'): %s\n", device, strerror(errno));
goto fail;
}
}
if (pcaps) {
if (ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps) < 0) {
- fprintf(stderr, "SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
goto fail;
}
}
@@ -112,7 +113,7 @@ int pa_oss_auto_format(int fd, struct pa_sample_spec *ss) {
if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != f) {
format = AFMT_U8;
if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != AFMT_U8) {
- fprintf(stderr, "SNDCTL_DSP_SETFMT: %s\n", format != AFMT_U8 ? "No supported sample format" : strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_SETFMT: %s\n", format != AFMT_U8 ? "No supported sample format" : strerror(errno));
return -1;
} else
ss->format = PA_SAMPLE_U8;
@@ -124,7 +125,7 @@ int pa_oss_auto_format(int fd, struct pa_sample_spec *ss) {
channels = ss->channels;
if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
- fprintf(stderr, "SNDCTL_DSP_CHANNELS: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_CHANNELS: %s\n", strerror(errno));
return -1;
}
assert(channels);
@@ -132,7 +133,7 @@ int pa_oss_auto_format(int fd, struct pa_sample_spec *ss) {
speed = ss->rate;
if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) < 0) {
- fprintf(stderr, "SNDCTL_DSP_SPEED: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_SPEED: %s\n", strerror(errno));
return -1;
}
assert(speed);
@@ -158,7 +159,7 @@ int pa_oss_set_fragments(int fd, int nfrags, int frag_size) {
arg = ((int) nfrags << 16) | simple_log2(frag_size);
if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &arg) < 0) {
- fprintf(stderr, "SNDCTL_DSP_SETFRAGMENT: %s\n", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_SETFRAGMENT: %s\n", strerror(errno));
return -1;
}
diff --git a/polyp/pdispatch.c b/polyp/pdispatch.c
index 22f5da09..23bdf68b 100644
--- a/polyp/pdispatch.c
+++ b/polyp/pdispatch.c
@@ -31,6 +31,7 @@
#include "native-common.h"
#include "xmalloc.h"
#include "llist.h"
+#include "log.h"
/*#define DEBUG_OPCODES*/
@@ -173,7 +174,7 @@ int pa_pdispatch_run(struct pa_pdispatch *pd, struct pa_packet*packet, void *use
goto finish;
#ifdef DEBUG_OPCODES
- fprintf(stderr, __FILE__": Recieved opcode <%s>\n", command_names[command]);
+ pa_log(__FILE__": Recieved opcode <%s>\n", command_names[command]);
#endif
if (command == PA_COMMAND_ERROR || command == PA_COMMAND_REPLY) {
@@ -191,7 +192,7 @@ int pa_pdispatch_run(struct pa_pdispatch *pd, struct pa_packet*packet, void *use
c->proc(pd, command, tag, ts, userdata);
} else {
- fprintf(stderr, "Recieved unsupported command %u\n", command);
+ pa_log(__FILE__": Recieved unsupported command %u\n", command);
goto finish;
}
diff --git a/polyp/polypaudio.pa b/polyp/polypaudio.pa
index 715e23b6..a31712f5 100755
--- a/polyp/polypaudio.pa
+++ b/polyp/polypaudio.pa
@@ -40,7 +40,7 @@ autoload_source_add input module-alsa-source source_name=input
#load module-simple-protocol-tcp
load module-native-protocol-unix
#load module-cli-protocol-unix
-load module-esound-protocol-unix
+#load module-esound-protocol-unix
# Load the CLI module
#load module-cli
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c
index fb6eadf4..94df7ec0 100644
--- a/polyp/polyplib-context.c
+++ b/polyp/polyplib-context.c
@@ -46,6 +46,7 @@
#include "authkey.h"
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_REQUEST] = { pa_command_request },
@@ -190,7 +191,7 @@ static void pstream_packet_callback(struct pa_pstream *p, struct pa_packet *pack
pa_context_ref(c);
if (pa_pdispatch_run(c->pdispatch, packet, c) < 0) {
- fprintf(stderr, "polyp.c: invalid packet.\n");
+ pa_log(__FILE__": invalid packet.\n");
pa_context_fail(c, PA_ERROR_PROTOCOL);
}
@@ -580,13 +581,13 @@ int pa_context_connect_spawn(struct pa_context *c, void (*atfork)(void)) {
return pa_context_connect(c, NULL);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
- fprintf(stderr, __FILE__": socketpair() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": socketpair() failed: %s\n", strerror(errno));
pa_context_fail(c, PA_ERROR_INTERNAL);
goto fail;
}
if ((pid = fork()) < 0) {
- fprintf(stderr, __FILE__": fork() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": fork() failed: %s\n", strerror(errno));
pa_context_fail(c, PA_ERROR_INTERNAL);
goto fail;
} else if (!pid) {
@@ -603,14 +604,14 @@ int pa_context_connect_spawn(struct pa_context *c, void (*atfork)(void)) {
p = POLYPAUDIO_BINARY;
snprintf(t, sizeof(t), "-Lmodule-native-protocol-fd fd=%i", fds[1]);
- execl(p, p, "-r", "-D", t, NULL);
+ execl(p, p, "-r", "-D", "-lsyslog", "-X 5", t, NULL);
exit(1);
}
/* Parent */
if (waitpid(pid, &status, 0) < 0) {
- fprintf(stderr, __FILE__": waitpid() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": waitpid() failed: %s\n", strerror(errno));
pa_context_fail(c, PA_ERROR_INTERNAL);
goto fail;
} else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
diff --git a/polyp/polyplib-simple.c b/polyp/polyplib-simple.c
index ccd39c2a..8caae87e 100644
--- a/polyp/polyplib-simple.c
+++ b/polyp/polyplib-simple.c
@@ -33,6 +33,7 @@
#include "mainloop.h"
#include "native-common.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_simple {
struct pa_mainloop *mainloop;
@@ -204,7 +205,7 @@ static void read_callback(struct pa_stream *s, const void*data, size_t length, v
assert(s && data && length && p);
if (p->read_data) {
- fprintf(stderr, __FILE__": Buffer overflow, dropping incoming memory blocks.\n");
+ pa_log(__FILE__": Buffer overflow, dropping incoming memory blocks.\n");
pa_xfree(p->read_data);
}
diff --git a/polyp/protocol-esound.c b/polyp/protocol-esound.c
index d6e2bf6b..3f87d4d0 100644
--- a/polyp/protocol-esound.c
+++ b/polyp/protocol-esound.c
@@ -45,6 +45,7 @@
#include "debug.h"
#include "namereg.h"
#include "xmalloc.h"
+#include "log.h"
#define DEFAULT_COOKIE_FILE ".esd_auth"
@@ -238,7 +239,7 @@ static int esd_proto_connect(struct connection *c, esd_proto_t request, const vo
if (!c->authorized) {
if (memcmp(data, c->protocol->esd_key, ESD_KEY_LEN) != 0) {
- fprintf(stderr, __FILE__": kicked client with invalid authorization key.\n");
+ pa_log(__FILE__": kicked client with invalid authorization key.\n");
return -1;
}
@@ -251,7 +252,7 @@ static int esd_proto_connect(struct connection *c, esd_proto_t request, const vo
else if (ekey == ESD_SWAP_ENDIAN_KEY)
c->swap_byte_order = 1;
else {
- fprintf(stderr, __FILE__": client sent invalid endian key\n");
+ pa_log(__FILE__": client sent invalid endian key\n");
return -1;
}
@@ -279,7 +280,7 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons
return -1;
if (!(sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1))) {
- fprintf(stderr, __FILE__": No output sink\n");
+ pa_log(__FILE__": No output sink\n");
return -1;
}
@@ -662,7 +663,7 @@ static int do_read(struct connection *c) {
assert(c->read_data_length < sizeof(c->request));
if ((r = pa_iochannel_read(c->io, ((uint8_t*) &c->request) + c->read_data_length, sizeof(c->request) - c->read_data_length)) <= 0) {
- fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1;
}
@@ -673,14 +674,14 @@ static int do_read(struct connection *c) {
c->request = swap_endian_32(c->request);
if (c->request < ESD_PROTO_CONNECT || c->request > ESD_PROTO_MAX) {
- fprintf(stderr, "protocol-esound.c: recieved invalid request.\n");
+ pa_log(__FILE__": recieved invalid request.\n");
return -1;
}
handler = proto_map+c->request;
if (!handler->proc) {
- fprintf(stderr, "protocol-sound.c: recieved unimplemented request.\n");
+ pa_log(__FILE__": recieved unimplemented request.\n");
return -1;
}
@@ -709,7 +710,7 @@ static int do_read(struct connection *c) {
assert(c->read_data && c->read_data_length < handler->data_length);
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->read_data + c->read_data_length, handler->data_length - c->read_data_length)) <= 0) {
- fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1;
}
@@ -729,7 +730,7 @@ static int do_read(struct connection *c) {
assert(c->scache_memchunk.memblock && c->scache_name && c->scache_memchunk.index < c->scache_memchunk.length);
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->scache_memchunk.memblock->data+c->scache_memchunk.index, c->scache_memchunk.length-c->scache_memchunk.index)) <= 0) {
- fprintf(stderr, __FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1;
}
@@ -784,7 +785,7 @@ static int do_read(struct connection *c) {
}
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
- fprintf(stderr, __FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1;
}
@@ -812,7 +813,7 @@ static int do_write(struct connection *c) {
assert(c->write_data_index < c->write_data_length);
if ((r = pa_iochannel_write(c->io, (uint8_t*) c->write_data+c->write_data_index, c->write_data_length-c->write_data_index)) < 0) {
- fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": write() failed: %s\n", strerror(errno));
return -1;
}
@@ -831,7 +832,7 @@ static int do_write(struct connection *c) {
if ((r = pa_iochannel_write(c->io, (uint8_t*) chunk.memblock->data+chunk.index, chunk.length)) < 0) {
pa_memblock_unref(chunk.memblock);
- fprintf(stderr, __FILE__": write(): %s\n", strerror(errno));
+ pa_log(__FILE__": write(): %s\n", strerror(errno));
return -1;
}
diff --git a/polyp/protocol-native.c b/polyp/protocol-native.c
index 2572810f..4c99d5fe 100644
--- a/polyp/protocol-native.c
+++ b/polyp/protocol-native.c
@@ -44,6 +44,7 @@
#include "xmalloc.h"
#include "util.h"
#include "subscribe.h"
+#include "log.h"
struct connection;
struct pa_protocol_native;
@@ -357,7 +358,7 @@ static void request_bytes(struct playback_stream *s) {
pa_tagstruct_putu32(t, l);
pa_pstream_send_tagstruct(s->connection->pstream, t);
- /*fprintf(stderr, "Requesting %u bytes\n", l);*/
+ /*pa_log(__FILE__": Requesting %u bytes\n", l);*/
}
static void send_memblock(struct connection *c) {
@@ -421,7 +422,7 @@ static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk
assert(i && i->userdata && chunk);
s = i->userdata;
- /*fprintf(stderr, "%3.0f \r", (double) pa_memblockq_get_length(s->memblockq)/pa_memblockq_get_tlength(s->memblockq)*100);*/
+ /*pa_log(__FILE__": %3.0f \r", (double) pa_memblockq_get_length(s->memblockq)/pa_memblockq_get_tlength(s->memblockq)*100);*/
if (pa_memblockq_peek(s->memblockq, chunk) < 0)
return -1;
@@ -442,7 +443,7 @@ static void sink_input_drop_cb(struct pa_sink_input *i, const struct pa_memchunk
s->drain_request = 0;
}
- /*fprintf(stderr, "after_drop: %u\n", pa_memblockq_get_length(s->memblockq));*/
+ /*pa_log(__FILE__": after_drop: %u\n", pa_memblockq_get_length(s->memblockq));*/
}
static void sink_input_kill_cb(struct pa_sink_input *i) {
@@ -456,7 +457,7 @@ static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i) {
assert(i && i->userdata);
s = i->userdata;
- /*fprintf(stderr, "get_latency: %u\n", pa_memblockq_get_length(s->memblockq));*/
+ /*pa_log(__FILE__": get_latency: %u\n", pa_memblockq_get_length(s->memblockq));*/
return pa_bytes_to_usec(pa_memblockq_get_length(s->memblockq), &s->sink_input->sample_spec);
}
@@ -482,7 +483,7 @@ static void source_output_kill_cb(struct pa_source_output *o) {
/*** pdispatch callbacks ***/
static void protocol_error(struct connection *c) {
- fprintf(stderr, __FILE__": protocol error, kicking client\n");
+ pa_log(__FILE__": protocol error, kicking client\n");
connection_free(c);
}
@@ -671,7 +672,7 @@ static void command_auth(struct pa_pdispatch *pd, uint32_t command, uint32_t tag
}
if (memcmp(c->protocol->auth_cookie, cookie, PA_NATIVE_COOKIE_LENGTH) != 0) {
- fprintf(stderr, "protocol-native.c: Denied access to client with invalid authorization key.\n");
+ pa_log(__FILE__": Denied access to client with invalid authorization key.\n");
pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
return;
}
@@ -1364,7 +1365,7 @@ static void command_flush_or_trigger_playback_stream(struct pa_pdispatch *pd, ui
else {
assert(command == PA_COMMAND_FLUSH_PLAYBACK_STREAM);
pa_memblockq_flush(s->memblockq);
- /*fprintf(stderr, "flush: %u\n", pa_memblockq_get_length(s->memblockq));*/
+ /*pa_log(__FILE__": flush: %u\n", pa_memblockq_get_length(s->memblockq));*/
}
pa_sink_notify(s->sink_input->sink);
@@ -1379,7 +1380,7 @@ static void pstream_packet_callback(struct pa_pstream *p, struct pa_packet *pack
assert(p && packet && packet->data && c);
if (pa_pdispatch_run(c->pdispatch, packet, c) < 0) {
- fprintf(stderr, "protocol-native: invalid packet.\n");
+ pa_log(__FILE__": invalid packet.\n");
connection_free(c);
}
}
@@ -1390,7 +1391,7 @@ static void pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, ui
assert(p && chunk && userdata);
if (!(stream = pa_idxset_get_by_index(c->output_streams, channel))) {
- fprintf(stderr, "protocol-native: client sent block for invalid stream.\n");
+ pa_log(__FILE__": client sent block for invalid stream.\n");
connection_free(c);
return;
}
@@ -1404,10 +1405,10 @@ static void pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, ui
pa_memblockq_push_align(p->memblockq, chunk, delta);
assert(p->sink_input);
- /*fprintf(stderr, "after_recv: %u\n", pa_memblockq_get_length(p->memblockq));*/
+ /*pa_log(__FILE__": after_recv: %u\n", pa_memblockq_get_length(p->memblockq));*/
pa_sink_notify(p->sink_input->sink);
- /*fprintf(stderr, "Recieved %u bytes.\n", chunk->length);*/
+ /*pa_log(__FILE__": Recieved %u bytes.\n", chunk->length);*/
} else {
struct upload_stream *u = (struct upload_stream*) stream;
@@ -1445,7 +1446,7 @@ static void pstream_die_callback(struct pa_pstream *p, void *userdata) {
assert(p && c);
connection_free(c);
-/* fprintf(stderr, "protocol-native: connection died.\n");*/
+/* pa_log(__FILE__": connection died.\n");*/
}
@@ -1509,7 +1510,7 @@ static struct pa_protocol_native* protocol_new_internal(struct pa_core *c, struc
assert(c && ma);
if (pa_modargs_get_value_boolean(ma, "public", &public) < 0) {
- fprintf(stderr, __FILE__": public= expects numeric argument.\n");
+ pa_log(__FILE__": public= expects numeric argument.\n");
return NULL;
}
diff --git a/polyp/protocol-simple.c b/polyp/protocol-simple.c
index 3ccb3068..f6240462 100644
--- a/polyp/protocol-simple.c
+++ b/polyp/protocol-simple.c
@@ -37,6 +37,7 @@
#include "sample-util.h"
#include "namereg.h"
#include "xmalloc.h"
+#include "log.h"
struct connection {
struct pa_protocol_simple *protocol;
@@ -121,7 +122,7 @@ static int do_read(struct connection *c) {
}
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
- fprintf(stderr, __FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+ pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1;
}
@@ -155,7 +156,7 @@ static int do_write(struct connection *c) {
if ((r = pa_iochannel_write(c->io, (uint8_t*) chunk.memblock->data+chunk.index, chunk.length)) < 0) {
pa_memblock_unref(chunk.memblock);
- fprintf(stderr, "write(): %s\n", strerror(errno));
+ pa_log(__FILE__": write(): %s\n", strerror(errno));
return -1;
}
@@ -299,12 +300,12 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
size_t l;
if (!(sink = pa_namereg_get(p->core, p->sink_name, PA_NAMEREG_SINK, 1))) {
- fprintf(stderr, "Failed to get sink.\n");
+ pa_log(__FILE__": Failed to get sink.\n");
goto fail;
}
if (!(c->sink_input = pa_sink_input_new(sink, c->client->name, &p->sample_spec))) {
- fprintf(stderr, "Failed to create sink input.\n");
+ pa_log(__FILE__": Failed to create sink input.\n");
goto fail;
}
@@ -329,13 +330,13 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
size_t l;
if (!(source = pa_namereg_get(p->core, p->source_name, PA_NAMEREG_SOURCE, 1))) {
- fprintf(stderr, "Failed to get source.\n");
+ pa_log(__FILE__": Failed to get source.\n");
goto fail;
}
c->source_output = pa_source_output_new(source, c->client->name, &p->sample_spec);
if (!c->source_output) {
- fprintf(stderr, "Failed to create source output.\n");
+ pa_log(__FILE__": Failed to create source output.\n");
goto fail;
}
c->source_output->owner = p->module;
@@ -377,7 +378,7 @@ struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct p
p->sample_spec = core->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &p->sample_spec) < 0) {
- fprintf(stderr, "Failed to parse sample type specification.\n");
+ pa_log(__FILE__": Failed to parse sample type specification.\n");
goto fail;
}
@@ -386,20 +387,20 @@ struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct p
enable = 0;
if (pa_modargs_get_value_boolean(ma, "record", &enable) < 0) {
- fprintf(stderr, __FILE__": record= expects a numeric argument.\n");
+ pa_log(__FILE__": record= expects a numeric argument.\n");
goto fail;
}
p->mode = enable ? RECORD : 0;
enable = 1;
if (pa_modargs_get_value_boolean(ma, "playback", &enable) < 0) {
- fprintf(stderr, __FILE__": playback= expects a numeric argument.\n");
+ pa_log(__FILE__": playback= expects a numeric argument.\n");
goto fail;
}
p->mode |= enable ? PLAYBACK : 0;
if ((p->mode & (RECORD|PLAYBACK)) == 0) {
- fprintf(stderr, __FILE__": neither playback nor recording enabled for protocol.\n");
+ pa_log(__FILE__": neither playback nor recording enabled for protocol.\n");
goto fail;
}
diff --git a/polyp/pstream.c b/polyp/pstream.c
index 438dccc7..1883c95d 100644
--- a/polyp/pstream.c
+++ b/polyp/pstream.c
@@ -31,6 +31,7 @@
#include "pstream.h"
#include "queue.h"
#include "xmalloc.h"
+#include "log.h"
enum pa_pstream_descriptor_index {
PA_PSTREAM_DESCRIPTOR_LENGTH,
@@ -214,7 +215,7 @@ void pa_pstream_send_packet(struct pa_pstream*p, struct pa_packet *packet) {
struct item_info *i;
assert(p && packet);
- /*fprintf(stderr, "push-packet %p\n", packet);*/
+ /*pa_log(__FILE__": push-packet %p\n", packet);*/
i = pa_xmalloc(sizeof(struct item_info));
i->type = PA_PSTREAM_ITEM_PACKET;
@@ -263,7 +264,7 @@ static void prepare_next_write_item(struct pa_pstream *p) {
p->write.index = 0;
if (p->write.current->type == PA_PSTREAM_ITEM_PACKET) {
- /*fprintf(stderr, "pop-packet %p\n", p->write.current->packet);*/
+ /*pa_log(__FILE__": pop-packet %p\n", p->write.current->packet);*/
assert(p->write.current->packet);
p->write.data = p->write.current->packet->data;
@@ -348,7 +349,7 @@ static void do_read(struct pa_pstream *p) {
/* Frame size too large */
if (ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) > FRAME_SIZE_MAX) {
- fprintf(stderr, "frame size too large\n");
+ pa_log(__FILE__": Frame size too large\n");
goto die;
}
diff --git a/polyp/sink-input.c b/polyp/sink-input.c
index 95dc5577..f4f57343 100644
--- a/polyp/sink-input.c
+++ b/polyp/sink-input.c
@@ -32,6 +32,7 @@
#include "sample-util.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
#define CONVERT_BUFFER_LENGTH 4096
@@ -43,7 +44,7 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
assert(s && spec);
if (pa_idxset_ncontents(s->inputs) >= PA_MAX_INPUTS_PER_SINK) {
- fprintf(stderr, __FILE__": Failed to create sink input: too many inputs per sink.\n");
+ pa_log(__FILE__": Failed to create sink input: too many inputs per sink.\n");
return NULL;
}
@@ -78,7 +79,7 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
assert(r == 0);
pa_sample_spec_snprint(st, sizeof(st), spec);
- fprintf(stderr, "sink-input: created %u \"%s\" on %u with sample spec \"%s\"\n", i->index, i->name, s->index, st);
+ pa_log(__FILE__": created %u \"%s\" on %u with sample spec \"%s\"\n", i->index, i->name, s->index, st);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, i->index);
diff --git a/polyp/sink.c b/polyp/sink.c
index 104248a9..9b8a6492 100644
--- a/polyp/sink.c
+++ b/polyp/sink.c
@@ -35,6 +35,7 @@
#include "sample-util.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
#define MAX_MIX_CHANNELS 32
@@ -77,7 +78,7 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co
assert(s->index != PA_IDXSET_INVALID && r >= 0);
pa_sample_spec_snprint(st, sizeof(st), spec);
- fprintf(stderr, "sink: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
+ pa_log(__FILE__": created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_NEW, s->index);
@@ -100,7 +101,7 @@ void pa_sink_free(struct pa_sink *s) {
pa_source_free(s->monitor_source);
pa_idxset_remove_by_data(s->core->sinks, s, NULL);
- fprintf(stderr, "sink: freed %u \"%s\"\n", s->index, s->name);
+ pa_log(__FILE__": freed %u \"%s\"\n", s->index, s->name);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
diff --git a/polyp/socket-client.c b/polyp/socket-client.c
index f697cbdb..773e922c 100644
--- a/polyp/socket-client.c
+++ b/polyp/socket-client.c
@@ -37,6 +37,7 @@
#include "socket-util.h"
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_socket_client {
int ref;
@@ -73,17 +74,17 @@ static void do_call(struct pa_socket_client *c) {
lerror = sizeof(error);
if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, &error, &lerror) < 0) {
- fprintf(stderr, "getsockopt(): %s\n", strerror(errno));
+ pa_log(__FILE__": getsockopt(): %s\n", strerror(errno));
goto finish;
}
if (lerror != sizeof(error)) {
- fprintf(stderr, "getsocktop() returned invalid size.\n");
+ pa_log(__FILE__": getsockopt() returned invalid size.\n");
goto finish;
}
if (error != 0) {
- fprintf(stderr, "connect(): %s\n", strerror(error));
+ pa_log(__FILE__": connect(): %s\n", strerror(error));
goto finish;
}
@@ -125,7 +126,7 @@ static int do_connect(struct pa_socket_client *c, const struct sockaddr *sa, soc
if ((r = connect(c->fd, sa, len)) < 0) {
if (errno != EINPROGRESS) {
- /*fprintf(stderr, "connect(): %s\n", strerror(errno));*/
+ /*pa_log(__FILE__": connect(): %s\n", strerror(errno));*/
return -1;
}
@@ -148,7 +149,7 @@ struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, ui
assert(c);
if ((c->fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "socket(): %s\n", strerror(errno));
+ pa_log(__FILE__": socket(): %s\n", strerror(errno));
goto fail;
}
@@ -178,7 +179,7 @@ struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, co
assert(c);
if ((c->fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "socket(): %s\n", strerror(errno));
+ pa_log(__FILE__": socket(): %s\n", strerror(errno));
goto fail;
}
@@ -206,7 +207,7 @@ struct pa_socket_client* pa_socket_client_new_sockaddr(struct pa_mainloop_api *m
assert(c);
if ((c->fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "socket(): %s\n", strerror(errno));
+ pa_log(__FILE__": socket(): %s\n", strerror(errno));
goto fail;
}
diff --git a/polyp/socket-server.c b/polyp/socket-server.c
index 131339ed..9f943dc0 100644
--- a/polyp/socket-server.c
+++ b/polyp/socket-server.c
@@ -39,6 +39,7 @@
#include "socket-util.h"
#include "xmalloc.h"
#include "util.h"
+#include "log.h"
struct pa_socket_server {
int ref;
@@ -62,7 +63,7 @@ static void callback(struct pa_mainloop_api *mainloop, struct pa_io_event *e, in
pa_socket_server_ref(s);
if ((nfd = accept(fd, NULL, NULL)) < 0) {
- fprintf(stderr, "accept(): %s\n", strerror(errno));
+ pa_log(__FILE__": accept(): %s\n", strerror(errno));
goto finish;
}
@@ -121,7 +122,7 @@ struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, co
assert(m && filename);
if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "socket(): %s\n", strerror(errno));
+ pa_log(__FILE__": socket(): %s\n", strerror(errno));
goto fail;
}
@@ -134,12 +135,12 @@ struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, co
pa_socket_low_delay(fd);
if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) {
- fprintf(stderr, "bind(): %s\n", strerror(errno));
+ pa_log(__FILE__": bind(): %s\n", strerror(errno));
goto fail;
}
if (listen(fd, 5) < 0) {
- fprintf(stderr, "listen(): %s\n", strerror(errno));
+ pa_log(__FILE__": listen(): %s\n", strerror(errno));
goto fail;
}
@@ -167,14 +168,14 @@ struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, ui
assert(m && port);
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "socket(): %s\n", strerror(errno));
+ pa_log(__FILE__": socket(): %s\n", strerror(errno));
goto fail;
}
pa_fd_set_cloexec(fd, 1);
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
- fprintf(stderr, "setsockopt(): %s\n", strerror(errno));
+ pa_log(__FILE__": setsockopt(): %s\n", strerror(errno));
pa_socket_tcp_low_delay(fd);
@@ -183,12 +184,12 @@ struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, ui
sa.sin_addr.s_addr = htonl(address);
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
- fprintf(stderr, "bind(): %s\n", strerror(errno));
+ pa_log(__FILE__": bind(): %s\n", strerror(errno));
goto fail;
}
if (listen(fd, 5) < 0) {
- fprintf(stderr, "listen(): %s\n", strerror(errno));
+ pa_log(__FILE__": listen(): %s\n", strerror(errno));
goto fail;
}
diff --git a/polyp/socket-util.c b/polyp/socket-util.c
index 1f93ef88..2f082bfb 100644
--- a/polyp/socket-util.c
+++ b/polyp/socket-util.c
@@ -41,6 +41,7 @@
#include "socket-util.h"
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
void pa_socket_peer_to_string(int fd, char *c, size_t l) {
struct stat st;
@@ -122,7 +123,7 @@ int pa_socket_set_rcvbuf(int fd, size_t l) {
assert(fd >= 0);
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &l, sizeof(l)) < 0) {
- fprintf(stderr, "SO_RCVBUF: %s\n", strerror(errno));
+ pa_log(__FILE__": SO_RCVBUF: %s\n", strerror(errno));
return -1;
}
@@ -133,7 +134,7 @@ int pa_socket_set_sndbuf(int fd, size_t l) {
assert(fd >= 0);
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &l, sizeof(l)) < 0) {
- fprintf(stderr, "SO_SNDBUF: %s\n", strerror(errno));
+ pa_log(__FILE__": SO_SNDBUF: %s\n", strerror(errno));
return -1;
}
@@ -145,7 +146,7 @@ int pa_unix_socket_is_stale(const char *fn) {
int fd = -1, ret = -1;
if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "socket(): %s\n", strerror(errno));
+ pa_log(__FILE__": socket(): %s\n", strerror(errno));
goto finish;
}
diff --git a/polyp/sound-file-stream.c b/polyp/sound-file-stream.c
index a77b5813..c667f5ff 100644
--- a/polyp/sound-file-stream.c
+++ b/polyp/sound-file-stream.c
@@ -33,6 +33,7 @@
#include "sound-file-stream.h"
#include "sink-input.h"
#include "xmalloc.h"
+#include "log.h"
#define BUF_SIZE (1024*10)
@@ -128,7 +129,7 @@ int pa_play_file(struct pa_sink *sink, const char *fname, pa_volume_t volume) {
memset(&sfinfo, 0, sizeof(sfinfo));
if (!(u->sndfile = sf_open(fname, SFM_READ, &sfinfo))) {
- fprintf(stderr, __FILE__": Failed to open file %s\n", fname);
+ pa_log(__FILE__": Failed to open file %s\n", fname);
goto fail;
}
@@ -137,7 +138,7 @@ int pa_play_file(struct pa_sink *sink, const char *fname, pa_volume_t volume) {
ss.channels = sfinfo.channels;
if (!pa_sample_spec_valid(&ss)) {
- fprintf(stderr, __FILE__": Unsupported sample format in file %s\n", fname);
+ pa_log(__FILE__": Unsupported sample format in file %s\n", fname);
goto fail;
}
diff --git a/polyp/sound-file.c b/polyp/sound-file.c
index 01fda78e..d1f7e0f7 100644
--- a/polyp/sound-file.c
+++ b/polyp/sound-file.c
@@ -30,6 +30,7 @@
#include "sound-file.h"
#include "sample.h"
+#include "log.h"
#define MAX_FILE_SIZE (1024*1024)
@@ -46,7 +47,7 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_m
chunk->index = chunk->length = 0;
if (!(sf = sf_open(fname, SFM_READ, &sfinfo))) {
- fprintf(stderr, __FILE__": Failed to open file %s\n", fname);
+ pa_log(__FILE__": Failed to open file %s\n", fname);
goto finish;
}
@@ -55,12 +56,12 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_m
ss->channels = sfinfo.channels;
if (!pa_sample_spec_valid(ss)) {
- fprintf(stderr, __FILE__": Unsupported sample format in file %s\n", fname);
+ pa_log(__FILE__": Unsupported sample format in file %s\n", fname);
goto finish;
}
if ((l = pa_frame_size(ss)*sfinfo.frames) > MAX_FILE_SIZE) {
- fprintf(stderr, __FILE__": File to large\n");
+ pa_log(__FILE__": File to large\n");
goto finish;
}
@@ -70,7 +71,7 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_m
chunk->length = l;
if (sf_readf_float(sf, chunk->memblock->data, sfinfo.frames) != sfinfo.frames) {
- fprintf(stderr, __FILE__": Premature file end\n");
+ pa_log(__FILE__": Premature file end\n");
goto finish;
}
diff --git a/polyp/source-output.c b/polyp/source-output.c
index 9d124f07..55448b5c 100644
--- a/polyp/source-output.c
+++ b/polyp/source-output.c
@@ -31,6 +31,7 @@
#include "source-output.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec) {
struct pa_source_output *o;
@@ -39,7 +40,7 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n
assert(s && spec);
if (pa_idxset_ncontents(s->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
- fprintf(stderr, __FILE__": Failed to create source output: too many outputs per source.\n");
+ pa_log(__FILE__": Failed to create source output: too many outputs per source.\n");
return NULL;
}
diff --git a/polyp/source.c b/polyp/source.c
index 6ab439d6..5cdfdb55 100644
--- a/polyp/source.c
+++ b/polyp/source.c
@@ -33,6 +33,7 @@
#include "namereg.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
struct pa_source *s;
@@ -63,7 +64,7 @@ struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail
assert(s->index != PA_IDXSET_INVALID && r >= 0);
pa_sample_spec_snprint(st, sizeof(st), spec);
- fprintf(stderr, "source: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
+ pa_log(__FILE__": created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index);
@@ -85,7 +86,7 @@ void pa_source_free(struct pa_source *s) {
pa_idxset_remove_by_data(s->core->sources, s, NULL);
- fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name);
+ pa_log(__FILE__": freed %u \"%s\"\n", s->index, s->name);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
diff --git a/polyp/strbuf.h b/polyp/strbuf.h
index 8ca51624..1622d3a0 100644
--- a/polyp/strbuf.h
+++ b/polyp/strbuf.h
@@ -22,6 +22,8 @@
USA.
***/
+#include "gcc-printf.h"
+
struct pa_strbuf;
struct pa_strbuf *pa_strbuf_new(void);
@@ -29,7 +31,7 @@ void pa_strbuf_free(struct pa_strbuf *sb);
char *pa_strbuf_tostring(struct pa_strbuf *sb);
char *pa_strbuf_tostring_free(struct pa_strbuf *sb);
-int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
void pa_strbuf_puts(struct pa_strbuf *sb, const char *t);
void pa_strbuf_putsn(struct pa_strbuf *sb, const char *t, size_t m);
diff --git a/polyp/subscribe.c b/polyp/subscribe.c
index 5f7651fd..d3b97de7 100644
--- a/polyp/subscribe.c
+++ b/polyp/subscribe.c
@@ -29,6 +29,7 @@
#include "queue.h"
#include "subscribe.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_subscription {
struct pa_core *core;
@@ -109,44 +110,44 @@ void pa_subscription_free_all(struct pa_core *c) {
/*static void dump_event(struct pa_subscription_event*e) {
switch (e->type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
- fprintf(stderr, "SINK_EVENT");
+ pa_log(__FILE__": SINK_EVENT");
break;
case PA_SUBSCRIPTION_EVENT_SOURCE:
- fprintf(stderr, "SOURCE_EVENT");
+ pa_log(__FILE__": SOURCE_EVENT");
break;
case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
- fprintf(stderr, "SINK_INPUT_EVENT");
+ pa_log(__FILE__": SINK_INPUT_EVENT");
break;
case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
- fprintf(stderr, "SOURCE_OUTPUT_EVENT");
+ pa_log(__FILE__": SOURCE_OUTPUT_EVENT");
break;
case PA_SUBSCRIPTION_EVENT_MODULE:
- fprintf(stderr, "MODULE_EVENT");
+ pa_log(__FILE__": MODULE_EVENT");
break;
case PA_SUBSCRIPTION_EVENT_CLIENT:
- fprintf(stderr, "CLIENT_EVENT");
+ pa_log(__FILE__": CLIENT_EVENT");
break;
default:
- fprintf(stderr, "OTHER");
+ pa_log(__FILE__": OTHER");
break;
}
switch (e->type & PA_SUBSCRIPTION_EVENT_TYPE_MASK) {
case PA_SUBSCRIPTION_EVENT_NEW:
- fprintf(stderr, " NEW");
+ pa_log(__FILE__": NEW");
break;
case PA_SUBSCRIPTION_EVENT_CHANGE:
- fprintf(stderr, " CHANGE");
+ pa_log(__FILE__": CHANGE");
break;
case PA_SUBSCRIPTION_EVENT_REMOVE:
- fprintf(stderr, " REMOVE");
+ pa_log(__FILE__": REMOVE");
break;
default:
- fprintf(stderr, " OTHER");
+ pa_log(__FILE__": OTHER");
break;
}
- fprintf(stderr, " %u\n", e->index);
+ pa_log(__FILE__": %u\n", e->index);
}*/
static void defer_cb(struct pa_mainloop_api *m, struct pa_defer_event *e, void *userdata) {
diff --git a/polyp/util.c b/polyp/util.c
index 061d5710..408e60e9 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -42,6 +42,7 @@
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
void pa_make_nonblock_fd(int fd) {
int v;
@@ -121,7 +122,7 @@ void pa_check_for_sigpipe(void) {
if (pthread_sigmask(SIG_SETMASK, NULL, &set) < 0) {
#endif
if (sigprocmask(SIG_SETMASK, NULL, &set) < 0) {
- fprintf(stderr, __FILE__": sigprocmask() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": sigprocmask() failed: %s\n", strerror(errno));
return;
}
#ifdef HAVE_PTHREAD
@@ -132,14 +133,14 @@ void pa_check_for_sigpipe(void) {
return;
if (sigaction(SIGPIPE, NULL, &sa) < 0) {
- fprintf(stderr, __FILE__": sigaction() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": sigaction() failed: %s\n", strerror(errno));
return;
}
if (sa.sa_handler != SIG_DFL)
return;
- fprintf(stderr, "polypaudio: WARNING: SIGPIPE is not trapped. This might cause malfunction!\n");
+ pa_log(__FILE__": WARNING: SIGPIPE is not trapped. This might cause malfunction!\n");
}
/* The following is based on an example from the GNU libc documentation */
@@ -169,6 +170,30 @@ char *pa_sprintf_malloc(const char *format, ...) {
}
}
+char *pa_vsprintf_malloc(const char *format, va_list ap) {
+ int size = 100;
+ char *c = NULL;
+
+ assert(format);
+
+ for(;;) {
+ int r;
+ va_list ap;
+
+ c = pa_xrealloc(c, size);
+ r = vsnprintf(c, size, format, ap);
+
+ if (r > -1 && r < size)
+ return c;
+
+ if (r > -1) /* glibc 2.1 */
+ size = r+1;
+ else /* glibc 2.0 */
+ size *= 2;
+ }
+}
+
+
char *pa_get_user_name(char *s, size_t l) {
struct passwd pw, *r;
char buf[1024];
@@ -220,26 +245,26 @@ uint32_t pa_age(struct timeval *tv) {
void pa_raise_priority(void) {
if (setpriority(PRIO_PROCESS, 0, NICE_LEVEL) < 0)
- fprintf(stderr, __FILE__": setpriority() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": setpriority() failed: %s\n", strerror(errno));
else
- fprintf(stderr, __FILE__": Successfully gained nice level %i.\n", NICE_LEVEL);
+ pa_log(__FILE__": Successfully gained nice level %i.\n", NICE_LEVEL);
#ifdef _POSIX_PRIORITY_SCHEDULING
{
struct sched_param sp;
if (sched_getparam(0, &sp) < 0) {
- fprintf(stderr, __FILE__": sched_getparam() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": sched_getparam() failed: %s\n", strerror(errno));
return;
}
sp.sched_priority = 1;
if (sched_setscheduler(0, SCHED_FIFO, &sp) < 0) {
- fprintf(stderr, __FILE__": sched_setscheduler() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": sched_setscheduler() failed: %s\n", strerror(errno));
return;
}
- fprintf(stderr, __FILE__": Successfully enabled SCHED_FIFO scheduling.\n");
+ pa_log(__FILE__": Successfully enabled SCHED_FIFO scheduling.\n");
}
#endif
}
diff --git a/polyp/util.h b/polyp/util.h
index f8dd3f04..18f883f0 100644
--- a/polyp/util.h
+++ b/polyp/util.h
@@ -24,6 +24,9 @@
#include <sys/types.h>
#include <inttypes.h>
+#include <stdarg.h>
+
+#include "gcc-printf.h"
void pa_make_nonblock_fd(int fd);
@@ -34,7 +37,8 @@ ssize_t pa_loop_write(int fd, const void*data, size_t size);
void pa_check_for_sigpipe(void);
-char *pa_sprintf_malloc(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+char *pa_sprintf_malloc(const char *format, ...) PA_GCC_PRINTF_ATTR(1,2);
+char *pa_vsprintf_malloc(const char *format, va_list ap);
char *pa_get_user_name(char *s, size_t l);
char *pa_get_host_name(char *s, size_t l);