AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
+AC_TYPE_OFF_T
AC_HEADER_TIME
# Checks for library functions.
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
kill client/...
autoload management
- more complete pactl
-- logging
- add sample directory
- add timing parameter to write callback of stream in client API
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)
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
#include "authkey.h"
#include "util.h"
+#include "log.h"
#define RANDOM_DEVICE "/dev/urandom"
} 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));
}
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;
}
#include "cli-text.h"
#include "cli-command.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_cli {
struct pa_core *core;
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 {
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);
#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;
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);
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);
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;
}
" -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);
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);
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;
}
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 []);
int quit_after_last_client_time;
struct pa_time_event *quit_event;
-
};
struct pa_core* pa_core_new(struct pa_mainloop_api *m);
#include "cpulimit.h"
#include "util.h"
+#include "log.h"
/* Utilize this much CPU time at maximum */
#define CPUTIME_PERCENT 70
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;
}
--- /dev/null
+#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
--- /dev/null
+#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);
+}
--- /dev/null
+#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
#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());
}
}
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:
case SIGINT:
case SIGTERM:
default:
- fprintf(stderr, "Exiting.\n");
+ pa_log(__FILE__": Exiting.\n");
m->quit(m, 1);
return;
}
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;
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;
}
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;
}
close(daemon_pipe[0]);
daemon_pipe[0] = -1;
+
+ if (cmdline->auto_log_target)
+ pa_log_set_target(PA_LOG_SYSLOG, NULL);
+
setsid();
setpgrp();
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 {
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);
lt_dlexit();
+ pa_log(__FILE__": Daemon terminated.\n");
+
finish:
if (cmdline)
pa_cmdline_free(cmdline);
close_pipe(daemon_pipe);
-
+
return retval;
}
#include "mainloop-signal.h"
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_signal_event {
int sig;
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;
}
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;
}
#include "util.h"
#include "idxset.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_io_event {
struct pa_mainloop *mainloop;
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);
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;
#include "memblockq.h"
#include "xmalloc.h"
+#include "log.h"
struct memblock_list {
struct memblock_list *next, *prev;
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;
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;
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;
#include "sample-util.h"
#include "alsa-util.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
snd_pcm_t *pcm_handle;
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) {
continue;
}
- fprintf(stderr, "snd_pcm_writei() failed\n");
+ pa_log(__FILE__": snd_pcm_writei() failed\n");
return;
}
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;
}
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);
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;
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;
}
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);
#include "sample-util.h"
#include "alsa-util.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
snd_pcm_t *pcm_handle;
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) {
continue;
}
- fprintf(stderr, "snd_pcm_readi() failed: %s\n", strerror(-frames));
+ pa_log(__FILE__": snd_pcm_readi() failed: %s\n", strerror(-frames));
return;
}
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);
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;
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;
}
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;
#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;
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;
}
#include "iochannel.h"
#include "modargs.h"
#include "protocol-native.h"
+#include "log.h"
static const char* const valid_modargs[] = {
"fd",
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;
}
#include "util.h"
#include "modargs.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
struct pa_sink *sink;
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;
}
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;
}
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;
}
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;
}
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;
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 {
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 {
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;
}
#include "util.h"
#include "modargs.h"
#include "xmalloc.h"
+#include "log.h"
struct userdata {
struct pa_sink *sink;
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;
}
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;
}
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;
}
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;
}
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;
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;
}
#include "util.h"
#include "modargs.h"
#include "xmalloc.h"
+#include "log.h"
#define DEFAULT_FIFO_NAME "/tmp/musicfifo"
#define DEFAULT_SINK_NAME "fifo_output"
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;
}
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;
}
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;
#include "socket-util.h"
#include "util.h"
#include "modargs.h"
+#include "log.h"
#if defined(USE_PROTOCOL_SIMPLE)
#include "protocol-simple.h"
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;
}
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;
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;
}
#include "modargs.h"
#include "xmalloc.h"
#include "namereg.h"
+#include "log.h"
struct userdata {
struct pa_core *core;
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;
}
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;
}
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;
}
#include "modargs.h"
#include "xmalloc.h"
#include "namereg.h"
+#include "log.h"
struct x11_source {
struct pa_io_event *io_event;
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;
}
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);
}
}
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;
}
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;
}
minor = XkbMinorVersion;
if (!XkbLibraryVersion(&major, &minor)) {
- fprintf(stderr, __FILE__": XkbLibraryVersion() failed\n");
+ pa_log(__FILE__": XkbLibraryVersion() failed\n");
goto fail;
}
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;
}
#include "module.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
#define UNLOAD_POLL_TIME 10
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));
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);
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);
#include "oss-util.h"
#include "util.h"
+#include "log.h"
int pa_oss_open(const char *device, int *mode, int* pcaps) {
int fd = -1;
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;
}
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;
}
}
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;
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);
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);
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;
}
#include "native-common.h"
#include "xmalloc.h"
#include "llist.h"
+#include "log.h"
/*#define DEBUG_OPCODES*/
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) {
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;
}
#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
#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 },
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);
}
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) {
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) {
#include "mainloop.h"
#include "native-common.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_simple {
struct pa_mainloop *mainloop;
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);
}
#include "debug.h"
#include "namereg.h"
#include "xmalloc.h"
+#include "log.h"
#define DEFAULT_COOKIE_FILE ".esd_auth"
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
}
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;
}
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;
}
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;
}
#include "xmalloc.h"
#include "util.h"
#include "subscribe.h"
+#include "log.h"
struct connection;
struct pa_protocol_native;
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) {
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;
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) {
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);
}
/*** 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);
}
}
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;
}
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);
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);
}
}
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;
}
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;
assert(p && c);
connection_free(c);
-/* fprintf(stderr, "protocol-native: connection died.\n");*/
+/* pa_log(__FILE__": connection died.\n");*/
}
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;
}
#include "sample-util.h"
#include "namereg.h"
#include "xmalloc.h"
+#include "log.h"
struct connection {
struct pa_protocol_simple *protocol;
}
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;
}
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;
}
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;
}
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;
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;
}
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;
}
#include "pstream.h"
#include "queue.h"
#include "xmalloc.h"
+#include "log.h"
enum pa_pstream_descriptor_index {
PA_PSTREAM_DESCRIPTOR_LENGTH,
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;
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;
/* 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;
}
#include "sample-util.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
#define CONVERT_BUFFER_LENGTH 4096
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;
}
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);
#include "sample-util.h"
#include "xmalloc.h"
#include "subscribe.h"
+#include "log.h"
#define MAX_MIX_CHANNELS 32
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);
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);
#include "socket-util.h"
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_socket_client {
int ref;
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;
}
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;
}
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;
}
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;
}
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;
}
#include "socket-util.h"
#include "xmalloc.h"
#include "util.h"
+#include "log.h"
struct pa_socket_server {
int ref;
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;
}
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;
}
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;
}
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);
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;
}
#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;
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;
}
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;
}
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;
}
#include "sound-file-stream.h"
#include "sink-input.h"
#include "xmalloc.h"
+#include "log.h"
#define BUF_SIZE (1024*10)
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;
}
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;
}
#include "sound-file.h"
#include "sample.h"
+#include "log.h"
#define MAX_FILE_SIZE (1024*1024)
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;
}
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;
}
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;
}
#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;
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;
}
#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;
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);
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);
USA.
***/
+#include "gcc-printf.h"
+
struct pa_strbuf;
struct pa_strbuf *pa_strbuf_new(void);
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);
#include "queue.h"
#include "subscribe.h"
#include "xmalloc.h"
+#include "log.h"
struct pa_subscription {
struct pa_core *core;
/*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) {
#include "util.h"
#include "xmalloc.h"
+#include "log.h"
void pa_make_nonblock_fd(int fd) {
int v;
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
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 */
}
}
+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];
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
}
#include <sys/types.h>
#include <inttypes.h>
+#include <stdarg.h>
+
+#include "gcc-printf.h"
void pa_make_nonblock_fd(int fd);
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);