summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/daemon/caps.c2
-rw-r--r--src/daemon/daemon-conf.c2
-rw-r--r--src/daemon/main.c2
-rw-r--r--src/modules/module-alsa-source.c2
-rw-r--r--src/modules/module-detect.c2
-rw-r--r--src/modules/module-esound-compat-spawnfd.c3
-rw-r--r--src/modules/module-esound-compat-spawnpid.c3
-rw-r--r--src/modules/module-esound-sink.c2
-rw-r--r--src/modules/module-jack-sink.c2
-rw-r--r--src/modules/module-jack-source.c2
-rw-r--r--src/modules/module-match.c2
-rw-r--r--src/modules/module-mmkbd-evdev.c2
-rw-r--r--src/modules/module-oss-mmap.c2
-rw-r--r--src/modules/module-oss.c2
-rw-r--r--src/modules/module-pipe-sink.c2
-rw-r--r--src/modules/module-pipe-source.c2
-rw-r--r--src/modules/module-protocol-stub.c2
-rw-r--r--src/modules/module-volume-restore.c2
-rw-r--r--src/modules/oss-util.c3
-rw-r--r--src/modules/rtp/module-rtp-recv.c2
-rw-r--r--src/modules/rtp/module-rtp-send.c2
-rw-r--r--src/modules/rtp/rtp.c3
-rw-r--r--src/modules/rtp/sap.c2
-rw-r--r--src/polyp/client-conf.c2
-rw-r--r--src/polyp/context.c2
-rw-r--r--src/polyp/error.c214
-rw-r--r--src/polyp/error.h6
-rw-r--r--src/polyp/mainloop-signal.c2
-rw-r--r--src/polyp/mainloop.c2
-rw-r--r--src/polyp/util.c3
-rw-r--r--src/polypcore/authkey.c2
-rw-r--r--src/polypcore/cli-command.c2
-rw-r--r--src/polypcore/conf-parser.c2
-rw-r--r--src/polypcore/core-error.c205
-rw-r--r--src/polypcore/core-error.h41
-rw-r--r--src/polypcore/core-scache.c2
-rw-r--r--src/polypcore/core-util.c2
-rw-r--r--src/polypcore/iochannel.c2
-rw-r--r--src/polypcore/ioline.c2
-rw-r--r--src/polypcore/pid.c2
-rw-r--r--src/polypcore/protocol-esound.c2
-rw-r--r--src/polypcore/protocol-simple.c2
-rw-r--r--src/polypcore/socket-client.c2
-rw-r--r--src/polypcore/socket-server.c2
-rw-r--r--src/polypcore/socket-util.c2
-rw-r--r--src/utils/pacmd.c14
-rw-r--r--src/utils/padsp.c4
48 files changed, 324 insertions, 253 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 16b5e9e3..3a8c9bba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -402,6 +402,7 @@ libpolyp_la_SOURCES += \
polypcore/strbuf.c polypcore/strbuf.h \
polypcore/strlist.c polypcore/strlist.h \
polypcore/tagstruct.c polypcore/tagstruct.h \
+ polypcore/core-error.c polypcore/core-error.h \
polypcore/winsock.h
if OS_IS_WIN32
@@ -574,7 +575,8 @@ libpolypcore_la_SOURCES += \
polypcore/source-output.c polypcore/source-output.h \
polypcore/strbuf.c polypcore/strbuf.h \
polypcore/tokenizer.c polypcore/tokenizer.h \
- polypcore/winsock.h
+ polypcore/winsock.h \
+ polypcore/core-error.c polypcore/core-error.h
if OS_IS_WIN32
libpolypcore_la_SOURCES += \
@@ -1186,3 +1188,5 @@ install-exec-hook:
chmod u+s $(DESTDIR)$(bindir)/polypaudio
ln -sf pacat $(DESTDIR)$(bindir)/parec
rm -f $(DESTDIR)$(modlibexecdir)/*.a
+
+.PHONY: utils/padsp
diff --git a/src/daemon/caps.c b/src/daemon/caps.c
index 4942868c..5e24da82 100644
--- a/src/daemon/caps.c
+++ b/src/daemon/caps.c
@@ -32,7 +32,7 @@
#include <sys/capability.h>
#endif
-#include <polyp/error.h>
+#include <polypcore/core-error.h>
#include <polypcore/log.h>
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 809769f8..2d8d9558 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -29,9 +29,9 @@
#include <assert.h>
#include <unistd.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/strbuf.h>
#include <polypcore/conf-parser.h>
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 2fadd496..b88f932c 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -50,11 +50,11 @@
#include "../polypcore/winsock.h"
-#include <polyp/error.h>
#include <polyp/mainloop.h>
#include <polyp/mainloop-signal.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core.h>
#include <polypcore/memblock.h>
#include <polypcore/module.h>
diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c
index c72b0322..414efda8 100644
--- a/src/modules/module-alsa-source.c
+++ b/src/modules/module-alsa-source.c
@@ -34,9 +34,9 @@
#include <asoundlib.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core.h>
#include <polypcore/module.h>
#include <polypcore/memchunk.h>
diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c
index e4f2e3f9..d0a37733 100644
--- a/src/modules/module-detect.c
+++ b/src/modules/module-detect.c
@@ -33,9 +33,9 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/modargs.h>
#include <polypcore/log.h>
diff --git a/src/modules/module-esound-compat-spawnfd.c b/src/modules/module-esound-compat-spawnfd.c
index f59e9e21..861e2570 100644
--- a/src/modules/module-esound-compat-spawnfd.c
+++ b/src/modules/module-esound-compat-spawnfd.c
@@ -28,8 +28,7 @@
#include <string.h>
#include <errno.h>
-#include <polyp/error.h>
-
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/modargs.h>
#include <polypcore/core-util.h>
diff --git a/src/modules/module-esound-compat-spawnpid.c b/src/modules/module-esound-compat-spawnpid.c
index c14ce12a..7b47bb0a 100644
--- a/src/modules/module-esound-compat-spawnpid.c
+++ b/src/modules/module-esound-compat-spawnpid.c
@@ -28,8 +28,7 @@
#include <errno.h>
#include <signal.h>
-#include <polyp/error.h>
-
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/core-util.h>
#include <polypcore/modargs.h>
diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index 72298679..53a9411a 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -33,9 +33,9 @@
#include <unistd.h>
#include <limits.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/sink.h>
#include <polypcore/module.h>
diff --git a/src/modules/module-jack-sink.c b/src/modules/module-jack-sink.c
index db2ba030..fc2bfc45 100644
--- a/src/modules/module-jack-sink.c
+++ b/src/modules/module-jack-sink.c
@@ -36,9 +36,9 @@
#include <jack/jack.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/sink.h>
#include <polypcore/module.h>
diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c
index 8816fb8a..ca9560a6 100644
--- a/src/modules/module-jack-source.c
+++ b/src/modules/module-jack-source.c
@@ -36,9 +36,9 @@
#include <jack/jack.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/source.h>
#include <polypcore/module.h>
diff --git a/src/modules/module-match.c b/src/modules/module-match.c
index f68f0c61..02d75e7e 100644
--- a/src/modules/module-match.c
+++ b/src/modules/module-match.c
@@ -32,9 +32,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/core-util.h>
#include <polypcore/modargs.h>
diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c
index d6c91e2e..ee2c6bff 100644
--- a/src/modules/module-mmkbd-evdev.c
+++ b/src/modules/module-mmkbd-evdev.c
@@ -33,9 +33,9 @@
#include <linux/input.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/log.h>
#include <polypcore/namereg.h>
diff --git a/src/modules/module-oss-mmap.c b/src/modules/module-oss-mmap.c
index dac7d7f3..5cf6228f 100644
--- a/src/modules/module-oss-mmap.c
+++ b/src/modules/module-oss-mmap.c
@@ -36,9 +36,9 @@
#include <limits.h>
#include <sys/mman.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/sink.h>
#include <polypcore/source.h>
diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c
index 8e217855..88724673 100644
--- a/src/modules/module-oss.c
+++ b/src/modules/module-oss.c
@@ -35,9 +35,9 @@
#include <unistd.h>
#include <limits.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/sink.h>
#include <polypcore/source.h>
diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c
index f0569ce9..01598e38 100644
--- a/src/modules/module-pipe-sink.c
+++ b/src/modules/module-pipe-sink.c
@@ -33,9 +33,9 @@
#include <unistd.h>
#include <limits.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/sink.h>
#include <polypcore/module.h>
diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c
index 77212ce5..be2a28d5 100644
--- a/src/modules/module-pipe-source.c
+++ b/src/modules/module-pipe-source.c
@@ -33,9 +33,9 @@
#include <unistd.h>
#include <limits.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/source.h>
#include <polypcore/module.h>
diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c
index 8eba352b..2b4f303b 100644
--- a/src/modules/module-protocol-stub.c
+++ b/src/modules/module-protocol-stub.c
@@ -42,9 +42,9 @@
#include "../polypcore/winsock.h"
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/socket-server.h>
#include <polypcore/socket-util.h>
diff --git a/src/modules/module-volume-restore.c b/src/modules/module-volume-restore.c
index 796e43a3..435f0c96 100644
--- a/src/modules/module-volume-restore.c
+++ b/src/modules/module-volume-restore.c
@@ -32,9 +32,9 @@
#include <stdlib.h>
#include <ctype.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/core-util.h>
#include <polypcore/modargs.h>
diff --git a/src/modules/oss-util.c b/src/modules/oss-util.c
index 027921c5..ff337a5c 100644
--- a/src/modules/oss-util.c
+++ b/src/modules/oss-util.c
@@ -34,8 +34,7 @@
#include <sys/stat.h>
#include <fcntl.h>
-#include <polyp/error.h>
-
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index 8d9b33c2..c448502e 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -31,10 +31,10 @@
#include <string.h>
#include <unistd.h>
-#include <polyp/error.h>
#include <polyp/timeval.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/llist.h>
#include <polypcore/sink.h>
diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c
index c8b3899a..4359d00d 100644
--- a/src/modules/rtp/module-rtp-send.c
+++ b/src/modules/rtp/module-rtp-send.c
@@ -32,11 +32,11 @@
#include <string.h>
#include <unistd.h>
-#include <polyp/error.h>
#include <polyp/timeval.h>
#include <polyp/util.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/module.h>
#include <polypcore/llist.h>
#include <polypcore/source.h>
diff --git a/src/modules/rtp/rtp.c b/src/modules/rtp/rtp.c
index 012d6578..52a1819c 100644
--- a/src/modules/rtp/rtp.c
+++ b/src/modules/rtp/rtp.c
@@ -36,8 +36,7 @@
#include <sys/filio.h>
#endif
-#include <polyp/error.h>
-
+#include <polypcore/core-error.h>
#include <polypcore/log.h>
#include "rtp.h"
diff --git a/src/modules/rtp/sap.c b/src/modules/rtp/sap.c
index 238ee420..134bab09 100644
--- a/src/modules/rtp/sap.c
+++ b/src/modules/rtp/sap.c
@@ -38,9 +38,9 @@
#include <sys/filio.h>
#endif
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
diff --git a/src/polyp/client-conf.c b/src/polyp/client-conf.c
index 0b3154c8..e1934ce1 100644
--- a/src/polyp/client-conf.c
+++ b/src/polyp/client-conf.c
@@ -29,7 +29,7 @@
#include <errno.h>
#include <string.h>
-#include <polyp/error.h>
+#include <polypcore/core-error.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
diff --git a/src/polyp/context.c b/src/polyp/context.c
index eb563819..68fb4bf3 100644
--- a/src/polyp/context.c
+++ b/src/polyp/context.c
@@ -47,7 +47,7 @@
#include "../polypcore/winsock.h"
-#include <polyp/error.h>
+#include <polypcore/core-error.h>
#include <polyp/version.h>
#include <polyp/xmalloc.h>
diff --git a/src/polyp/error.c b/src/polyp/error.c
index 0e3b506f..27da7eae 100644
--- a/src/polyp/error.c
+++ b/src/polyp/error.c
@@ -28,15 +28,6 @@
#include <stdlib.h>
#include <string.h>
-#ifdef HAVE_PTHREAD
-#include <pthread.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-#endif
-
-#include <polyp/utf8.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-util.h>
@@ -44,191 +35,32 @@
#include "error.h"
-static const char* const errortab[PA_ERR_MAX] = {
- [PA_OK] = "OK",
- [PA_ERR_ACCESS] = "Access denied",
- [PA_ERR_COMMAND] = "Unknown command",
- [PA_ERR_INVALID] = "Invalid argument",
- [PA_ERR_EXIST] = "Entity exists",
- [PA_ERR_NOENTITY] = "No such entity",
- [PA_ERR_CONNECTIONREFUSED] = "Connection refused",
- [PA_ERR_PROTOCOL] = "Protocol error",
- [PA_ERR_TIMEOUT] = "Timeout",
- [PA_ERR_AUTHKEY] = "No authorization key",
- [PA_ERR_INTERNAL] = "Internal error",
- [PA_ERR_CONNECTIONTERMINATED] = "Connection terminated",
- [PA_ERR_KILLED] = "Entity killed",
- [PA_ERR_INVALIDSERVER] = "Invalid server",
- [PA_ERR_MODINITFAILED] = "Module initalization failed",
- [PA_ERR_BADSTATE] = "Bad state",
- [PA_ERR_NODATA] = "No data",
- [PA_ERR_VERSION] = "Incompatible protocol version",
- [PA_ERR_TOOLARGE] = "Too large"
-};
-
const char*pa_strerror(int error) {
+
+ static const char* const errortab[PA_ERR_MAX] = {
+ [PA_OK] = "OK",
+ [PA_ERR_ACCESS] = "Access denied",
+ [PA_ERR_COMMAND] = "Unknown command",
+ [PA_ERR_INVALID] = "Invalid argument",
+ [PA_ERR_EXIST] = "Entity exists",
+ [PA_ERR_NOENTITY] = "No such entity",
+ [PA_ERR_CONNECTIONREFUSED] = "Connection refused",
+ [PA_ERR_PROTOCOL] = "Protocol error",
+ [PA_ERR_TIMEOUT] = "Timeout",
+ [PA_ERR_AUTHKEY] = "No authorization key",
+ [PA_ERR_INTERNAL] = "Internal error",
+ [PA_ERR_CONNECTIONTERMINATED] = "Connection terminated",
+ [PA_ERR_KILLED] = "Entity killed",
+ [PA_ERR_INVALIDSERVER] = "Invalid server",
+ [PA_ERR_MODINITFAILED] = "Module initalization failed",
+ [PA_ERR_BADSTATE] = "Bad state",
+ [PA_ERR_NODATA] = "No data",
+ [PA_ERR_VERSION] = "Incompatible protocol version",
+ [PA_ERR_TOOLARGE] = "Too large"
+ };
+
if (error < 0 || error >= PA_ERR_MAX)
return NULL;
return errortab[error];
}
-
-#ifdef HAVE_PTHREAD
-
-static pthread_once_t cstrerror_once = PTHREAD_ONCE_INIT;
-static pthread_key_t tlsstr_key;
-
-static void inittls(void) {
- int ret;
-
- ret = pthread_key_create(&tlsstr_key, pa_xfree);
- if (ret) {
- fprintf(stderr, __FILE__ ": CRITICAL: Unable to allocate TLS key (%d)\n", errno);
- exit(-1);
- }
-}
-
-#elif HAVE_WINDOWS_H
-
-static DWORD tlsstr_key = TLS_OUT_OF_INDEXES;
-static DWORD monitor_key = TLS_OUT_OF_INDEXES;
-
-static void inittls(void) {
- HANDLE mutex;
- char name[64];
-
- sprintf(name, "polypaudio%d", (int)GetCurrentProcessId());
-
- mutex = CreateMutex(NULL, FALSE, name);
- if (!mutex) {
- fprintf(stderr, __FILE__ ": CRITICAL: Unable to create named mutex (%d)\n", (int)GetLastError());
- exit(-1);
- }
-
- WaitForSingleObject(mutex, INFINITE);
-
- if (tlsstr_key == TLS_OUT_OF_INDEXES) {
- tlsstr_key = TlsAlloc();
- monitor_key = TlsAlloc();
- if ((tlsstr_key == TLS_OUT_OF_INDEXES) || (monitor_key == TLS_OUT_OF_INDEXES)) {
- fprintf(stderr, __FILE__ ": CRITICAL: Unable to allocate TLS key (%d)\n", (int)GetLastError());
- exit(-1);
- }
- }
-
- ReleaseMutex(mutex);
-
- CloseHandle(mutex);
-}
-
-/*
- * This is incredibly brain dead, but this is necessary when dealing with
- * the hell that is Win32.
- */
-struct monitor_data {
- HANDLE thread;
- void *data;
-};
-
-static DWORD WINAPI monitor_thread(LPVOID param) {
- struct monitor_data *data;
-
- data = (struct monitor_data*)param;
- assert(data);
-
- WaitForSingleObject(data->thread, INFINITE);
-
- CloseHandle(data->thread);
- pa_xfree(data->data);
- pa_xfree(data);
-
- return 0;
-}
-
-static void start_monitor(void) {
- HANDLE thread;
- struct monitor_data *data;
-
- data = pa_xnew(struct monitor_data, 1);
- assert(data);
-
- DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
- GetCurrentProcess(), &data->thread, 0, FALSE, DUPLICATE_SAME_ACCESS);
-
- thread = CreateThread(NULL, 0, monitor_thread, data, 0, NULL);
- assert(thread);
-
- TlsSetValue(monitor_key, data);
-
- CloseHandle(thread);
-}
-
-#else
-
-/* Unsafe, but we have no choice */
-static char *tlsstr;
-
-#endif
-
-const char* pa_cstrerror(int errnum) {
- const char *origbuf;
-
-#ifdef HAVE_STRERROR_R
- char errbuf[128];
-#endif
-
-#ifdef HAVE_PTHREAD
- char *tlsstr;
-
- pthread_once(&cstrerror_once, inittls);
-
- tlsstr = pthread_getspecific(tlsstr_key);
-#elif defined(HAVE_WINDOWS_H)
- char *tlsstr;
- struct monitor_data *data;
-
- inittls();
-
- tlsstr = TlsGetValue(tlsstr_key);
- if (!tlsstr)
- start_monitor();
- data = TlsGetValue(monitor_key);
-#endif
-
- if (tlsstr)
- pa_xfree(tlsstr);
-
-#ifdef HAVE_STRERROR_R
-
-#ifdef __GLIBC__
- origbuf = strerror_r(errnum, errbuf, sizeof(errbuf));
- if (origbuf == NULL)
- origbuf = "";
-#else
- if (strerror_r(errnum, errbuf, sizeof(errbuf)) == 0) {
- origbuf = errbuf;
- errbuf[sizeof(errbuf) - 1] = '\0';
- } else
- origbuf = "";
-#endif
-
-#else
- /* This might not be thread safe, but we hope for the best */
- origbuf = strerror(errnum);
-#endif
-
- tlsstr = pa_locale_to_utf8(origbuf);
- if (!tlsstr) {
- fprintf(stderr, "Unable to convert, filtering\n");
- tlsstr = pa_utf8_filter(origbuf);
- }
-
-#ifdef HAVE_PTHREAD
- pthread_setspecific(tlsstr_key, tlsstr);
-#elif defined(HAVE_WINDOWS_H)
- TlsSetValue(tlsstr_key, tlsstr);
- data->data = tlsstr;
-#endif
-
- return tlsstr;
-}
diff --git a/src/polyp/error.h b/src/polyp/error.h
index 1d7b2ca6..9856c1af 100644
--- a/src/polyp/error.h
+++ b/src/polyp/error.h
@@ -33,12 +33,6 @@ PA_C_DECL_BEGIN
/** Return a human readable error message for the specified numeric error code */
const char* pa_strerror(int error);
-/** A wrapper around the standard strerror() function that converts the
- * string to UTF-8. The function is thread safe but the returned string is
- * only guaranteed to exist until the thread exits or pa_cstrerror() is
- * called again from the same thread. */
-const char* pa_cstrerror(int errnum);
-
PA_C_DECL_END
#endif
diff --git a/src/polyp/mainloop-signal.c b/src/polyp/mainloop-signal.c
index c6ad431a..92702814 100644
--- a/src/polyp/mainloop-signal.c
+++ b/src/polyp/mainloop-signal.c
@@ -36,7 +36,7 @@
#include <windows.h>
#endif
-#include <polyp/error.h>
+#include <polypcore/core-error.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-util.h>
diff --git a/src/polyp/mainloop.c b/src/polyp/mainloop.c
index 6088fa4b..61d8b488 100644
--- a/src/polyp/mainloop.c
+++ b/src/polyp/mainloop.c
@@ -44,7 +44,7 @@
#include "../polypcore/pipe.h"
#endif
-#include <polyp/error.h>
+#include <polypcore/core-error.h>
#include <polyp/timeval.h>
#include <polyp/xmalloc.h>
diff --git a/src/polyp/util.c b/src/polyp/util.c
index 91054483..842b9e7f 100644
--- a/src/polyp/util.c
+++ b/src/polyp/util.c
@@ -51,8 +51,7 @@
#include "../polypcore/winsock.h"
-#include <polyp/error.h>
-
+#include <polypcore/core-error.h>
#include <polypcore/log.h>
#include <polypcore/core-util.h>
diff --git a/src/polypcore/authkey.c b/src/polypcore/authkey.c
index 6b462a23..54f4dd86 100644
--- a/src/polypcore/authkey.c
+++ b/src/polypcore/authkey.c
@@ -35,8 +35,8 @@
#include <limits.h>
#include <sys/stat.h>
-#include <polyp/error.h>
#include <polyp/util.h>
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
#include <polypcore/random.h>
diff --git a/src/polypcore/cli-command.c b/src/polypcore/cli-command.c
index 039aa957..e25e464c 100644
--- a/src/polypcore/cli-command.c
+++ b/src/polypcore/cli-command.c
@@ -29,7 +29,6 @@
#include <stdlib.h>
#include <errno.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/module.h>
@@ -50,6 +49,7 @@
#include <polypcore/sound-file-stream.h>
#include <polypcore/props.h>
#include <polypcore/core-util.h>
+#include <polypcore/core-error.h>
#include "cli-command.h"
diff --git a/src/polypcore/conf-parser.c b/src/polypcore/conf-parser.c
index 4bcb83dd..d59bc555 100644
--- a/src/polypcore/conf-parser.c
+++ b/src/polypcore/conf-parser.c
@@ -28,9 +28,9 @@
#include <stdio.h>
#include <errno.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/log.h>
#include <polypcore/core-util.h>
diff --git a/src/polypcore/core-error.c b/src/polypcore/core-error.c
new file mode 100644
index 00000000..f2240a9f
--- /dev/null
+++ b/src/polypcore/core-error.c
@@ -0,0 +1,205 @@
+/* $Id$ */
+
+/***
+ This file is part of polypaudio.
+
+ polypaudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ polypaudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with polypaudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_PTHREAD
+#include <pthread.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+#include <polyp/utf8.h>
+#include <polyp/xmalloc.h>
+
+#include <polypcore/core-util.h>
+#include <polypcore/native-common.h>
+
+#include "core-error.h"
+
+#ifdef HAVE_PTHREAD
+
+static pthread_once_t cstrerror_once = PTHREAD_ONCE_INIT;
+static pthread_key_t tlsstr_key;
+
+static void inittls(void) {
+ int ret;
+
+ ret = pthread_key_create(&tlsstr_key, pa_xfree);
+ if (ret) {
+ fprintf(stderr, __FILE__ ": CRITICAL: Unable to allocate TLS key (%d)\n", errno);
+ exit(-1);
+ }
+}
+
+#elif HAVE_WINDOWS_H
+
+static DWORD tlsstr_key = TLS_OUT_OF_INDEXES;
+static DWORD monitor_key = TLS_OUT_OF_INDEXES;
+
+static void inittls(void) {
+ HANDLE mutex;
+ char name[64];
+
+ sprintf(name, "polypaudio%d", (int)GetCurrentProcessId());
+
+ mutex = CreateMutex(NULL, FALSE, name);
+ if (!mutex) {
+ fprintf(stderr, __FILE__ ": CRITICAL: Unable to create named mutex (%d)\n", (int)GetLastError());
+ exit(-1);
+ }
+
+ WaitForSingleObject(mutex, INFINITE);
+
+ if (tlsstr_key == TLS_OUT_OF_INDEXES) {
+ tlsstr_key = TlsAlloc();
+ monitor_key = TlsAlloc();
+ if ((tlsstr_key == TLS_OUT_OF_INDEXES) || (monitor_key == TLS_OUT_OF_INDEXES)) {
+ fprintf(stderr, __FILE__ ": CRITICAL: Unable to allocate TLS key (%d)\n", (int)GetLastError());
+ exit(-1);
+ }
+ }
+
+ ReleaseMutex(mutex);
+
+ CloseHandle(mutex);
+}
+
+/*
+ * This is incredibly brain dead, but this is necessary when dealing with
+ * the hell that is Win32.
+ */
+struct monitor_data {
+ HANDLE thread;
+ void *data;
+};
+
+static DWORD WINAPI monitor_thread(LPVOID param) {
+ struct monitor_data *data;
+
+ data = (struct monitor_data*)param;
+ assert(data);
+
+ WaitForSingleObject(data->thread, INFINITE);
+
+ CloseHandle(data->thread);
+ pa_xfree(data->data);
+ pa_xfree(data);
+
+ return 0;
+}
+
+static void start_monitor(void) {
+ HANDLE thread;
+ struct monitor_data *data;
+
+ data = pa_xnew(struct monitor_data, 1);
+ assert(data);
+
+ DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
+ GetCurrentProcess(), &data->thread, 0, FALSE, DUPLICATE_SAME_ACCESS);
+
+ thread = CreateThread(NULL, 0, monitor_thread, data, 0, NULL);
+ assert(thread);
+
+ TlsSetValue(monitor_key, data);
+
+ CloseHandle(thread);
+}
+
+#else
+
+/* Unsafe, but we have no choice */
+static char *tlsstr;
+
+#endif
+
+const char* pa_cstrerror(int errnum) {
+ const char *origbuf;
+
+#ifdef HAVE_STRERROR_R
+ char errbuf[128];
+#endif
+
+#ifdef HAVE_PTHREAD
+ char *tlsstr;
+
+ pthread_once(&cstrerror_once, inittls);
+
+ tlsstr = pthread_getspecific(tlsstr_key);
+#elif defined(HAVE_WINDOWS_H)
+ char *tlsstr;
+ struct monitor_data *data;
+
+ inittls();
+
+ tlsstr = TlsGetValue(tlsstr_key);
+ if (!tlsstr)
+ start_monitor();
+ data = TlsGetValue(monitor_key);
+#endif
+
+ if (tlsstr)
+ pa_xfree(tlsstr);
+
+#ifdef HAVE_STRERROR_R
+
+#ifdef __GLIBC__
+ origbuf = strerror_r(errnum, errbuf, sizeof(errbuf));
+ if (origbuf == NULL)
+ origbuf = "";
+#else
+ if (strerror_r(errnum, errbuf, sizeof(errbuf)) == 0) {
+ origbuf = errbuf;
+ errbuf[sizeof(errbuf) - 1] = '\0';
+ } else
+ origbuf = "";
+#endif
+
+#else
+ /* This might not be thread safe, but we hope for the best */
+ origbuf = strerror(errnum);
+#endif
+
+ tlsstr = pa_locale_to_utf8(origbuf);
+ if (!tlsstr) {
+ fprintf(stderr, "Unable to convert, filtering\n");
+ tlsstr = pa_utf8_filter(origbuf);
+ }
+
+#ifdef HAVE_PTHREAD
+ pthread_setspecific(tlsstr_key, tlsstr);
+#elif defined(HAVE_WINDOWS_H)
+ TlsSetValue(tlsstr_key, tlsstr);
+ data->data = tlsstr;
+#endif
+
+ return tlsstr;
+}
diff --git a/src/polypcore/core-error.h b/src/polypcore/core-error.h
new file mode 100644
index 00000000..17595c98
--- /dev/null
+++ b/src/polypcore/core-error.h
@@ -0,0 +1,41 @@
+#ifndef foocoreerrorhfoo
+#define foocoreerrorhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of polypaudio.
+
+ polypaudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ polypaudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with polypaudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <inttypes.h>
+#include <polyp/cdecl.h>
+
+/** \file
+ * Error management */
+
+PA_C_DECL_BEGIN
+
+/** A wrapper around the standard strerror() function that converts the
+ * string to UTF-8. The function is thread safe but the returned string is
+ * only guaranteed to exist until the thread exits or pa_cstrerror() is
+ * called again from the same thread. */
+const char* pa_cstrerror(int errnum);
+
+PA_C_DECL_END
+
+#endif
diff --git a/src/polypcore/core-scache.c b/src/polypcore/core-scache.c
index 1d60a910..b44a7e19 100644
--- a/src/polypcore/core-scache.c
+++ b/src/polypcore/core-scache.c
@@ -41,7 +41,6 @@
#include <windows.h>
#endif
-#include <polyp/error.h>
#include <polyp/mainloop.h>
#include <polyp/channelmap.h>
#include <polyp/timeval.h>
@@ -57,6 +56,7 @@
#include <polypcore/sound-file.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
+#include <polypcore/core-error.h>
#include "core-scache.h"
diff --git a/src/polypcore/core-util.c b/src/polypcore/core-util.c
index bb6a3d85..6cf281c5 100644
--- a/src/polypcore/core-util.c
+++ b/src/polypcore/core-util.c
@@ -69,10 +69,10 @@
#include <samplerate.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polyp/util.h>
+#include <polypcore/core-error.h>
#include <polypcore/winsock.h>
#include <polypcore/log.h>
diff --git a/src/polypcore/iochannel.c b/src/polypcore/iochannel.c
index 8af6a36b..106c413e 100644
--- a/src/polypcore/iochannel.c
+++ b/src/polypcore/iochannel.c
@@ -38,9 +38,9 @@
#include "winsock.h"
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/socket-util.h>
#include <polypcore/log.h>
diff --git a/src/polypcore/ioline.c b/src/polypcore/ioline.c
index 2e0a3e1a..6a2ef338 100644
--- a/src/polypcore/ioline.c
+++ b/src/polypcore/ioline.c
@@ -29,9 +29,9 @@
#include <stdlib.h>
#include <string.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/log.h>
#include "ioline.h"
diff --git a/src/polypcore/pid.c b/src/polypcore/pid.c
index b8f53955..a5c0ef0b 100644
--- a/src/polypcore/pid.c
+++ b/src/polypcore/pid.c
@@ -39,9 +39,9 @@
#include <windows.h>
#endif
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
diff --git a/src/polypcore/protocol-esound.c b/src/polypcore/protocol-esound.c
index d7c9475a..02e140b9 100644
--- a/src/polypcore/protocol-esound.c
+++ b/src/polypcore/protocol-esound.c
@@ -30,7 +30,6 @@
#include <stdlib.h>
#include <limits.h>
-#include <polyp/error.h>
#include <polyp/sample.h>
#include <polyp/timeval.h>
#include <polyp/utf8.h>
@@ -49,6 +48,7 @@
#include <polypcore/namereg.h>
#include <polypcore/log.h>
#include <polypcore/core-util.h>
+#include <polypcore/core-error.h>
#include "endianmacros.h"
diff --git a/src/polypcore/protocol-simple.c b/src/polypcore/protocol-simple.c
index f15f882a..8b319d70 100644
--- a/src/polypcore/protocol-simple.c
+++ b/src/polypcore/protocol-simple.c
@@ -30,7 +30,6 @@
#include <errno.h>
#include <string.h>
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
@@ -39,6 +38,7 @@
#include <polypcore/sample-util.h>
#include <polypcore/namereg.h>
#include <polypcore/log.h>
+#include <polypcore/core-error.h>
#include "protocol-simple.h"
diff --git a/src/polypcore/socket-client.c b/src/polypcore/socket-client.c
index aa885759..fd840ab5 100644
--- a/src/polypcore/socket-client.c
+++ b/src/polypcore/socket-client.c
@@ -54,10 +54,10 @@
#include "winsock.h"
-#include <polyp/error.h>
#include <polyp/timeval.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/socket-util.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
diff --git a/src/polypcore/socket-server.c b/src/polypcore/socket-server.c
index 871fac11..17071ec2 100644
--- a/src/polypcore/socket-server.c
+++ b/src/polypcore/socket-server.c
@@ -64,11 +64,11 @@
#include <polyp/xmalloc.h>
#include <polyp/util.h>
-#include <polyp/error.h>
#include <polypcore/socket-util.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
+#include <polypcore/core-error.h>
#include "socket-server.h"
diff --git a/src/polypcore/socket-util.c b/src/polypcore/socket-util.c
index 06cdc625..aefcb5ef 100644
--- a/src/polypcore/socket-util.c
+++ b/src/polypcore/socket-util.c
@@ -59,9 +59,9 @@
#include "winsock.h"
-#include <polyp/error.h>
#include <polyp/xmalloc.h>
+#include <polypcore/core-error.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
index 351d79da..ad50c77c 100644
--- a/src/utils/pacmd.c
+++ b/src/utils/pacmd.c
@@ -54,7 +54,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
}
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(PF_UNIX, SOCK_STREAM, 0): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": socket(PF_UNIX, SOCK_STREAM, 0): %s", strerror(errno));
goto fail;
}
@@ -66,7 +66,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
int r;
if ((r = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && (errno != ECONNREFUSED && errno != ENOENT)) {
- pa_log(__FILE__": connect(): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": connect(): %s", strerror(errno));
goto fail;
}
@@ -97,7 +97,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
for (;;) {
if (select(FD_SETSIZE, &ifds, &ofds, NULL, NULL) < 0) {
- pa_log(__FILE__": select(): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": select(): %s", strerror(errno));
goto fail;
}
@@ -109,7 +109,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
if (r == 0)
break;
- pa_log(__FILE__": read(): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": read(): %s", strerror(errno));
goto fail;
}
@@ -125,7 +125,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
if (r == 0)
break;
- pa_log(__FILE__": read(): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": read(): %s", strerror(errno));
goto fail;
}
@@ -138,7 +138,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
assert(obuf_length);
if ((r = write(1, obuf + obuf_index, obuf_length)) < 0) {
- pa_log(__FILE__": write(): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": write(): %s", strerror(errno));
goto fail;
}
@@ -152,7 +152,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
assert(ibuf_length);
if ((r = write(fd, ibuf + ibuf_index, ibuf_length)) < 0) {
- pa_log(__FILE__": write(): %s", pa_cstrerror(errno));
+ pa_log(__FILE__": write(): %s", strerror(errno));
goto fail;
}
diff --git a/src/utils/padsp.c b/src/utils/padsp.c
index 5987ec5f..c1cc9c92 100644
--- a/src/utils/padsp.c
+++ b/src/utils/padsp.c
@@ -361,7 +361,7 @@ static void reset_params(fd_info *i) {
i->n_fragments = 0;
}
-static char *client_name(char *buf, size_t n) {
+static const char *client_name(char *buf, size_t n) {
char p[PATH_MAX];
const char *e;
@@ -376,7 +376,7 @@ static char *client_name(char *buf, size_t n) {
return buf;
}
-static char *stream_name(void) {
+static const char *stream_name(void) {
const char *e;
if ((e = getenv("PADSP_STREAM_NAME")))