From 8d12ab9e632420864fa024909c66863de2452987 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Wed, 12 Jan 2011 08:15:44 +0100 Subject: Use setenv instead of putenv In theory putenv could be used to handle freeing of strings yourself, but this was not done in PulseAudio. That leaves no advantages in using putenv. With setenv you're at the mercy of the implementation whether the strings leak, but at least that is better then a certain leak, as it was before. --- src/pulsecore/core-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 4e7d0d71..ec0b338d 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2501,7 +2501,7 @@ void pa_set_env(const char *key, const char *value) { /* This is not thread-safe */ - putenv(pa_sprintf_malloc("%s=%s", key, value)); + setenv(key, value, 1); } void pa_set_env_and_record(const char *key, const char *value) { -- cgit From d6d9fb295d03a411974a148e469465e0f7c59891 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 4 Jan 2011 11:17:53 +0100 Subject: Clean up includes Instead should be included. That file includes poll.h on platform where it is appropriate. Also remove some unnecessary includes. --- src/daemon/main.c | 4 ---- src/modules/bluetooth/module-bluetooth-device.c | 3 +-- src/modules/module-esound-sink.c | 3 ++- src/modules/module-pipe-sink.c | 2 +- src/modules/module-pipe-source.c | 2 +- src/modules/module-sine-source.c | 2 -- src/modules/oss/module-oss.c | 2 +- src/modules/rtp/module-rtp-recv.c | 2 +- src/pulse/thread-mainloop.c | 7 +------ src/pulsecore/lock-autospawn.c | 1 - 10 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/daemon/main.c b/src/daemon/main.c index cad6f70d..0db794bc 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -43,10 +43,6 @@ #include #endif -#ifdef HAVE_SYS_IOCTL_H -#include -#endif - #ifdef HAVE_PWD_H #include #endif diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 6d31c1eb..dc09ffca 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -25,8 +25,6 @@ #include #include -#include -#include #include #include @@ -44,6 +42,7 @@ #include #include #include +#include #include #include #include diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index 02541e62..0d04fff7 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -60,6 +59,8 @@ #include #include #include +#include +#include #include "module-esound-sink-symdef.h" diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c index e26cbf64..4ed91aae 100644 --- a/src/modules/module-pipe-sink.c +++ b/src/modules/module-pipe-sink.c @@ -32,7 +32,6 @@ #include #include #include -#include #ifdef HAVE_SYS_FILIO_H #include @@ -49,6 +48,7 @@ #include #include #include +#include #include "module-pipe-sink-symdef.h" diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c index 1a6607df..c50536ef 100644 --- a/src/modules/module-pipe-source.c +++ b/src/modules/module-pipe-source.c @@ -32,7 +32,6 @@ #include #include #include -#include #ifdef HAVE_SYS_FILIO_H #include @@ -49,6 +48,7 @@ #include #include #include +#include #include "module-pipe-source-symdef.h" diff --git a/src/modules/module-sine-source.c b/src/modules/module-sine-source.c index c66099c0..955834f1 100644 --- a/src/modules/module-sine-source.c +++ b/src/modules/module-sine-source.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -47,7 +46,6 @@ #include #include #include -#include #include "module-sine-source-symdef.h" diff --git a/src/modules/oss/module-oss.c b/src/modules/oss/module-oss.c index ba9b99e0..c9dc4e7a 100644 --- a/src/modules/oss/module-oss.c +++ b/src/modules/oss/module-oss.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include @@ -70,6 +69,7 @@ #include #include #include +#include #if defined(__NetBSD__) && !defined(SNDCTL_DSP_GETODELAY) #include diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c index b59519fb..a920e66e 100644 --- a/src/modules/rtp/module-rtp-recv.c +++ b/src/modules/rtp/module-rtp-recv.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -54,6 +53,7 @@ #include #include #include +#include #include "module-rtp-recv-symdef.h" diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c index c3cf49c4..d8c82c8c 100644 --- a/src/pulse/thread-mainloop.c +++ b/src/pulse/thread-mainloop.c @@ -31,12 +31,6 @@ #include #include -#ifdef HAVE_POLL_H -#include -#else -#include -#endif - #include #include #include @@ -46,6 +40,7 @@ #include #include #include +#include #include "thread-mainloop.h" diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c index 422f5eb2..b5150573 100644 --- a/src/pulsecore/lock-autospawn.c +++ b/src/pulsecore/lock-autospawn.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include -- cgit From 4f1d4044f8409ff29eeb7f97324daba496e40714 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 4 Jan 2011 17:03:13 +0100 Subject: Use instead of The check whether POSIX socket.h or WIN32 winsock2.h must be included can be made centrally. The downside is that some functionality of e.g. arpa/inet.h is also implemented in winsock.h, so that some files that don't use socket functions, but do use inet.h functions, must also include pulsecore/socket.h. (as well as arpa/inet.h) --- src/Makefile.am | 2 +- src/daemon/main.c | 2 +- src/modules/module-esound-sink.c | 2 +- src/modules/module-protocol-stub.c | 5 +---- src/pulse/context.c | 6 +----- src/pulse/mainloop.c | 2 +- src/pulse/timeval.c | 1 - src/pulse/util.c | 16 ++++++---------- src/pulsecore/core-util.c | 3 +-- src/pulsecore/core-util.h | 2 +- src/pulsecore/creds.h | 4 +--- src/pulsecore/inet_ntop.c | 6 +----- src/pulsecore/inet_ntop.h | 6 +----- src/pulsecore/inet_pton.c | 6 +----- src/pulsecore/inet_pton.h | 6 +----- src/pulsecore/iochannel.c | 7 ++----- src/pulsecore/ioline.c | 2 +- src/pulsecore/ipacl.c | 7 ++----- src/pulsecore/parseaddr.c | 4 +++- src/pulsecore/pipe.c | 6 +----- src/pulsecore/poll.c | 11 +++++------ src/pulsecore/pstream.c | 6 +----- src/pulsecore/rtpoll.c | 1 - src/pulsecore/socket-client.c | 7 ++----- src/pulsecore/socket-server.c | 11 +++-------- src/pulsecore/socket-util.c | 8 ++------ src/pulsecore/socket-util.h | 2 +- src/pulsecore/socket.h | 31 +++++++++++++++++++++++++++++++ src/pulsecore/tagstruct.c | 2 +- src/pulsecore/winsock.h | 26 -------------------------- src/tests/ipacl-test.c | 8 ++------ 31 files changed, 76 insertions(+), 132 deletions(-) create mode 100644 src/pulsecore/socket.h delete mode 100644 src/pulsecore/winsock.h diff --git a/src/Makefile.am b/src/Makefile.am index 0687e409..baba9c5e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -617,7 +617,7 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \ pulsecore/tokenizer.c pulsecore/tokenizer.h \ pulsecore/usergroup.c pulsecore/usergroup.h \ pulsecore/sndfile-util.c pulsecore/sndfile-util.h \ - pulsecore/winsock.h + pulsecore/socket.h libpulsecommon_@PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSNDFILE_CFLAGS) libpulsecommon_@PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version diff --git a/src/daemon/main.c b/src/daemon/main.c index 0db794bc..de809b1b 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -70,7 +70,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index 0d04fff7..9eba8ac3 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -44,6 +43,7 @@ #include #include +#include #include #include #include diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c index e21186bb..7ba54054 100644 --- a/src/modules/module-protocol-stub.c +++ b/src/modules/module-protocol-stub.c @@ -30,9 +30,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -42,9 +39,9 @@ #include -#include #include #include +#include #include #include #include diff --git a/src/pulse/context.c b/src/pulse/context.c index 7a539b4d..ca816507 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -39,9 +39,6 @@ #include #endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -57,9 +54,7 @@ #include #include -#include #include - #include #include #include @@ -69,6 +64,7 @@ #include #include #include +#include #include #include #include diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c index 8f743ec7..8c261381 100644 --- a/src/pulse/mainloop.c +++ b/src/pulse/mainloop.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include "mainloop.h" diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c index cde4417c..c4a08419 100644 --- a/src/pulse/timeval.c +++ b/src/pulse/timeval.c @@ -31,7 +31,6 @@ #include #endif -#include #include #include diff --git a/src/pulse/util.c b/src/pulse/util.c index ca766dab..3206e94c 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -37,10 +37,6 @@ #include #endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - #ifdef HAVE_NETDB_H #include #endif @@ -56,7 +52,7 @@ #include #include -#include +#include #include #include #include @@ -195,11 +191,11 @@ char *pa_get_binary_name(char *s, size_t l) { { char *rp; - if ((rp = pa_readlink("/proc/curproc/file"))) { - pa_strlcpy(s, pa_path_get_filename(rp), l); - pa_xfree(rp); - return s; - } + if ((rp = pa_readlink("/proc/curproc/file"))) { + pa_strlcpy(s, pa_path_get_filename(rp), l); + pa_xfree(rp); + return s; + } } #endif diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index ec0b338d..3ce5edbf 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -43,7 +43,6 @@ #include #include #include -#include #ifdef HAVE_STRTOF_L #include @@ -110,7 +109,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 0d63cfcb..8619330d 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -28,7 +28,6 @@ #include #include #include -#include #ifdef HAVE_SYS_RESOURCE_H #include @@ -36,6 +35,7 @@ #include #include +#include #ifndef PACKAGE #error "Please include config.h before including this file!" diff --git a/src/pulsecore/creds.h b/src/pulsecore/creds.h index c15c469b..9e6fb124 100644 --- a/src/pulsecore/creds.h +++ b/src/pulsecore/creds.h @@ -28,9 +28,7 @@ #error "Please include config.h before including this file!" #endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif +#include #ifdef HAVE_SYS_UN_H #include diff --git a/src/pulsecore/inet_ntop.c b/src/pulsecore/inet_ntop.c index 012a1a05..e283a670 100644 --- a/src/pulsecore/inet_ntop.c +++ b/src/pulsecore/inet_ntop.c @@ -28,11 +28,7 @@ #ifndef HAVE_INET_NTOP -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#include "winsock.h" +#include #include "inet_ntop.h" diff --git a/src/pulsecore/inet_ntop.h b/src/pulsecore/inet_ntop.h index 7fb67b44..7e1b2037 100644 --- a/src/pulsecore/inet_ntop.h +++ b/src/pulsecore/inet_ntop.h @@ -1,11 +1,7 @@ #ifndef fooinet_ntophfoo #define fooinet_ntophfoo -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#include "winsock.h" +#include const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); diff --git a/src/pulsecore/inet_pton.c b/src/pulsecore/inet_pton.c index abdfa467..198d1a0d 100644 --- a/src/pulsecore/inet_pton.c +++ b/src/pulsecore/inet_pton.c @@ -28,11 +28,7 @@ #ifndef HAVE_INET_PTON -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#include "winsock.h" +#include #include "inet_pton.h" diff --git a/src/pulsecore/inet_pton.h b/src/pulsecore/inet_pton.h index 111b4a07..9d9c476a 100644 --- a/src/pulsecore/inet_pton.h +++ b/src/pulsecore/inet_pton.h @@ -1,11 +1,7 @@ #ifndef fooinet_ptonhfoo #define fooinet_ptonhfoo -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#include "winsock.h" +#include int inet_pton(int af, const char *src, void *dst); diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c index f85c9896..f89b0670 100644 --- a/src/pulsecore/iochannel.c +++ b/src/pulsecore/iochannel.c @@ -28,19 +28,16 @@ #include #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif + #ifdef HAVE_SYS_UN_H #include #endif -#include "winsock.h" - #include #include #include +#include #include #include #include diff --git a/src/pulsecore/ioline.c b/src/pulsecore/ioline.c index 7afdb08c..963f7d22 100644 --- a/src/pulsecore/ioline.c +++ b/src/pulsecore/ioline.c @@ -30,7 +30,7 @@ #include -#include +#include #include #include #include diff --git a/src/pulsecore/ipacl.c b/src/pulsecore/ipacl.c index 312e0403..0cbe34af 100644 --- a/src/pulsecore/ipacl.c +++ b/src/pulsecore/ipacl.c @@ -28,9 +28,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_NETINET_IN_H #include #endif @@ -50,10 +47,10 @@ #include #include #include -#include +#include #ifndef HAVE_INET_PTON -#include "inet_pton.h" +#include #endif #include "ipacl.h" diff --git a/src/pulsecore/parseaddr.c b/src/pulsecore/parseaddr.c index 44cd9a05..7f6cd903 100644 --- a/src/pulsecore/parseaddr.c +++ b/src/pulsecore/parseaddr.c @@ -25,8 +25,10 @@ #include #include + +#ifdef HAVE_ARPA_INET_H #include -#include +#endif #include #include diff --git a/src/pulsecore/pipe.c b/src/pulsecore/pipe.c index c21e4b1f..db8e16f8 100644 --- a/src/pulsecore/pipe.c +++ b/src/pulsecore/pipe.c @@ -29,11 +29,7 @@ #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#include "winsock.h" +#include #include "pipe.h" diff --git a/src/pulsecore/poll.c b/src/pulsecore/poll.c index b98fb169..b993c478 100644 --- a/src/pulsecore/poll.c +++ b/src/pulsecore/poll.c @@ -45,8 +45,7 @@ #include #endif -#include "winsock.h" - +#include #include #include @@ -187,11 +186,11 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) { * connected socket, a server socket, or something else using a * 0-byte recv, and use ioctl(2) to detect POLLHUP. */ r = recv(f->fd, NULL, 0, MSG_PEEK); - if (r == 0 || (r < 0 && errno == ENOTSOCK)) - ioctl(f->fd, FIONREAD, &r); + if (r == 0 || (r < 0 && errno == ENOTSOCK)) + ioctl(f->fd, FIONREAD, &r); - if (r == 0) - f->revents |= POLLHUP; + if (r == 0) + f->revents |= POLLHUP; #else /* !OS_IS_DARWIN */ if (recv (f->fd, data, 64, MSG_PEEK) == -1) { if (errno == ESHUTDOWN || errno == ECONNRESET || diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c index 3e0bfa3b..369e22ca 100644 --- a/src/pulsecore/pstream.c +++ b/src/pulsecore/pstream.c @@ -28,9 +28,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -38,10 +35,9 @@ #include #endif - #include -#include +#include #include #include #include diff --git a/src/pulsecore/rtpoll.c b/src/pulsecore/rtpoll.c index 2ef78736..98d7d625 100644 --- a/src/pulsecore/rtpoll.c +++ b/src/pulsecore/rtpoll.c @@ -40,7 +40,6 @@ #include #include #include -#include #include #include diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c index 7c449bee..31acfd2d 100644 --- a/src/pulsecore/socket-client.c +++ b/src/pulsecore/socket-client.c @@ -32,9 +32,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -56,9 +53,9 @@ #include #include -#include -#include +#include #include +#include #include #include #include diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c index 3b7c6973..e45ded04 100644 --- a/src/pulsecore/socket-server.c +++ b/src/pulsecore/socket-server.c @@ -32,9 +32,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_SYS_UN_H #include #ifndef SUN_LEN @@ -54,18 +51,16 @@ #endif #ifndef HAVE_INET_NTOP -#include "inet_ntop.h" +#include #endif - #ifndef HAVE_INET_PTON -#include "inet_pton.h" +#include #endif -#include "winsock.h" - #include #include +#include #include #include #include diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c index 2cc9882a..0b16e0f9 100644 --- a/src/pulsecore/socket-util.c +++ b/src/pulsecore/socket-util.c @@ -36,9 +36,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -62,17 +59,16 @@ #endif #ifndef HAVE_INET_NTOP -#include "inet_ntop.h" +#include #endif -#include "winsock.h" - #include #include #include #include #include +#include #include "socket-util.h" diff --git a/src/pulsecore/socket-util.h b/src/pulsecore/socket-util.h index f6d16376..154afd4a 100644 --- a/src/pulsecore/socket-util.h +++ b/src/pulsecore/socket-util.h @@ -24,8 +24,8 @@ ***/ #include -#include +#include #include void pa_socket_peer_to_string(int fd, char *c, size_t l); diff --git a/src/pulsecore/socket.h b/src/pulsecore/socket.h new file mode 100644 index 00000000..0d38bee6 --- /dev/null +++ b/src/pulsecore/socket.h @@ -0,0 +1,31 @@ +#ifndef foopulsecoresockethfoo +#define foopulsecoresockethfoo + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#ifdef HAVE_WINSOCK2_H +#include + +#define ESHUTDOWN WSAESHUTDOWN +#define ECONNRESET WSAECONNRESET +#define ECONNABORTED WSAECONNABORTED +#define ENETRESET WSAENETRESET +#define EINPROGRESS WSAEINPROGRESS +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define ETIMEDOUT WSAETIMEDOUT +#define ECONNREFUSED WSAECONNREFUSED +#define EHOSTUNREACH WSAEHOSTUNREACH +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EADDRINUSE WSAEADDRINUSE + +typedef long suseconds_t; + +#endif + +#ifdef HAVE_WS2TCPIP_H +#include +#endif + +#endif diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c index 330b7596..804b9f90 100644 --- a/src/pulsecore/tagstruct.c +++ b/src/pulsecore/tagstruct.c @@ -35,7 +35,7 @@ #include -#include +#include #include #include "tagstruct.h" diff --git a/src/pulsecore/winsock.h b/src/pulsecore/winsock.h deleted file mode 100644 index 0352bf4d..00000000 --- a/src/pulsecore/winsock.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef foowinsockhfoo -#define foowinsockhfoo - -#ifdef HAVE_WINSOCK2_H -#include - -#define ESHUTDOWN WSAESHUTDOWN -#define ECONNRESET WSAECONNRESET -#define ECONNABORTED WSAECONNABORTED -#define ENETRESET WSAENETRESET -#define EINPROGRESS WSAEINPROGRESS -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#define ETIMEDOUT WSAETIMEDOUT -#define ECONNREFUSED WSAECONNREFUSED -#define EHOSTUNREACH WSAEHOSTUNREACH -#define EWOULDBLOCK WSAEWOULDBLOCK - -typedef long suseconds_t; - -#endif - -#ifdef HAVE_WS2TCPIP_H -#include -#endif - -#endif diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index 57b70685..88bd6c6f 100644 --- a/src/tests/ipacl-test.c +++ b/src/tests/ipacl-test.c @@ -8,9 +8,6 @@ #include #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif #ifdef HAVE_NETINET_IN_H #include #endif @@ -24,9 +21,8 @@ #include #endif -#include "../pulsecore/winsock.h" -#include "../pulsecore/macro.h" - +#include +#include #include int main(int argc, char *argv[]) { -- cgit From 0ac0479534d9cb6e4ef734eeb3a663f33a4f8ef3 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 4 Jan 2011 17:07:50 +0100 Subject: Adapt win32 specific code to current API --- src/daemon/main.c | 4 ++-- src/pulsecore/mutex-win32.c | 25 ++++++++++++++++++++++++- src/pulsecore/thread-win32.c | 5 +++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/daemon/main.c b/src/daemon/main.c index de809b1b..cab275f3 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -133,7 +133,7 @@ static void message_cb(pa_mainloop_api*a, pa_time_event*e, const struct timeval } pa_timeval_add(pa_gettimeofday(&tvnext), 100000); - a->rtclock_time_restart(e, &tvnext); + a->time_restart(e, &tvnext); } #endif @@ -980,7 +980,7 @@ int main(int argc, char *argv[]) { #endif #ifdef OS_IS_WIN32 - win32_timer = pa_mainloop_get_api(mainloop)->rtclock_time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL); + win32_timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL); #endif if (!conf->no_cpu_limit) diff --git a/src/pulsecore/mutex-win32.c b/src/pulsecore/mutex-win32.c index 3a910b03..f4652a90 100644 --- a/src/pulsecore/mutex-win32.c +++ b/src/pulsecore/mutex-win32.c @@ -91,7 +91,7 @@ void pa_cond_signal(pa_cond *c, int broadcast) { return; if (broadcast) - SetEvent(pa_hashmap_get_first(c->wait_events)); + SetEvent(pa_hashmap_first(c->wait_events)); else { void *iter; const void *key; @@ -131,3 +131,26 @@ int pa_cond_wait(pa_cond *c, pa_mutex *m) { return 0; } + +/* This is a copy of the function in mutex-posix.c */ +pa_mutex* pa_static_mutex_get(pa_static_mutex *s, pa_bool_t recursive, pa_bool_t inherit_priority) { + pa_mutex *m; + + pa_assert(s); + + /* First, check if already initialized and short cut */ + if ((m = pa_atomic_ptr_load(&s->ptr))) + return m; + + /* OK, not initialized, so let's allocate, and fill in */ + m = pa_mutex_new(recursive, inherit_priority); + if ((pa_atomic_ptr_cmpxchg(&s->ptr, NULL, m))) + return m; + + pa_mutex_free(m); + + /* Him, filling in failed, so someone else must have filled in + * already */ + pa_assert_se(m = pa_atomic_ptr_load(&s->ptr)); + return m; +} diff --git a/src/pulsecore/thread-win32.c b/src/pulsecore/thread-win32.c index 0a1baa54..7d458b97 100644 --- a/src/pulsecore/thread-win32.c +++ b/src/pulsecore/thread-win32.c @@ -71,8 +71,9 @@ static DWORD WINAPI internal_thread_func(LPVOID param) { return 0; } -pa_thread* pa_thread_new(pa_thread_func_t thread_func, void *userdata) { +pa_thread* pa_thread_new(const char *name, pa_thread_func_t thread_func, void *userdata) { pa_thread *t; + DWORD thread_id; assert(thread_func); @@ -80,7 +81,7 @@ pa_thread* pa_thread_new(pa_thread_func_t thread_func, void *userdata) { t->thread_func = thread_func; t->userdata = userdata; - t->thread = CreateThread(NULL, 0, internal_thread_func, t, 0, NULL); + t->thread = CreateThread(NULL, 0, internal_thread_func, t, 0, &thread_id); if (!t->thread) { pa_xfree(t); -- cgit From bb12ff83564d43566089dd979639c6993ba76665 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 6 Jan 2011 00:51:33 +0100 Subject: Apply #ifdefs around functionality not available on win32 And also the reverse: around some win32 specific functionality --- configure.ac | 3 ++- src/daemon/daemon-conf.c | 5 ++++ src/daemon/dumpmodules.c | 2 ++ src/daemon/ltdl-bind-now.c | 4 ++++ src/daemon/main.c | 2 ++ src/modules/module-augment-properties.c | 2 ++ src/modules/module-cli.c | 6 ++++- src/modules/module-esound-sink.c | 9 ++++++++ src/pulse/context.c | 6 +++++ src/pulse/util.c | 14 +++++++---- src/pulsecore/core-rtclock.c | 2 ++ src/pulsecore/core-rtclock.h | 2 ++ src/pulsecore/core-util.c | 41 +++++++++++++++++++++++++++++++-- src/pulsecore/inet_ntop.h | 4 ++++ src/pulsecore/inet_pton.h | 4 ++++ src/pulsecore/lock-autospawn.c | 6 +++++ src/pulsecore/memtrap.c | 7 ++++++ src/pulsecore/start-child.c | 2 ++ src/pulsecore/thread.h | 2 +- src/tests/rtstutter.c | 10 +++++--- 20 files changed, 120 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 08c947a7..42d9c3bf 100644 --- a/configure.ac +++ b/configure.ac @@ -390,6 +390,7 @@ AC_CHECK_HEADERS_ONCE([byteswap.h]) AC_CHECK_HEADERS_ONCE([sys/syscall.h]) AC_CHECK_HEADERS_ONCE([sys/eventfd.h]) AC_CHECK_HEADERS_ONCE([execinfo.h]) +AC_CHECK_HEADERS_ONCE([langinfo.h]) #### Typdefs, structures, etc. #### @@ -470,7 +471,7 @@ AC_FUNC_SELECT_ARGTYPES AC_CHECK_FUNCS_ONCE([chmod chown fstat fchown fchmod clock_gettime getaddrinfo getgrgid_r getgrnam_r \ getpwnam_r getpwuid_r gettimeofday getuid inet_ntop inet_pton mlock nanosleep \ pipe posix_fadvise posix_madvise posix_memalign setpgid setsid shm_open \ - sigaction sleep sysconf pthread_setaffinity_np]) + sigaction sleep symlink sysconf uname pthread_setaffinity_np]) AC_CHECK_FUNCS([mkfifo], [HAVE_MKFIFO=1], [HAVE_MKFIFO=0]) AM_CONDITIONAL(HAVE_MKFIFO, test "x$HAVE_MKFIFO" = "x1") diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 74e81351..3339f3b0 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -28,7 +28,10 @@ #include #include #include + +#ifdef HAVE_SCHED_H #include +#endif #include #include @@ -460,10 +463,12 @@ static int parse_rtprio(const char *filename, unsigned line, const char *section pa_assert(rvalue); pa_assert(data); +#ifdef HAVE_SCHED_H if (pa_atoi(rvalue, &rtprio) < 0 || rtprio < sched_get_priority_min(SCHED_FIFO) || rtprio > sched_get_priority_max(SCHED_FIFO)) { pa_log("[%s:%u] Invalid realtime priority '%s'.", filename, line, rvalue); return -1; } +#endif c->realtime_priority = (int) rtprio; return 0; diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index 92470b49..d0504dc5 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -90,7 +90,9 @@ static void show_info(const char *name, const char *path, void (*info)(const cha } } +#ifndef OS_IS_WIN32 extern const lt_dlsymlist lt_preloaded_symbols[]; +#endif static int is_preloaded(const char *name) { const lt_dlsymlist *l; diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c index 276b2a06..2ba73ce7 100644 --- a/src/daemon/ltdl-bind-now.c +++ b/src/daemon/ltdl-bind-now.c @@ -51,6 +51,10 @@ #undef PA_BIND_NOW #endif +#ifdef OS_IS_WIN32 +#undef PA_BIND_NOW +#endif + #ifdef PA_BIND_NOW /* diff --git a/src/daemon/main.c b/src/daemon/main.c index cab275f3..5aeb9bc6 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -654,6 +654,7 @@ int main(int argc, char *argv[]) { goto finish; } +#ifdef HAVE_GETUID if (getuid() == 0 && !conf->system_instance) pa_log_warn(_("This program is not intended to be run as root (unless --system is specified).")); #ifndef HAVE_DBUS /* A similar, only a notice worthy check was done earlier, if D-Bus is enabled. */ @@ -662,6 +663,7 @@ int main(int argc, char *argv[]) { goto finish; } #endif +#endif /* HAVE_GETUID */ if (conf->cmd == PA_CMD_START && conf->system_instance) { pa_log(_("--start not supported for system instances.")); diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c index 30df69d8..bdeee291 100644 --- a/src/modules/module-augment-properties.c +++ b/src/modules/module-augment-properties.c @@ -180,6 +180,7 @@ static void update_rule(struct rule *r) { DIR *desktopfiles_dir; struct dirent *dir; +#ifdef DT_DIR /* Let's try a more aggressive search, but only one level */ if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) { while ((dir = readdir(desktopfiles_dir))) { @@ -200,6 +201,7 @@ static void update_rule(struct rule *r) { } closedir(desktopfiles_dir); } +#endif } if (!found) { r->good = FALSE; diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c index c5ff4564..90ce3b63 100644 --- a/src/modules/module-cli.c +++ b/src/modules/module-cli.c @@ -105,10 +105,14 @@ int pa__init(pa_module*m) { * of log messages, particularly because if stdout and stderr are * dup'ed they share the same O_NDELAY, too. */ +#ifndef OS_IS_WIN32 if ((fd = pa_open_cloexec("/dev/tty", O_RDWR|O_NONBLOCK, 0)) >= 0) { io = pa_iochannel_new(m->core->mainloop, fd, fd); pa_log_debug("Managed to open /dev/tty."); - } else { + } + else +#endif + { io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO); pa_iochannel_set_noclose(io, TRUE); pa_log_debug("Failed to open /dev/tty, using stdin/stdout fds instead."); diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index 9eba8ac3..5a1391d7 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -31,9 +31,18 @@ #include #include #include + +#ifdef HAVE_NETINET_IN_H #include +#endif + +#ifdef HAVE_NETINET_TCP_H #include +#endif + +#ifdef HAVE_SYS_IOCTL_H #include +#endif #ifdef HAVE_LINUX_SOCKIOS_H #include diff --git a/src/pulse/context.c b/src/pulse/context.c index ca816507..8f632b5d 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -585,10 +585,12 @@ static char *get_old_legacy_runtime_dir(void) { return NULL; } +#ifdef HAVE_GETUID if (st.st_uid != getuid()) { pa_xfree(p); return NULL; } +#endif return p; } @@ -607,10 +609,12 @@ static char *get_very_old_legacy_runtime_dir(void) { return NULL; } +#ifdef HAVE_GETUID if (st.st_uid != getuid()) { pa_xfree(p); return NULL; } +#endif return p; } @@ -997,6 +1001,7 @@ int pa_context_connect( /* Set up autospawning */ if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) { +#ifdef HAVE_GETUID if (getuid() == 0) pa_log_debug("Not doing autospawn since we are root."); else { @@ -1005,6 +1010,7 @@ int pa_context_connect( if (api) c->spawn_api = *api; } +#endif } pa_context_set_state(c, PA_CONTEXT_CONNECTING); diff --git a/src/pulse/util.c b/src/pulse/util.c index 3206e94c..c5cfc8ca 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -75,11 +75,15 @@ char *pa_get_user_name(char *s, size_t l) { pa_assert(s); pa_assert(l > 0); - if ((p = (getuid() == 0 ? "root" : NULL)) || - (p = getenv("USER")) || - (p = getenv("LOGNAME")) || - (p = getenv("USERNAME"))) - { + p = NULL; +#ifdef HAVE_GETUID + p = getuid() == 0 ? "root" : NULL; +#endif + if (!p) p = getenv("USER"); + if (!p) p = getenv("LOGNAME"); + if (!p) p = getenv("USERNAME"); + + if (p) { name = pa_strlcpy(s, p, l); } else { #ifdef HAVE_PWD_H diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c index 110158ba..a69b466f 100644 --- a/src/pulsecore/core-rtclock.c +++ b/src/pulsecore/core-rtclock.c @@ -174,6 +174,7 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) { return tv; } +#ifdef HAVE_CLOCK_GETTIME pa_usec_t pa_timespec_load(const struct timespec *ts) { if (PA_UNLIKELY(!ts)) @@ -198,6 +199,7 @@ struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v) { return ts; } +#endif static struct timeval* wallclock_from_rtclock(struct timeval *tv) { diff --git a/src/pulsecore/core-rtclock.h b/src/pulsecore/core-rtclock.h index 3b393ed5..62535368 100644 --- a/src/pulsecore/core-rtclock.h +++ b/src/pulsecore/core-rtclock.h @@ -43,8 +43,10 @@ void pa_rtclock_hrtimer_enable(void); struct timeval* pa_rtclock_from_wallclock(struct timeval *tv); +#ifdef HAVE_CLOCK_GETTIME pa_usec_t pa_timespec_load(const struct timespec *ts); struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v); +#endif struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock); diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 3ce5edbf..4c4fbfe0 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -41,8 +41,14 @@ #include #include #include + +#ifdef HAVE_LANGINFO_H #include +#endif + +#ifdef HAVE_UNAME #include +#endif #ifdef HAVE_STRTOF_L #include @@ -216,7 +222,7 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) { if (r < 0 && errno != EEXIST) return -1; -#ifdef HAVE_FSTAT +#if defined(HAVE_FSTAT) && !defined(OS_IS_WIN32) if ((fd = open(dir, #ifdef O_CLOEXEC O_CLOEXEC| @@ -254,7 +260,6 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) { #endif pa_assert_se(pa_close(fd) >= 0); - #endif #ifdef HAVE_LSTAT @@ -610,6 +615,7 @@ char *pa_strlcpy(char *b, const char *s, size_t l) { } static int set_scheduler(int rtprio) { +#ifdef HAVE_SCHED_H struct sched_param sp; #ifdef HAVE_DBUS int r; @@ -633,6 +639,7 @@ static int set_scheduler(int rtprio) { pa_log_debug("SCHED_RR worked."); return 0; } +#endif /* HAVE_SCHED_H */ #ifdef HAVE_DBUS /* Try to talk to RealtimeKit */ @@ -702,10 +709,12 @@ static int set_nice(int nice_level) { dbus_error_init(&error); #endif +#ifdef HAVE_SYS_RESOURCE_H if (setpriority(PRIO_PROCESS, 0, nice_level) >= 0) { pa_log_debug("setpriority() worked."); return 0; } +#endif #ifdef HAVE_DBUS /* Try to talk to RealtimeKit */ @@ -826,6 +835,7 @@ int pa_parse_boolean(const char *v) { else if (!strcmp(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off")) return 0; +#ifdef HAVE_LANGINFO_H /* And then we check language dependant */ if ((expr = nl_langinfo(YESEXPR))) if (expr[0]) @@ -836,6 +846,7 @@ int pa_parse_boolean(const char *v) { if (expr[0]) if (pa_match(expr, v) > 0) return 0; +#endif errno = EINVAL; return -1; @@ -1338,11 +1349,13 @@ static char *get_pulse_home(void) { goto finish; } +#ifdef HAVE_GETUID if (st.st_uid != getuid()) { pa_log_error("Home directory %s not ours.", h); errno = EACCES; goto finish; } +#endif ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h); @@ -1440,7 +1453,11 @@ static char* make_random_dir(mode_t m) { fn[i] = table[rand() % (sizeof(table)-1)]; u = umask((~m) & 0777); +#ifndef OS_IS_WIN32 r = mkdir(fn, m); +#else + r = mkdir(fn); +#endif saved_errno = errno; umask(u); @@ -1463,6 +1480,7 @@ static int make_random_dir_and_link(mode_t m, const char *k) { if (!(p = make_random_dir(m))) return -1; +#ifdef HAVE_SYMLINK if (symlink(p, k) < 0) { int saved_errno = errno; @@ -1475,6 +1493,7 @@ static int make_random_dir_and_link(mode_t m, const char *k) { errno = saved_errno; return -1; } +#endif pa_xfree(p); return 0; @@ -1559,6 +1578,7 @@ char *pa_get_runtime_dir(void) { /* Hmm, so this symlink is still around, make sure nobody fools * us */ +#ifdef HAVE_LSTAT if (lstat(p, &st) < 0) { if (errno != ENOENT) { @@ -1578,6 +1598,7 @@ char *pa_get_runtime_dir(void) { pa_log_info("Hmm, runtime path exists, but points to an invalid directory. Changing runtime directory."); } +#endif pa_xfree(p); p = NULL; @@ -2217,6 +2238,7 @@ void pa_close_pipe(int fds[2]) { } char *pa_readlink(const char *p) { +#ifdef HAVE_READLINK size_t l = 100; for (;;) { @@ -2238,6 +2260,9 @@ char *pa_readlink(const char *p) { pa_xfree(c); l *= 2; } +#else + return NULL; +#endif } int pa_close_all(int except_fd, ...) { @@ -2276,6 +2301,7 @@ int pa_close_all(int except_fd, ...) { } int pa_close_allv(const int except_fds[]) { +#ifndef OS_IS_WIN32 struct rlimit rl; int maxfd, fd; @@ -2365,6 +2391,7 @@ int pa_close_allv(const int except_fds[]) { if (pa_close(fd) < 0 && errno != EBADF) return -1; } +#endif /* !OS_IS_WIN32 */ return 0; } @@ -2405,6 +2432,7 @@ int pa_unblock_sigs(int except, ...) { } int pa_unblock_sigsv(const int except[]) { +#ifndef OS_IS_WIN32 int i; sigset_t ss; @@ -2416,6 +2444,9 @@ int pa_unblock_sigsv(const int except[]) { return -1; return sigprocmask(SIG_SETMASK, &ss, NULL); +#else + return 0; +#endif } int pa_reset_sigs(int except, ...) { @@ -2454,6 +2485,7 @@ int pa_reset_sigs(int except, ...) { } int pa_reset_sigsv(const int except[]) { +#ifndef OS_IS_WIN32 int sig; for (sig = 1; sig < NSIG; sig++) { @@ -2490,6 +2522,7 @@ int pa_reset_sigsv(const int except[]) { return -1; } } +#endif return 0; } @@ -2624,9 +2657,13 @@ char *pa_machine_id(void) { if ((h = pa_get_host_name_malloc())) return h; +#ifndef OS_IS_WIN32 /* If no hostname was set we use the POSIX hostid. It's usually * the IPv4 address. Might not be that stable. */ return pa_sprintf_malloc("%08lx", (unsigned long) gethostid); +#else + return NULL; +#endif } char *pa_session_id(void) { diff --git a/src/pulsecore/inet_ntop.h b/src/pulsecore/inet_ntop.h index 7e1b2037..77ace6a4 100644 --- a/src/pulsecore/inet_ntop.h +++ b/src/pulsecore/inet_ntop.h @@ -1,8 +1,12 @@ #ifndef fooinet_ntophfoo #define fooinet_ntophfoo +#ifndef HAVE_INET_NTOP + #include const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); #endif + +#endif diff --git a/src/pulsecore/inet_pton.h b/src/pulsecore/inet_pton.h index 9d9c476a..913efc4c 100644 --- a/src/pulsecore/inet_pton.h +++ b/src/pulsecore/inet_pton.h @@ -1,8 +1,12 @@ #ifndef fooinet_ptonhfoo #define fooinet_ptonhfoo +#ifndef HAVE_INET_PTON + #include int inet_pton(int af, const char *src, void *dst); #endif + +#endif diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c index b5150573..1a082db6 100644 --- a/src/pulsecore/lock-autospawn.c +++ b/src/pulsecore/lock-autospawn.c @@ -27,7 +27,10 @@ #include #include #include + +#ifdef HAVE_PTHREAD #include +#endif #include #include @@ -206,11 +209,14 @@ static void empty_pipe(void) { static void thread_func(void *u) { int fd; char *lf; + +#ifdef HAVE_PTHREAD sigset_t fullset; /* No signals in this thread please */ sigfillset(&fullset); pthread_sigmask(SIG_BLOCK, &fullset, NULL); +#endif if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) { pa_log_warn(_("Cannot access autospawn lock.")); diff --git a/src/pulsecore/memtrap.c b/src/pulsecore/memtrap.c index 4fc18210..b56d806a 100644 --- a/src/pulsecore/memtrap.c +++ b/src/pulsecore/memtrap.c @@ -24,7 +24,10 @@ #endif #include + +#ifdef HAVE_SYS_MMAN_H #include +#endif /* This is deprecated on glibc but is still used by FreeBSD */ #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) @@ -68,6 +71,7 @@ static void sigsafe_error(const char *s) { (void) write(STDERR_FILENO, s, strlen(s)); } +#ifdef HAVE_SIGACTION static void signal_handler(int sig, siginfo_t* si, void *data) { unsigned j; pa_memtrap *m; @@ -102,6 +106,7 @@ fail: sigsafe_error("Failed to handle SIGBUS.\n"); abort(); } +#endif static void memtrap_link(pa_memtrap *m, unsigned j) { pa_assert(m); @@ -221,6 +226,7 @@ unlock: } void pa_memtrap_install(void) { +#ifdef HAVE_SIGACTION struct sigaction sa; allocate_aupdate(); @@ -230,4 +236,5 @@ void pa_memtrap_install(void) { sa.sa_flags = SA_RESTART|SA_SIGINFO; pa_assert_se(sigaction(SIGBUS, &sa, NULL) == 0); +#endif } diff --git a/src/pulsecore/start-child.c b/src/pulsecore/start-child.c index 4a70aea1..dabcfa5b 100644 --- a/src/pulsecore/start-child.c +++ b/src/pulsecore/start-child.c @@ -47,6 +47,7 @@ int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) { pid_t child; int pipe_fds[2] = { -1, -1 }; +#ifdef HAVE_FORK if (pipe(pipe_fds) < 0) { pa_log("pipe() failed: %s", pa_cstrerror(errno)); goto fail; @@ -104,6 +105,7 @@ int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) { execl(name, name, argv1, NULL); _exit(1); } +#endif fail: pa_close_pipe(pipe_fds); diff --git a/src/pulsecore/thread.h b/src/pulsecore/thread.h index aea02764..79b61ae0 100644 --- a/src/pulsecore/thread.h +++ b/src/pulsecore/thread.h @@ -92,7 +92,7 @@ void *pa_tls_set(pa_tls *t, void *userdata); } \ struct __stupid_useless_struct_to_allow_trailing_semicolon -#ifdef SUPPORT_TLS___THREAD +#if defined(SUPPORT_TLS___THREAD) && !defined(OS_IS_WIN32) /* An optimized version of the above that requires no dynamic * allocation if the compiler supports __thread */ #define PA_STATIC_TLS_DECLARE_NO_FREE(name) \ diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c index c93fee93..21f33bf2 100644 --- a/src/tests/rtstutter.c +++ b/src/tests/rtstutter.c @@ -29,7 +29,10 @@ #include #include #include + +#ifdef HAVE_PTHREAD #include +#endif #include #include @@ -43,9 +46,6 @@ static int msec_lower, msec_upper; static void* work(void *p) PA_GCC_NORETURN; static void* work(void *p) { -#ifdef HAVE_PTHREAD_SETAFFINITY_NP - cpu_set_t mask; -#endif struct sched_param param; pa_log_notice("CPU%i: Created thread.", PA_PTR_TO_UINT(p)); @@ -55,9 +55,13 @@ static void* work(void *p) { pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) == 0); #ifdef HAVE_PTHREAD_SETAFFINITY_NP +{ + cpu_set_t mask; + CPU_ZERO(&mask); CPU_SET((size_t) PA_PTR_TO_UINT(p), &mask); pa_assert_se(pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) == 0); +} #endif for (;;) { -- cgit From a951c779c6fe0705f75c1dfbe090deb78485b4e8 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 4 Jan 2011 16:48:06 +0100 Subject: Use PCRE if POSIX regex.h is not available --- configure.ac | 9 ++++++--- src/modules/module-match.c | 7 ++++++- src/pulsecore/core-util.c | 7 ++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 42d9c3bf..a2657c08 100644 --- a/configure.ac +++ b/configure.ac @@ -362,10 +362,7 @@ AC_CHECK_HEADERS([netinet/ip.h], [], [], # include #endif ]) -AC_CHECK_HEADERS([regex.h], [HAVE_REGEX=1], [HAVE_REGEX=0]) AC_CHECK_HEADERS([sys/un.h], [HAVE_AF_UNIX=1], [HAVE_AF_UNIX=0]) - -AM_CONDITIONAL(HAVE_REGEX, test "x$HAVE_REGEX" = "x1") AM_CONDITIONAL(HAVE_AF_UNIX, test "x$HAVE_AF_UNIX" = "x1") # Linux @@ -391,6 +388,7 @@ AC_CHECK_HEADERS_ONCE([sys/syscall.h]) AC_CHECK_HEADERS_ONCE([sys/eventfd.h]) AC_CHECK_HEADERS_ONCE([execinfo.h]) AC_CHECK_HEADERS_ONCE([langinfo.h]) +AC_CHECK_HEADERS_ONCE([regex.h pcreposix.h]) #### Typdefs, structures, etc. #### @@ -459,6 +457,8 @@ fi AC_SUBST(HAVE_BONJOUR) AM_CONDITIONAL([HAVE_BONJOUR], [test "x$HAVE_BONJOUR" = x1]) +AC_SEARCH_LIBS([regexec], [pcreposix]) + #### Check for functions #### # ISO @@ -518,6 +518,9 @@ AS_IF([test "$pulseaudio_cv_PTHREAD_PRIO_INHERIT" = "yes"], [ AC_DEFINE_UNQUOTED(PA_CFLAGS,"$CFLAGS", [The CFLAGS used during compilation]) +AC_CHECK_FUNCS([regexec], [HAVE_REGEX=1], [HAVE_REGEX=0]) +AM_CONDITIONAL(HAVE_REGEX, [test "x$HAVE_REGEX" = "x1"]) + #### Large File-Support (LFS) #### AC_SYS_LARGEFILE diff --git a/src/modules/module-match.c b/src/modules/module-match.c index d83c86c3..f9f36fdb 100644 --- a/src/modules/module-match.c +++ b/src/modules/module-match.c @@ -27,10 +27,15 @@ #include #include #include -#include #include #include +#if defined(HAVE_REGEX_H) +#include +#elif defined(HAVE_PCREPOSIX_H) +#include +#endif + #include #include diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 4c4fbfe0..ba9e820d 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -40,7 +40,6 @@ #include #include #include -#include #ifdef HAVE_LANGINFO_H #include @@ -50,6 +49,12 @@ #include #endif +#if defined(HAVE_REGEX_H) +#include +#elif defined(HAVE_PCREPOSIX_H) +#include +#endif + #ifdef HAVE_STRTOF_L #include #endif -- cgit From 2de2c735c937c6724c14656acf01ce90f122b903 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 6 Jan 2011 01:35:27 +0100 Subject: Fix dependencies and include necessary headers --- src/Makefile.am | 8 ++++++++ src/pulsecore/core-util.c | 1 + src/pulsecore/inet_ntop.c | 1 + src/pulsecore/parseaddr.c | 1 + src/pulsecore/pipe.c | 1 + src/pulsecore/proplist-util.c | 2 +- src/pulsecore/start-child.c | 1 + src/tests/ipacl-test.c | 1 + 8 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index baba9c5e..89377a67 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -562,6 +562,14 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \ pulse/client-conf.c pulse/client-conf.h \ pulse/i18n.c pulse/i18n.h \ pulse/fork-detect.c pulse/fork-detect.h \ + pulse/xmalloc.c pulse/xmalloc.h \ + pulse/proplist.c pulse/proplist.h \ + pulse/utf8.c pulse/utf8.h \ + pulse/channelmap.c pulse/channelmap.h \ + pulse/sample.c pulse/sample.h \ + pulse/util.c pulse/util.h \ + pulse/timeval.c pulse/timeval.h \ + pulse/rtclock.c pulse/rtclock.h \ pulsecore/atomic.h \ pulsecore/authkey.c pulsecore/authkey.h \ pulsecore/conf-parser.c pulsecore/conf-parser.h \ diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index ba9e820d..49cd01a4 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "core-util.h" diff --git a/src/pulsecore/inet_ntop.c b/src/pulsecore/inet_ntop.c index e283a670..64c28edb 100644 --- a/src/pulsecore/inet_ntop.c +++ b/src/pulsecore/inet_ntop.c @@ -28,6 +28,7 @@ #ifndef HAVE_INET_NTOP +#include #include #include "inet_ntop.h" diff --git a/src/pulsecore/parseaddr.c b/src/pulsecore/parseaddr.c index 7f6cd903..99fdcbf4 100644 --- a/src/pulsecore/parseaddr.c +++ b/src/pulsecore/parseaddr.c @@ -35,6 +35,7 @@ #include #include +#include #include "parseaddr.h" diff --git a/src/pulsecore/pipe.c b/src/pulsecore/pipe.c index db8e16f8..f873ef6b 100644 --- a/src/pulsecore/pipe.c +++ b/src/pulsecore/pipe.c @@ -30,6 +30,7 @@ #include #include +#include #include "pipe.h" diff --git a/src/pulsecore/proplist-util.c b/src/pulsecore/proplist-util.c index 23864bcb..642c498c 100644 --- a/src/pulsecore/proplist-util.c +++ b/src/pulsecore/proplist-util.c @@ -25,7 +25,7 @@ #include #include -#include +#include #ifdef __APPLE__ #include diff --git a/src/pulsecore/start-child.c b/src/pulsecore/start-child.c index dabcfa5b..fd1baebb 100644 --- a/src/pulsecore/start-child.c +++ b/src/pulsecore/start-child.c @@ -40,6 +40,7 @@ #include #include +#include #include "start-child.h" diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index 88bd6c6f..58663468 100644 --- a/src/tests/ipacl-test.c +++ b/src/tests/ipacl-test.c @@ -24,6 +24,7 @@ #include #include #include +#include int main(int argc, char *argv[]) { struct sockaddr_in sa; -- cgit From 5815ec6f3ec7d138e9dd2d28d442ad1059ecb020 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 6 Jan 2011 01:39:29 +0100 Subject: Add AM_LDFLAGS more consistently to all commands --- src/Makefile.am | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 89377a67..55e6322d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,12 +74,12 @@ BINLDFLAGS = -static endif if OS_IS_WIN32 -AM_LDFLAGS+=-Wl,--export-all-symbols +AM_LDFLAGS+=-Wl,--export-all-symbols,--enable-auto-import -no-undefined WINSOCK_LIBS=-lwsock32 -lws2_32 -lwininet endif FOREIGN_CFLAGS = -w -MODULE_LDFLAGS = -module -disable-static -avoid-version $(LDFLAGS_NOUNDEFINED) +MODULE_LDFLAGS = $(AM_LDFLAGS) -module -disable-static -avoid-version $(LDFLAGS_NOUNDEFINED) MODULE_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la ################################### @@ -866,7 +866,7 @@ libpulsecore_@PA_MAJORMINOR@_la_SOURCES = \ pulsecore/database.h libpulsecore_@PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSPEEX_CFLAGS) $(LIBSNDFILE_CFLAGS) $(WINSOCK_CFLAGS) -libpulsecore_@PA_MAJORMINOR@_la_LDFLAGS = -avoid-version +libpulsecore_@PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libpulsecore_@PA_MAJORMINOR@_la_LIBADD = $(AM_LIBADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSPEEX_LIBS) $(LIBSNDFILE_LIBS) $(WINSOCK_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libpulsecore-foreign.la if HAVE_X11 @@ -936,27 +936,27 @@ modlibexec_LTLIBRARIES += \ endif libprotocol_simple_la_SOURCES = pulsecore/protocol-simple.c pulsecore/protocol-simple.h -libprotocol_simple_la_LDFLAGS = -avoid-version +libprotocol_simple_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libprotocol_simple_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libcli_la_SOURCES = pulsecore/cli.c pulsecore/cli.h -libcli_la_LDFLAGS = -avoid-version +libcli_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libcli_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libprotocol_cli_la_SOURCES = pulsecore/protocol-cli.c pulsecore/protocol-cli.h -libprotocol_cli_la_LDFLAGS = -avoid-version +libprotocol_cli_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libprotocol_cli_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libcli.la libprotocol_http_la_SOURCES = pulsecore/protocol-http.c pulsecore/protocol-http.h pulsecore/mime-type.c pulsecore/mime-type.h -libprotocol_http_la_LDFLAGS = -avoid-version +libprotocol_http_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libprotocol_http_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libprotocol_native_la_SOURCES = pulsecore/protocol-native.c pulsecore/protocol-native.h pulsecore/native-common.h -libprotocol_native_la_LDFLAGS = -avoid-version +libprotocol_native_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libprotocol_native_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libprotocol_esound_la_SOURCES = pulsecore/protocol-esound.c pulsecore/protocol-esound.h pulsecore/esound.h -libprotocol_esound_la_LDFLAGS = -avoid-version +libprotocol_esound_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libprotocol_esound_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la librtp_la_SOURCES = \ @@ -965,19 +965,19 @@ librtp_la_SOURCES = \ modules/rtp/sap.c modules/rtp/sap.h \ modules/rtp/rtsp_client.c modules/rtp/rtsp_client.h \ modules/rtp/headerlist.c modules/rtp/headerlist.h -librtp_la_LDFLAGS = -avoid-version +librtp_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version librtp_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libraop_la_SOURCES = \ modules/raop/raop_client.c modules/raop/raop_client.h \ modules/raop/base64.c modules/raop/base64.h libraop_la_CFLAGS = $(AM_CFLAGS) $(OPENSSL_CFLAGS) -I$(top_srcdir)/src/modules/rtp -libraop_la_LDFLAGS = -avoid-version +libraop_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libraop_la_LIBADD = $(AM_LIBADD) $(OPENSSL_LIBS) libpulsecore-@PA_MAJORMINOR@.la librtp.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la # Avahi libavahi_wrap_la_SOURCES = pulsecore/avahi-wrap.c pulsecore/avahi-wrap.h -libavahi_wrap_la_LDFLAGS = -avoid-version +libavahi_wrap_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version libavahi_wrap_la_CFLAGS = $(AM_CFLAGS) $(AVAHI_CFLAGS) libavahi_wrap_la_LIBADD = $(AM_LIBADD) $(AVAHI_CFLAGS) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la @@ -1416,7 +1416,7 @@ module_esound_compat_spawnpid_la_LDFLAGS = $(MODULE_LDFLAGS) module_esound_compat_spawnpid_la_LIBADD = $(MODULE_LIBADD) module_esound_sink_la_SOURCES = modules/module-esound-sink.c -module_esound_sink_la_LDFLAGS = $(MODULE_LDFLAGS) +module_esound_sink_la_LDFLAGS = $(MODULE_LDFLAGS) $(WINSOCK_LIBS) module_esound_sink_la_LIBADD = $(MODULE_LIBADD) # Pipes @@ -1440,7 +1440,7 @@ module_null_sink_la_LDFLAGS = $(MODULE_LDFLAGS) module_null_sink_la_LIBADD = $(MODULE_LIBADD) module_sine_source_la_SOURCES = modules/module-sine-source.c -module_sine_source_la_LDFLAGS = -module -avoid-version +module_sine_source_la_LDFLAGS = $(MODULE_LDFLAGS) module_sine_source_la_LIBADD = $(MODULE_LIBADD) # Couplings -- cgit From 7b90e3b942b43521e4ed6b9f07b14ee3ae156cf3 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 4 Jan 2011 17:12:09 +0100 Subject: Repair some typos --- src/pulsecore/core-util.c | 8 ++++---- src/pulsecore/socket-client.c | 2 +- src/pulsecore/thread-mq.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 49cd01a4..f2a09463 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1166,23 +1166,23 @@ int pa_check_in_group(gid_t g) { #else /* HAVE_GRP_H */ int pa_own_uid_in_group(const char *name, gid_t *gid) { - errno = ENOSUP; + errno = ENOTSUP; return -1; } int pa_uid_in_group(uid_t uid, const char *name) { - errno = ENOSUP; + errno = ENOTSUP; return -1; } gid_t pa_get_gid_of_group(const char *name) { - errno = ENOSUP; + errno = ENOTSUP; return (gid_t) -1; } int pa_check_in_group(gid_t g) { - errno = ENOSUP; + errno = ENOTSUP; return -1; } diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c index 31acfd2d..ae7abc9e 100644 --- a/src/pulsecore/socket-client.c +++ b/src/pulsecore/socket-client.c @@ -522,7 +522,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, pa_bool_t use_ if (!host) goto finish; - pa_zero(sa); + pa_zero(s); s.sin_family = AF_INET; memcpy(&s.sin_addr, host->h_addr, sizeof(struct in_addr)); s.sin_port = htons(a.port); diff --git a/src/pulsecore/thread-mq.h b/src/pulsecore/thread-mq.h index 96839d25..a1f4b3fe 100644 --- a/src/pulsecore/thread-mq.h +++ b/src/pulsecore/thread-mq.h @@ -27,7 +27,7 @@ #include /* Two way communication between a thread and a mainloop. Before the - * thread is started a pa_pthread_mq should be initialized and than + * thread is started a pa_thread_mq should be initialized and than * attached to the thread using pa_thread_mq_install(). */ typedef struct pa_thread_mq { -- cgit From d6d43367053bbc0d99acd7a21a21e15a5aaae659 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 6 Jan 2011 02:10:45 +0100 Subject: Implement some functions for win32 And disable building binaries for win32 that make no sense there --- src/Makefile.am | 22 ++++++++++++----- src/daemon/main.c | 2 +- src/pulsecore/authkey.c | 2 +- src/pulsecore/core-util.c | 62 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 71 insertions(+), 17 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 55e6322d..c17c225d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -177,8 +177,11 @@ endif bin_PROGRAMS += \ pacat \ - pactl \ - pasuspender + pactl + +if !OS_IS_WIN32 +bin_PROGRAMS += pasuspender +endif if HAVE_AF_UNIX bin_PROGRAMS += pacmd @@ -256,9 +259,7 @@ TESTS = \ envelope-test \ proplist-test \ lock-autospawn-test \ - prioq-test \ - sigbus-test \ - usergroup-test + prioq-test TESTS_BINARIES = \ mainloop-test \ @@ -295,9 +296,16 @@ TESTS_BINARIES = \ rtstutter \ stripnul \ lock-autospawn-test \ - prioq-test \ + prioq-test + +if !OS_IS_WIN32 +TESTS += \ + sigbus-test \ + usergroup-test +TESTS_BINARIES += \ sigbus-test \ usergroup-test +endif if HAVE_SIGXCPU #TESTS += \ @@ -326,9 +334,11 @@ TESTS_BINARIES += \ endif if !OS_IS_DARWIN +if !OS_IS_WIN32 TESTS_BINARIES += \ once-test endif +endif if BUILD_TESTS_DEFAULT noinst_PROGRAMS = $(TESTS_BINARIES) diff --git a/src/daemon/main.c b/src/daemon/main.c index 5aeb9bc6..243e7c0a 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -1078,7 +1078,7 @@ finish: } #ifdef OS_IS_WIN32 - if (win32_timer) + if (mainloop && win32_timer) pa_mainloop_get_api(mainloop)->time_free(win32_timer); #endif diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c index d671e367..684bc010 100644 --- a/src/pulsecore/authkey.c +++ b/src/pulsecore/authkey.c @@ -151,7 +151,7 @@ static char *normalize_path(const char *fn) { #ifndef OS_IS_WIN32 if (fn[0] != '/') { #else - if (strlen(fn) < 3 || !isalpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') { + if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') { #endif char *homedir, *s; diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index f2a09463..04a2341f 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -91,6 +91,10 @@ #include #endif +#ifndef ENOTSUP +#define ENOTSUP 135 +#endif + #ifdef HAVE_PWD_H #include #endif @@ -147,20 +151,18 @@ static pa_strlist *recorded_env = NULL; #define PULSE_ROOTENV "PULSE_ROOT" int pa_set_root(HANDLE handle) { - char library_path[MAX_PATH + sizeof(PULSE_ROOTENV) + 1], *sep; - - strcpy(library_path, PULSE_ROOTENV "="); + char library_path[MAX_PATH], *sep; /* FIXME: Needs to set errno */ - if (!GetModuleFileName(handle, library_path + sizeof(PULSE_ROOTENV), MAX_PATH)) + if (!GetModuleFileName(handle, library_path, MAX_PATH)) return 0; sep = strrchr(library_path, PA_PATH_SEP_CHAR); if (sep) *sep = '\0'; - if (_putenv(library_path) < 0) + if (!SetEnvironmentVariable(PULSE_ROOTENV, library_path)) return 0; return 1; @@ -696,14 +698,21 @@ int pa_make_realtime(int rtprio) { pa_log_info("Successfully enabled SCHED_RR scheduling for thread, with priority %i, which is lower than the requested %i.", p, rtprio); return 0; } +#elif defined(OS_IS_WIN32) + /* Windows only allows realtime scheduling to be set on a per process basis. + * Therefore, instead of making the thread realtime, just give it the highest non-realtime priority. */ + if(SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL)) { + pa_log_info("Successfully enabled THREAD_PRIORITY_TIME_CRITICAL scheduling for thread."); + return 0; + } - pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno)); - return -1; + pa_log_warn("SetThreadPriority() failed: 0x%08X", GetLastError()); + errno = EPERM; #else - errno = ENOTSUP; - return -1; #endif + pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno)); + return -1; } static int set_nice(int nice_level) { @@ -1499,6 +1508,9 @@ static int make_random_dir_and_link(mode_t m, const char *k) { errno = saved_errno; return -1; } +#else + pa_xfree(p); + return -1; #endif pa_xfree(p); @@ -1558,6 +1570,7 @@ char *pa_get_runtime_dir(void) { goto fail; } +#ifdef HAVE_SYMLINK /* Hmm, so the runtime directory didn't exist yet, so let's * create one in /tmp and symlink that to it */ @@ -1570,6 +1583,11 @@ char *pa_get_runtime_dir(void) { goto fail; } +#else + /* No symlink possible, so let's just create the runtime directly */ + if (!mkdir(k)) + goto fail; +#endif return k; } @@ -2539,7 +2557,11 @@ void pa_set_env(const char *key, const char *value) { /* This is not thread-safe */ +#ifdef OS_IS_WIN32 + SetEnvironmentVariable(key, value); +#else setenv(key, value, 1); +#endif } void pa_set_env_and_record(const char *key, const char *value) { @@ -2564,7 +2586,11 @@ void pa_unset_env_recorded(void) { if (!s) break; +#ifdef OS_IS_WIN32 + SetEnvironmentVariable(s, NULL); +#else unsetenv(s); +#endif pa_xfree(s); } } @@ -2682,11 +2708,22 @@ char *pa_session_id(void) { } char *pa_uname_string(void) { +#ifdef HAVE_UNAME struct utsname u; pa_assert_se(uname(&u) >= 0); return pa_sprintf_malloc("%s %s %s %s", u.sysname, u.machine, u.release, u.version); +#endif +#ifdef OS_IS_WIN32 + OSVERSIONINFO i; + + pa_zero(i); + i.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + pa_assert_se(GetVersionEx(&i)); + + return pa_sprintf_malloc("Windows %d.%d (%d) %s", i.dwMajorVersion, i.dwMinorVersion, i.dwBuildNumber, i.szCSDVersion); +#endif } #ifdef HAVE_VALGRIND_MEMCHECK_H @@ -2835,10 +2872,17 @@ char *pa_realpath(const char *path) { char *path_buf; path_buf = pa_xmalloc(PATH_MAX); +#if defined(OS_IS_WIN32) + if (!(t = _fullpath(path_buf, path, _MAX_PATH))) { + pa_xfree(path_buf); + return NULL; + } +#else if (!(t = realpath(path, path_buf))) { pa_xfree(path_buf); return NULL; } +#endif } #else #error "It's not clear whether this system supports realpath(..., NULL) like GNU libc does. If it doesn't we need a private version of realpath() here." -- cgit From 5699954d3360716ad693e0b88596e372afe74443 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Mon, 17 Jan 2011 13:17:48 +0100 Subject: win32: flush stderr after log output --- src/pulsecore/log.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c index 7ba41ee9..2c0e267a 100644 --- a/src/pulsecore/log.c +++ b/src/pulsecore/log.c @@ -374,6 +374,9 @@ void pa_log_levelv_meta( fprintf(stderr, "%s%c: %s%s%s%s%s%s\n", timestamp, level_to_char[level], location, prefix, t, grey, pa_strempty(bt), suffix); else fprintf(stderr, "%s%s%s%s%s%s%s\n", timestamp, location, prefix, t, grey, pa_strempty(bt), suffix); +#ifdef OS_IS_WIN32 + fflush(stderr); +#endif pa_xfree(local_t); -- cgit From a39a83665f07a0819a31ee2d1ab60210a67c47a2 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 18 Jan 2011 11:26:57 +0100 Subject: win32: Implement rtclock based on QueryPerformanceCounter Also remove some unnecessary headers. --- src/pulse/def.h | 1 - src/pulse/mainloop-api.h | 1 - src/pulse/rtclock.c | 2 +- src/pulse/timeval.c | 15 +++++---------- src/pulsecore/authkey.c | 1 - src/pulsecore/core-rtclock.c | 30 ++++++++++++++++++++++++++++++ src/pulsecore/core-util.c | 2 -- src/pulsecore/memblockq.c | 2 -- src/pulsecore/tagstruct.h | 1 - 9 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/pulse/def.h b/src/pulse/def.h index 4a8da137..ac4ae538 100644 --- a/src/pulse/def.h +++ b/src/pulse/def.h @@ -25,7 +25,6 @@ #include #include -#include #include #include diff --git a/src/pulse/mainloop-api.h b/src/pulse/mainloop-api.h index aa0d5e73..0ce2219b 100644 --- a/src/pulse/mainloop-api.h +++ b/src/pulse/mainloop-api.h @@ -24,7 +24,6 @@ ***/ #include -#include #include #include diff --git a/src/pulse/rtclock.c b/src/pulse/rtclock.c index 49ff6aae..baa0f3a5 100644 --- a/src/pulse/rtclock.c +++ b/src/pulse/rtclock.c @@ -23,10 +23,10 @@ #include #endif +#include #include #include "rtclock.h" -#include "timeval.h" pa_usec_t pa_rtclock_now(void) { struct timeval tv; diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c index c4a08419..10ba322f 100644 --- a/src/pulse/timeval.c +++ b/src/pulse/timeval.c @@ -37,29 +37,22 @@ #include "timeval.h" struct timeval *pa_gettimeofday(struct timeval *tv) { -#ifdef HAVE_GETTIMEOFDAY pa_assert(tv); - pa_assert_se(gettimeofday(tv, NULL) == 0); - return tv; -#elif defined(OS_IS_WIN32) +#if defined(OS_IS_WIN32) /* * Copied from implementation by Steven Edwards (LGPL). * Found on wine mailing list. */ - #if defined(_MSC_VER) || defined(__BORLANDC__) #define EPOCHFILETIME (116444736000000000i64) #else #define EPOCHFILETIME (116444736000000000LL) #endif - FILETIME ft; LARGE_INTEGER li; int64_t t; - pa_assert(tv); - GetSystemTimeAsFileTime(&ft); li.LowPart = ft.dwLowDateTime; li.HighPart = ft.dwHighDateTime; @@ -68,11 +61,13 @@ struct timeval *pa_gettimeofday(struct timeval *tv) { t /= 10; /* In microseconds */ tv->tv_sec = (time_t) (t / PA_USEC_PER_SEC); tv->tv_usec = (suseconds_t) (t % PA_USEC_PER_SEC); - - return tv; +#elif defined(HAVE_GETTIMEOFDAY) + pa_assert_se(gettimeofday(tv, NULL) == 0); #else #error "Platform lacks gettimeofday() or equivalent function." #endif + + return tv; } pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) { diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c index 684bc010..92509d89 100644 --- a/src/pulsecore/authkey.c +++ b/src/pulsecore/authkey.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c index a69b466f..ac2c097a 100644 --- a/src/pulsecore/core-rtclock.c +++ b/src/pulsecore/core-rtclock.c @@ -40,12 +40,20 @@ #include #endif +#ifdef HAVE_WINDOWS_H +#include +#endif + #include #include #include #include "core-rtclock.h" +#ifdef OS_IS_WIN32 +static int64_t counter_freq = 0; +#endif + pa_usec_t pa_rtclock_age(const struct timeval *tv) { struct timeval now; pa_assert(tv); @@ -88,6 +96,17 @@ struct timeval *pa_rtclock_get(struct timeval *tv) { tv->tv_usec = ts.tv_nsec / PA_NSEC_PER_USEC; return tv; +#elif defined(OS_IS_WIN32) + if (counter_freq > 0) { + LARGE_INTEGER count; + + pa_assert_se(QueryPerformanceCounter(&count)); + + tv->tv_sec = count.QuadPart / counter_freq; + tv->tv_usec = (count.QuadPart % counter_freq) * PA_USEC_PER_SEC / counter_freq; + + return tv; + } #endif /* HAVE_CLOCK_GETTIME */ return pa_gettimeofday(tv); @@ -118,6 +137,11 @@ pa_bool_t pa_rtclock_hrtimer(void) { pa_assert_se(clock_getres(CLOCK_REALTIME, &ts) == 0); return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC); +#elif defined(OS_IS_WIN32) + + if (counter_freq > 0) + return counter_freq >= (int64_t) (PA_USEC_PER_SEC/PA_HRTIMER_THRESHOLD_USEC); + #endif /* HAVE_CLOCK_GETTIME */ return FALSE; @@ -148,6 +172,12 @@ void pa_rtclock_hrtimer_enable(void) { } } +#elif defined(OS_IS_WIN32) + LARGE_INTEGER freq; + + pa_assert_se(QueryPerformanceFrequency(&freq)); + counter_freq = freq.QuadPart; + #endif } diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 04a2341f..8a377e37 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -34,11 +34,9 @@ #include #include #include -#include #include #include #include -#include #include #ifdef HAVE_LANGINFO_H diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c index c7840484..11faedac 100644 --- a/src/pulsecore/memblockq.c +++ b/src/pulsecore/memblockq.c @@ -23,8 +23,6 @@ #include #endif -#include -#include #include #include #include diff --git a/src/pulsecore/tagstruct.h b/src/pulsecore/tagstruct.h index 1a99e924..b6553ada 100644 --- a/src/pulsecore/tagstruct.h +++ b/src/pulsecore/tagstruct.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include -- cgit From 5205e6a85ac8699c464e2d676c4d8b1c2b7989e5 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 18 Jan 2011 11:28:13 +0100 Subject: win32: Implement pa_random --- src/pulsecore/random.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c index 3d159bf2..bdbc1437 100644 --- a/src/pulsecore/random.c +++ b/src/pulsecore/random.c @@ -31,6 +31,11 @@ #include #include +#ifdef HAVE_WINDOWS_H +#include +#include +#endif + #include #include #include @@ -43,10 +48,20 @@ static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL }; static int random_proper(void *ret_data, size_t length) { #ifdef OS_IS_WIN32 + int ret = -1; + pa_assert(ret_data); pa_assert(length > 0); - return -1; + HCRYPTPROV hCryptProv = NULL; + + if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { + if(CryptGenRandom(hCryptProv, length, ret_data)) + ret = 0; + CryptReleaseContext(hCryptProv, 0); + } + + return ret; #else /* OS_IS_WIN32 */ -- cgit From 110b14ec21eacaf6baa4fa111a76e26bad585dcd Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Wed, 12 Jan 2011 15:02:18 +0100 Subject: module-waveout: Adapted to updated API Waveout sink works again, Wavein source still needs some work. --- src/Makefile.am | 17 +- src/modules/module-waveout.c | 395 +++++++++++++++++++++++++------------------ 2 files changed, 235 insertions(+), 177 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index c17c225d..ed4a06a1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1183,10 +1183,10 @@ pulselibexec_PROGRAMS += \ gconf-helper endif -#if OS_IS_WIN32 -#modlibexec_LTLIBRARIES += \ -# module-waveout.la -#endif +if OS_IS_WIN32 +modlibexec_LTLIBRARIES += \ + module-waveout.la +endif if HAVE_HAL modlibexec_LTLIBRARIES += \ @@ -1624,11 +1624,10 @@ module_mmkbd_evdev_la_LIBADD = $(MODULE_LIBADD) module_mmkbd_evdev_la_CFLAGS = $(AM_CFLAGS) # Windows waveout - -#module_waveout_la_SOURCES = modules/module-waveout.c -#module_waveout_la_LDFLAGS = $(MODULE_LDFLAGS) -#module_waveout_la_LIBADD = $(MODULE_LIBADD) -lwinmm -#module_waveout_la_CFLAGS = $(AM_CFLAGS) +module_waveout_la_SOURCES = modules/module-waveout.c +module_waveout_la_LDFLAGS = $(MODULE_LDFLAGS) +module_waveout_la_LIBADD = $(MODULE_LIBADD) -lwinmm +module_waveout_la_CFLAGS = $(AM_CFLAGS) # Hardware autodetection module module_detect_la_SOURCES = modules/module-detect.c diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c index 6fedceb2..0dbf7ef9 100644 --- a/src/modules/module-waveout.c +++ b/src/modules/module-waveout.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -39,12 +40,14 @@ #include #include #include +#include +#include #include "module-waveout-symdef.h" -PA_MODULE_AUTHOR("Pierre Ossman") -PA_MODULE_DESCRIPTION("Windows waveOut Sink/Source") -PA_MODULE_VERSION(PACKAGE_VERSION) +PA_MODULE_AUTHOR("Pierre Ossman"); +PA_MODULE_DESCRIPTION("Windows waveOut Sink/Source"); +PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_USAGE( "sink_name= " "source_name= " @@ -56,7 +59,7 @@ PA_MODULE_USAGE( "rate= " "fragments= " "fragment_size= " - "channel_map=") + "channel_map="); #define DEFAULT_SINK_NAME "wave_output" #define DEFAULT_SOURCE_NAME "wave_input" @@ -67,10 +70,12 @@ struct userdata { pa_sink *sink; pa_source *source; pa_core *core; - pa_time_event *event; - pa_defer_event *defer; pa_usec_t poll_timeout; + pa_thread *thread; + pa_thread_mq thread_mq; + pa_rtpoll *rtpoll; + uint32_t fragments, fragment_size; uint32_t free_ofrags, free_ifrags; @@ -103,22 +108,19 @@ static const char* const valid_modargs[] = { NULL }; -static void update_usage(struct userdata *u) { - pa_module_set_used(u->module, - (u->sink ? pa_sink_used_by(u->sink) : 0) + - (u->source ? pa_source_used_by(u->source) : 0)); -} - -static void do_write(struct userdata *u) -{ +static void do_write(struct userdata *u) { uint32_t free_frags; pa_memchunk memchunk; WAVEHDR *hdr; MMRESULT res; + void *p; if (!u->sink) return; + if (!PA_SINK_IS_LINKED(u->sink->state)) + return; + EnterCriticalSection(&u->crit); free_frags = u->free_ofrags; LeaveCriticalSection(&u->crit); @@ -137,18 +139,17 @@ static void do_write(struct userdata *u) len = u->fragment_size - hdr->dwBufferLength; - if (pa_sink_render(u->sink, len, &memchunk) < 0) - break; + pa_sink_render(u->sink, len, &memchunk); - assert(memchunk.memblock); - assert(memchunk.memblock->data); - assert(memchunk.length); + pa_assert(memchunk.memblock); + pa_assert(memchunk.length); if (memchunk.length < len) len = memchunk.length; - memcpy(hdr->lpData + hdr->dwBufferLength, - (char*)memchunk.memblock->data + memchunk.index, len); + p = pa_memblock_acquire(memchunk.memblock); + memcpy(hdr->lpData + hdr->dwBufferLength, (char*) p + memchunk.index, len); + pa_memblock_release(memchunk.memblock); hdr->dwBufferLength += len; @@ -165,15 +166,12 @@ static void do_write(struct userdata *u) u->sink_underflow = 0; res = waveOutPrepareHeader(u->hwo, hdr, sizeof(WAVEHDR)); - if (res != MMSYSERR_NOERROR) { - pa_log_error(__FILE__ ": ERROR: Unable to prepare waveOut block: %d", - res); - } + if (res != MMSYSERR_NOERROR) + pa_log_error("Unable to prepare waveOut block: %d", res); + res = waveOutWrite(u->hwo, hdr, sizeof(WAVEHDR)); - if (res != MMSYSERR_NOERROR) { - pa_log_error(__FILE__ ": ERROR: Unable to write waveOut block: %d", - res); - } + if (res != MMSYSERR_NOERROR) + pa_log_error("Unable to write waveOut block: %d", res); u->written_bytes += hdr->dwBufferLength; @@ -187,21 +185,22 @@ static void do_write(struct userdata *u) } } -static void do_read(struct userdata *u) -{ +static void do_read(struct userdata *u) { uint32_t free_frags; pa_memchunk memchunk; WAVEHDR *hdr; MMRESULT res; + void *p; if (!u->source) return; - EnterCriticalSection(&u->crit); + if (!PA_SOURCE_IS_LINKED(u->source->state)) + return; + EnterCriticalSection(&u->crit); free_frags = u->free_ifrags; u->free_ifrags = 0; - LeaveCriticalSection(&u->crit); if (free_frags == u->fragments) @@ -214,11 +213,13 @@ static void do_read(struct userdata *u) if (hdr->dwBytesRecorded) { memchunk.memblock = pa_memblock_new(u->core->mempool, hdr->dwBytesRecorded); - assert(memchunk.memblock); + pa_assert(memchunk.memblock); - memcpy((char*)memchunk.memblock->data, hdr->lpData, hdr->dwBytesRecorded); + p = pa_memblock_acquire(memchunk.memblock); + memcpy((char*) p, hdr->lpData, hdr->dwBytesRecorded); + pa_memblock_release(memchunk.memblock); - memchunk.length = memchunk.memblock->length = hdr->dwBytesRecorded; + memchunk.length = hdr->dwBytesRecorded; memchunk.index = 0; pa_source_post(u->source, &memchunk); @@ -226,15 +227,12 @@ static void do_read(struct userdata *u) } res = waveInPrepareHeader(u->hwi, hdr, sizeof(WAVEHDR)); - if (res != MMSYSERR_NOERROR) { - pa_log_error(__FILE__ ": ERROR: Unable to prepare waveIn block: %d", - res); - } + if (res != MMSYSERR_NOERROR) + pa_log_error("Unable to prepare waveIn block: %d", res); + res = waveInAddBuffer(u->hwi, hdr, sizeof(WAVEHDR)); - if (res != MMSYSERR_NOERROR) { - pa_log_error(__FILE__ ": ERROR: Unable to add waveIn block: %d", - res); - } + if (res != MMSYSERR_NOERROR) + pa_log_error("Unable to add waveIn block: %d", res); free_frags--; u->cur_ihdr++; @@ -242,32 +240,53 @@ static void do_read(struct userdata *u) } } -static void poll_cb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { +static void thread_func(void *userdata) { struct userdata *u = userdata; - struct timeval ntv; - assert(u); + pa_assert(u); + pa_assert(u->sink || u->source); - update_usage(u); + pa_log_debug("Thread starting up"); - do_write(u); - do_read(u); + if (u->core->realtime_scheduling) + pa_make_realtime(u->core->realtime_priority); - pa_gettimeofday(&ntv); - pa_timeval_add(&ntv, u->poll_timeout); + pa_thread_mq_install(&u->thread_mq); - a->rtclock_time_restart(e, &ntv); -} + for (;;) { + int ret; -static void defer_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { - struct userdata *u = userdata; + if (PA_SINK_IS_OPENED(u->sink->thread_info.state) || + PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { + + if (u->sink->thread_info.rewind_requested) + pa_sink_process_rewind(u->sink, 0); - assert(u); + if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) + do_write(u); + if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) + do_read(u); - a->defer_enable(e, 0); + pa_rtpoll_set_timer_relative(u->rtpoll, u->poll_timeout); + } else + pa_rtpoll_set_timer_disabled(u->rtpoll); - do_write(u); - do_read(u); + /* Hmm, nothing to do. Let's sleep */ + if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) + goto fail; + + if (ret == 0) + goto finish; + } + +fail: + /* If this was no regular exit from the loop we have to continue + * processing messages until we received PA_MESSAGE_SHUTDOWN */ + pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL); + pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN); + +finish: + pa_log_debug("Thread shutting down"); } static void CALLBACK chunk_done_cb(HWAVEOUT hwo, UINT msg, DWORD_PTR inst, DWORD param1, DWORD param2) { @@ -277,10 +296,8 @@ static void CALLBACK chunk_done_cb(HWAVEOUT hwo, UINT msg, DWORD_PTR inst, DWORD return; EnterCriticalSection(&u->crit); - u->free_ofrags++; - assert(u->free_ofrags <= u->fragments); - + pa_assert(u->free_ofrags <= u->fragments); LeaveCriticalSection(&u->crit); } @@ -291,107 +308,124 @@ static void CALLBACK chunk_ready_cb(HWAVEIN hwi, UINT msg, DWORD_PTR inst, DWORD return; EnterCriticalSection(&u->crit); - u->free_ifrags++; - assert(u->free_ifrags <= u->fragments); - + pa_assert(u->free_ifrags <= u->fragments); LeaveCriticalSection(&u->crit); } -static pa_usec_t sink_get_latency_cb(pa_sink *s) { - struct userdata *u = s->userdata; +static pa_usec_t sink_get_latency(struct userdata *u) { uint32_t free_frags; MMTIME mmt; - assert(s && u && u->sink); + pa_assert(u); + pa_assert(u->sink); memset(&mmt, 0, sizeof(mmt)); mmt.wType = TIME_BYTES; if (waveOutGetPosition(u->hwo, &mmt, sizeof(mmt)) == MMSYSERR_NOERROR) - return pa_bytes_to_usec(u->written_bytes - mmt.u.cb, &s->sample_spec); + return pa_bytes_to_usec(u->written_bytes - mmt.u.cb, &u->sink->sample_spec); else { EnterCriticalSection(&u->crit); - free_frags = u->free_ofrags; - LeaveCriticalSection(&u->crit); - return pa_bytes_to_usec((u->fragments - free_frags) * u->fragment_size, - &s->sample_spec); + return pa_bytes_to_usec((u->fragments - free_frags) * u->fragment_size, &u->sink->sample_spec); } } -static pa_usec_t source_get_latency_cb(pa_source *s) { +static pa_usec_t source_get_latency(struct userdata *u) { pa_usec_t r = 0; - struct userdata *u = s->userdata; uint32_t free_frags; - assert(s && u && u->sink); + pa_assert(u); + pa_assert(u->source); EnterCriticalSection(&u->crit); - free_frags = u->free_ifrags; - LeaveCriticalSection(&u->crit); - r += pa_bytes_to_usec((free_frags + 1) * u->fragment_size, &s->sample_spec); + r += pa_bytes_to_usec((free_frags + 1) * u->fragment_size, &u->source->sample_spec); return r; } -static void notify_sink_cb(pa_sink *s) { - struct userdata *u = s->userdata; - assert(u); +static int process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) { + struct userdata *u; - u->core->mainloop->defer_enable(u->defer, 1); -} + if (pa_sink_isinstance(o)) { + u = PA_SINK(o)->userdata; -static void notify_source_cb(pa_source *s) { - struct userdata *u = s->userdata; - assert(u); + switch (code) { + + case PA_SINK_MESSAGE_GET_LATENCY: { + pa_usec_t r = 0; + if (u->hwo) + r = sink_get_latency(u); + *((pa_usec_t*) data) = r; + return 0; + } + + } + + return pa_sink_process_msg(o, code, data, offset, chunk); + } + + if (pa_source_isinstance(o)) { + u = PA_SOURCE(o)->userdata; + + switch (code) { - u->core->mainloop->defer_enable(u->defer, 1); + case PA_SOURCE_MESSAGE_GET_LATENCY: { + pa_usec_t r = 0; + if (u->hwi) + r = source_get_latency(u); + *((pa_usec_t*) data) = r; + return 0; + } + + } + + return pa_source_process_msg(o, code, data, offset, chunk); + } + + return -1; } -static int sink_get_hw_volume_cb(pa_sink *s) { +static void sink_get_volume_cb(pa_sink *s) { struct userdata *u = s->userdata; DWORD vol; pa_volume_t left, right; if (waveOutGetVolume(u->hwo, &vol) != MMSYSERR_NOERROR) - return -1; + return; left = PA_CLAMP_VOLUME((vol & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME); right = PA_CLAMP_VOLUME(((vol >> 16) & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME); /* Windows supports > 2 channels, except for volume control */ - if (s->hw_volume.channels > 2) - pa_cvolume_set(&s->hw_volume, s->hw_volume.channels, (left + right)/2); - - s->hw_volume.values[0] = left; - if (s->hw_volume.channels > 1) - s->hw_volume.values[1] = right; + if (s->real_volume.channels > 2) + pa_cvolume_set(&s->real_volume, s->real_volume.channels, (left + right)/2); - return 0; + s->real_volume.values[0] = left; + if (s->real_volume.channels > 1) + s->real_volume.values[1] = right; } -static int sink_set_hw_volume_cb(pa_sink *s) { +static void sink_set_volume_cb(pa_sink *s) { struct userdata *u = s->userdata; DWORD vol; - vol = s->hw_volume.values[0] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM; - if (s->hw_volume.channels > 1) - vol |= (s->hw_volume.values[0] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM) << 16; + vol = s->real_volume.values[0] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM; + if (s->real_volume.channels > 1) + vol |= (s->real_volume.values[1] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM) << 16; if (waveOutSetVolume(u->hwo, vol) != MMSYSERR_NOERROR) - return -1; - - return 0; + return; } static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) { wf->wFormatTag = WAVE_FORMAT_PCM; if (ss->channels > 2) { - pa_log_error("ERROR: More than two channels not supported."); + pa_log_error("More than two channels not supported."); return -1; } @@ -404,7 +438,7 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) { case 44100: break; default: - pa_log_error("ERROR: Unsupported sample rate."); + pa_log_error("Unsupported sample rate."); return -1; } @@ -415,7 +449,7 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) { else if (ss->format == PA_SAMPLE_S16NE) wf->wBitsPerSample = 16; else { - pa_log_error("ERROR: Unsupported sample format."); + pa_log_error("Unsupported sample format."); return -1; } @@ -427,21 +461,31 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) { return 0; } -int pa__init(pa_core *c, pa_module*m) { +int pa__get_n_used(pa_module *m) { + struct userdata *u; + pa_assert(m); + pa_assert(m->userdata); + u = (struct userdata *)m->userdata; + + return (u->sink ? pa_sink_used_by(u->sink) : 0) + + (u->source ? pa_source_used_by(u->source) : 0); +} + +int pa__init(pa_module *m) { struct userdata *u = NULL; HWAVEOUT hwo = INVALID_HANDLE_VALUE; HWAVEIN hwi = INVALID_HANDLE_VALUE; WAVEFORMATEX wf; int nfrags, frag_size; - int record = 1, playback = 1; + pa_bool_t record = TRUE, playback = TRUE; unsigned int device; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; unsigned int i; - struct timeval tv; - assert(c && m); + pa_assert(m); + pa_assert(m->core); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("failed to parse module arguments."); @@ -471,7 +515,7 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - ss = c->default_sample_spec; + ss = m->core->default_sample_spec; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_WAVEEX) < 0) { pa_log("failed to parse sample specification"); goto fail; @@ -505,34 +549,47 @@ int pa__init(pa_core *c, pa_module*m) { InitializeCriticalSection(&u->crit); if (hwi != INVALID_HANDLE_VALUE) { - u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map); - assert(u->source); + pa_source_new_data data; + pa_source_new_data_init(&data); + data.driver = __FILE__; + data.module = m; + pa_source_new_data_set_sample_spec(&data, &ss); + pa_source_new_data_set_channel_map(&data, &map); + pa_source_new_data_set_name(&data, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME)); + u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY); + pa_source_new_data_done(&data); + + pa_assert(u->source); u->source->userdata = u; - u->source->notify = notify_source_cb; - u->source->get_latency = source_get_latency_cb; - pa_source_set_owner(u->source, m); pa_source_set_description(u->source, "Windows waveIn PCM"); - u->source->is_hardware = 1; + u->source->parent.process_msg = process_msg; } else u->source = NULL; if (hwo != INVALID_HANDLE_VALUE) { - u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map); - assert(u->sink); - u->sink->notify = notify_sink_cb; - u->sink->get_latency = sink_get_latency_cb; - u->sink->get_hw_volume = sink_get_hw_volume_cb; - u->sink->set_hw_volume = sink_set_hw_volume_cb; + pa_sink_new_data data; + pa_sink_new_data_init(&data); + data.driver = __FILE__; + data.module = m; + pa_sink_new_data_set_sample_spec(&data, &ss); + pa_sink_new_data_set_channel_map(&data, &map); + pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME)); + u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY); + pa_sink_new_data_done(&data); + + pa_assert(u->sink); + u->sink->get_volume = sink_get_volume_cb; + u->sink->set_volume = sink_set_volume_cb; u->sink->userdata = u; - pa_sink_set_owner(u->sink, m); pa_sink_set_description(u->sink, "Windows waveOut PCM"); - u->sink->is_hardware = 1; + u->sink->parent.process_msg = process_msg; } else u->sink = NULL; - assert(u->source || u->sink); + pa_assert(u->source || u->sink); + pa_modargs_free(ma); - u->core = c; + u->core = m->core; u->hwi = hwi; u->hwo = hwo; @@ -546,82 +603,84 @@ int pa__init(pa_core *c, pa_module*m) { u->poll_timeout = pa_bytes_to_usec(u->fragments * u->fragment_size / 10, &ss); - pa_gettimeofday(&tv); - pa_timeval_add(&tv, u->poll_timeout); - - u->event = c->mainloop->rtclock_time_new(c->mainloop, &tv, poll_cb, u); - assert(u->event); - - u->defer = c->mainloop->defer_new(c->mainloop, defer_cb, u); - assert(u->defer); - c->mainloop->defer_enable(u->defer, 0); - u->cur_ihdr = 0; u->cur_ohdr = 0; u->ihdrs = pa_xmalloc0(sizeof(WAVEHDR) * u->fragments); - assert(u->ihdrs); + pa_assert(u->ihdrs); u->ohdrs = pa_xmalloc0(sizeof(WAVEHDR) * u->fragments); - assert(u->ohdrs); + pa_assert(u->ohdrs); for (i = 0;i < u->fragments;i++) { u->ihdrs[i].dwBufferLength = u->fragment_size; u->ohdrs[i].dwBufferLength = u->fragment_size; u->ihdrs[i].lpData = pa_xmalloc(u->fragment_size); - assert(u->ihdrs); + pa_assert(u->ihdrs); u->ohdrs[i].lpData = pa_xmalloc(u->fragment_size); - assert(u->ohdrs); + pa_assert(u->ohdrs); } u->module = m; m->userdata = u; - pa_modargs_free(ma); - /* Read mixer settings */ if (u->sink) - sink_get_hw_volume_cb(u->sink); - - return 0; + sink_get_volume_cb(u->sink); -fail: - if (hwi != INVALID_HANDLE_VALUE) - waveInClose(hwi); + u->rtpoll = pa_rtpoll_new(); + pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); + if (!(u->thread = pa_thread_new("waveout-source", thread_func, u))) { + pa_log("Failed to create thread."); + goto fail; + } - if (hwo != INVALID_HANDLE_VALUE) - waveOutClose(hwo); + if (u->sink) { + pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); + pa_sink_set_rtpoll(u->sink, u->rtpoll); + pa_sink_put(u->sink); + } + if (u->source) { + pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); + pa_source_set_rtpoll(u->source, u->rtpoll); + pa_source_put(u->source); + } - if (u) - pa_xfree(u); + return 0; +fail: if (ma) pa_modargs_free(ma); + pa__done(m); + return -1; } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module *m) { struct userdata *u; unsigned int i; - assert(c && m); + pa_assert(m); + pa_assert(m->core); if (!(u = m->userdata)) return; - if (u->event) - c->mainloop->time_free(u->event); + if (u->sink) + pa_sink_unlink(u->sink); + if (u->source) + pa_source_unlink(u->source); - if (u->defer) - c->mainloop->defer_free(u->defer); + pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL); + if (u->thread) + pa_thread_free(u->thread); + pa_thread_mq_done(&u->thread_mq); - if (u->sink) { - pa_sink_disconnect(u->sink); + if (u->sink) pa_sink_unref(u->sink); - } - - if (u->source) { - pa_source_disconnect(u->source); + if (u->source) pa_source_unref(u->source); - } + + if (u->rtpoll) + pa_rtpoll_free(u->rtpoll); if (u->hwi != INVALID_HANDLE_VALUE) { waveInReset(u->hwi); -- cgit From f2a9fd779e6bfc79d7e6f6f45447e9adbb873c34 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 17 Feb 2011 11:28:54 +0100 Subject: Give module-waveout a configure switch - Also disable the scary DBus and udev warnings when building for win32 - and only install some dbus/x11 specific files when appropriate --- configure.ac | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/Makefile.am | 9 ++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index a2657c08..8b4f5866 100644 --- a/configure.ac +++ b/configure.ac @@ -878,6 +878,39 @@ fi AC_SUBST(HAVE_SOLARIS) AM_CONDITIONAL([HAVE_SOLARIS], [test "x$HAVE_SOLARIS" = x1]) +#### WaveOut audio support (optional) #### + +AC_ARG_ENABLE([waveout], + AS_HELP_STRING([--disable-waveout],[Disable optional WaveOut audio support]), + [ + case "${enableval}" in + yes) waveout=yes ;; + no) waveout=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --disable-waveout) ;; + esac + ], + [waveout=auto]) + +if test "x${waveout}" != xno ; then + AC_CHECK_HEADERS([mmsystem.h], + [ + HAVE_WAVEOUT=1 + AC_DEFINE([HAVE_WAVEOUT], 1, [Have WaveOut audio?]) + ], + [ + HAVE_WAVEOUT=0 + if test "x$waveout" = xyes ; then + AC_MSG_ERROR([*** WaveOut audio support not found]) + fi + ], + [#include ]) +else + HAVE_WAVEOUT=0 +fi + +AC_SUBST(HAVE_WAVEOUT) +AM_CONDITIONAL([HAVE_WAVEOUT], [test "x$HAVE_WAVEOUT" = x1]) + #### GLib 2 support (optional) #### AC_ARG_ENABLE([glib2], @@ -1529,6 +1562,11 @@ if test "x$HAVE_SOLARIS" = "x1" ; then ENABLE_SOLARIS=yes fi +ENABLE_WAVEOUT=no +if test "x$HAVE_WAVEOUT" = "x1" ; then + ENABLE_WAVEOUT=yes +fi + ENABLE_GTK20=no if test "x$HAVE_GTK20" = "x1" ; then ENABLE_GTK20=yes @@ -1650,6 +1688,7 @@ echo " System Config Path: ${PA_SYSTEM_CONFIG_PATH} Compiler: ${CC} CFLAGS: ${CFLAGS} + LIBS: ${LIBS} Have X11: ${ENABLE_X11} Enable OSS Output: ${ENABLE_OSS_OUTPUT} @@ -1657,6 +1696,7 @@ echo " Enable CoreAudio: ${ENABLE_COREAUDIO} Enable Alsa: ${ENABLE_ALSA} Enable Solaris: ${ENABLE_SOLARIS} + Enable WaveOut: ${ENABLE_WAVEOUT} Enable GLib 2.0: ${ENABLE_GLIB20} Enable Gtk+ 2.0: ${ENABLE_GTK20} Enable GConf: ${ENABLE_GCONF} @@ -1687,7 +1727,7 @@ echo " Preopened modules: ${PREOPEN_MODS} " -if test "${ENABLE_DBUS}" = "no" ; then +if test "${ENABLE_DBUS}" = "no" && test "x$os_is_win32" != "x1" ; then echo " ===== WARNING WARNING WARNING WARNING WARNING WARNING WARNING ===== You do not have DBUS support enabled. It is strongly recommended @@ -1700,7 +1740,7 @@ controling the PulseAudio daemon itself. " fi -if test "${ENABLE_UDEV}" = "no" ; then +if test "${ENABLE_UDEV}" = "no" && test "x$os_is_win32" != "x1" ; then echo " ===== WARNING WARNING WARNING WARNING WARNING WARNING WARNING ===== You do not have udev support enabled. It is strongly recommended diff --git a/src/Makefile.am b/src/Makefile.am index ed4a06a1..d49d91c7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -112,8 +112,10 @@ pulseconf_DATA = \ daemon.conf \ client.conf +if HAVE_DBUS dbuspolicy_DATA = \ daemon/pulseaudio-system.conf +endif if HAVE_X11 xdgautostart_in_files = \ @@ -175,6 +177,8 @@ endif # Utility programs # ################################### +bin_SCRIPTS = esdcompat + bin_PROGRAMS += \ pacat \ pactl @@ -189,14 +193,13 @@ endif if HAVE_X11 bin_PROGRAMS += pax11publish +bin_SCRIPTS += start-pulseaudio-x11 start-pulseaudio-kde endif if HAVE_AVAHI bin_PROGRAMS += pabrowse endif -bin_SCRIPTS = esdcompat start-pulseaudio-x11 start-pulseaudio-kde - pacat_SOURCES = utils/pacat.c pacat_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la $(LIBSNDFILE_LIBS) pacat_CFLAGS = $(AM_CFLAGS) $(LIBSNDFILE_CFLAGS) @@ -1183,7 +1186,7 @@ pulselibexec_PROGRAMS += \ gconf-helper endif -if OS_IS_WIN32 +if HAVE_WAVEOUT modlibexec_LTLIBRARIES += \ module-waveout.la endif -- cgit From aebf66bef6ebc8561b3cd4bfb4189ea739056f65 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 17 Feb 2011 11:50:10 +0100 Subject: Use pa_* instead of generic functions to improve portability --- src/pulsecore/inet_ntop.c | 4 +++- src/pulsecore/inet_pton.c | 4 +++- src/tests/asyncq-test.c | 2 +- src/tests/rtstutter.c | 19 ++++++++----------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/pulsecore/inet_ntop.c b/src/pulsecore/inet_ntop.c index 64c28edb..059b25cc 100644 --- a/src/pulsecore/inet_ntop.c +++ b/src/pulsecore/inet_ntop.c @@ -29,6 +29,7 @@ #ifndef HAVE_INET_NTOP #include +#include #include #include "inet_ntop.h" @@ -39,7 +40,8 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { struct in6_addr *in6 = (struct in6_addr*)src; #endif - assert(src && dst); + pa_assert(src); + pa_assert(dst); switch (af) { case AF_INET: diff --git a/src/pulsecore/inet_pton.c b/src/pulsecore/inet_pton.c index 198d1a0d..efb15263 100644 --- a/src/pulsecore/inet_pton.c +++ b/src/pulsecore/inet_pton.c @@ -28,6 +28,7 @@ #ifndef HAVE_INET_PTON +#include #include #include "inet_pton.h" @@ -38,7 +39,8 @@ int inet_pton(int af, const char *src, void *dst) { struct in6_addr *in6 = (struct in6_addr*)dst; #endif - assert(src && dst); + pa_assert(src); + pa_assert(dst); switch (af) { case AF_INET: diff --git a/src/tests/asyncq-test.c b/src/tests/asyncq-test.c index 538bbb17..eae8cce9 100644 --- a/src/tests/asyncq-test.c +++ b/src/tests/asyncq-test.c @@ -51,7 +51,7 @@ static void consumer(void *_q) { void *p; int i; - sleep(1); + pa_msleep(1000); for (i = 0;; i++) { p = pa_asyncq_pop(q, TRUE); diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c index 21f33bf2..21e3cdeb 100644 --- a/src/tests/rtstutter.c +++ b/src/tests/rtstutter.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -34,25 +33,24 @@ #include #endif +#include #include #include #include #include +#include #include static int msec_lower, msec_upper; -static void* work(void *p) PA_GCC_NORETURN; +static void work(void *p) PA_GCC_NORETURN; -static void* work(void *p) { - struct sched_param param; +static void work(void *p) { pa_log_notice("CPU%i: Created thread.", PA_PTR_TO_UINT(p)); - memset(¶m, 0, sizeof(param)); - param.sched_priority = 12; - pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) == 0); + pa_make_realtime(12); #ifdef HAVE_PTHREAD_SETAFFINITY_NP { @@ -69,7 +67,7 @@ static void* work(void *p) { uint64_t nsec; pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p)); - sleep(1); + pa_msleep(1000); #ifdef CLOCK_REALTIME pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0); @@ -101,7 +99,7 @@ static void* work(void *p) { int main(int argc, char*argv[]) { unsigned n; - pa_log_set_level(PA_LOG_DEBUG); + pa_log_set_level(PA_LOG_INFO); srand((unsigned) time(NULL)); @@ -122,8 +120,7 @@ int main(int argc, char*argv[]) { pa_log_notice("Creating random latencies in the range of %ims to %ims.", msec_lower, msec_upper); for (n = 1; n < pa_ncpus(); n++) { - pthread_t t; - pa_assert_se(pthread_create(&t, NULL, work, PA_UINT_TO_PTR(n)) == 0); + pa_assert_se(pa_thread_new("rtstutter", work, PA_UINT_TO_PTR(n))); } work(PA_INT_TO_PTR(0)); -- cgit From 30c7c9518440670ca3b627298c4e32885204882f Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 18 Jan 2011 11:28:53 +0100 Subject: tests/rtstutter: Use pa_rtclock --- src/tests/rtstutter.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c index 21e3cdeb..9ef835c3 100644 --- a/src/tests/rtstutter.c +++ b/src/tests/rtstutter.c @@ -41,6 +41,7 @@ #include #include #include +#include static int msec_lower, msec_upper; @@ -63,36 +64,24 @@ static void work(void *p) { #endif for (;;) { - struct timespec now, end; - uint64_t nsec; + struct timeval now, end; + uint64_t usec; pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p)); pa_msleep(1000); -#ifdef CLOCK_REALTIME - pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0); -#endif - - nsec = - (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) + - (uint64_t) ((uint64_t) msec_lower*PA_NSEC_PER_MSEC); + usec = + (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_USEC_PER_MSEC)/RAND_MAX) + + (uint64_t) ((uint64_t) msec_lower*PA_USEC_PER_MSEC); - pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (nsec/PA_NSEC_PER_MSEC)); + pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (usec/PA_USEC_PER_MSEC)); - end.tv_sec += (time_t) (nsec / PA_NSEC_PER_SEC); - end.tv_nsec += (long int) (nsec % PA_NSEC_PER_SEC); - - while ((pa_usec_t) end.tv_nsec > PA_NSEC_PER_SEC) { - end.tv_sec++; - end.tv_nsec -= (long int) PA_NSEC_PER_SEC; - } + pa_rtclock_get(&end); + pa_timeval_add(&end, usec); do { -#ifdef CLOCK_REALTIME - pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0); -#endif - } while (now.tv_sec < end.tv_sec || - (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec)); + pa_rtclock_get(&now); + } while (pa_timeval_cmp(&now, &end) < 0); } } -- cgit From 821562b9bc8d1a9033daaae0fd5373498a085054 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Wed, 5 Jan 2011 19:50:44 +0100 Subject: Use pa_read, pa_write and pa_poll instead of system functions --- src/daemon/cpulimit.c | 2 +- src/pulse/thread-mainloop.c | 2 +- src/pulsecore/fdsem.c | 18 +++++++++--------- src/pulsecore/lock-autospawn.c | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index f5042a75..c1c2a6f6 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -140,7 +140,7 @@ static void signal_handler(int sig) { write_err("Soft CPU time limit exhausted, terminating.\n"); /* Try a soft cleanup */ - (void) write(the_pipe[1], &c, sizeof(c)); + (void) pa_write(the_pipe[1], &c, sizeof(c), NULL); phase = PHASE_SOFT; reset_cpu_time(CPUTIME_INTERVAL_HARD); diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c index d8c82c8c..ef4ef56e 100644 --- a/src/pulse/thread-mainloop.c +++ b/src/pulse/thread-mainloop.c @@ -67,7 +67,7 @@ static int poll_func(struct pollfd *ufds, unsigned long nfds, int timeout, void * avahi_simple_poll_quit() can succeed from another thread. */ pa_mutex_unlock(mutex); - r = poll(ufds, nfds, timeout); + r = pa_poll(ufds, nfds, timeout); pa_mutex_lock(mutex); return r; diff --git a/src/pulsecore/fdsem.c b/src/pulsecore/fdsem.c index 5bf99479..62380451 100644 --- a/src/pulsecore/fdsem.c +++ b/src/pulsecore/fdsem.c @@ -154,7 +154,7 @@ static void flush(pa_fdsem *f) { if (f->efd >= 0) { uint64_t u; - if ((r = read(f->efd, &u, sizeof(u))) != sizeof(u)) { + if ((r = pa_read(f->efd, &u, sizeof(u), NULL)) != sizeof(u)) { if (r >= 0 || errno != EINTR) { pa_log_error("Invalid read from eventfd: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); @@ -167,7 +167,7 @@ static void flush(pa_fdsem *f) { } else #endif - if ((r = read(f->fds[0], &x, sizeof(x))) <= 0) { + if ((r = pa_read(f->fds[0], &x, sizeof(x), NULL)) <= 0) { if (r >= 0 || errno != EINTR) { pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); @@ -197,9 +197,9 @@ void pa_fdsem_post(pa_fdsem *f) { if (f->efd >= 0) { uint64_t u = 1; - if ((r = write(f->efd, &u, sizeof(u))) != sizeof(u)) { + if ((r = pa_write(f->efd, &u, sizeof(u), NULL)) != sizeof(u)) { if (r >= 0 || errno != EINTR) { - pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); + pa_log_error("Invalid write to eventfd: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); pa_assert_not_reached(); } @@ -208,9 +208,9 @@ void pa_fdsem_post(pa_fdsem *f) { } else #endif - if ((r = write(f->fds[1], &x, 1)) != 1) { + if ((r = pa_write(f->fds[1], &x, 1, NULL)) != 1) { if (r >= 0 || errno != EINTR) { - pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); + pa_log_error("Invalid write to pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); pa_assert_not_reached(); } @@ -241,10 +241,10 @@ void pa_fdsem_wait(pa_fdsem *f) { if (f->efd >= 0) { uint64_t u; - if ((r = read(f->efd, &u, sizeof(u))) != sizeof(u)) { + if ((r = pa_read(f->efd, &u, sizeof(u), NULL)) != sizeof(u)) { if (r >= 0 || errno != EINTR) { - pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); + pa_log_error("Invalid read from eventfd: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); pa_assert_not_reached(); } @@ -255,7 +255,7 @@ void pa_fdsem_wait(pa_fdsem *f) { } else #endif - if ((r = read(f->fds[0], &x, sizeof(x))) <= 0) { + if ((r = pa_read(f->fds[0], &x, sizeof(x), NULL)) <= 0) { if (r >= 0 || errno != EINTR) { pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF"); diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c index 1a082db6..a9c942fb 100644 --- a/src/pulsecore/lock-autospawn.c +++ b/src/pulsecore/lock-autospawn.c @@ -161,7 +161,7 @@ static void ping(void) { for (;;) { char x = 'x'; - if ((s = write(pipe_fd[1], &x, 1)) == 1) + if ((s = pa_write(pipe_fd[1], &x, 1, NULL)) == 1) break; pa_assert(s < 0); @@ -188,7 +188,7 @@ static void wait_for_ping(void) { if ((k = pa_poll(&pfd, 1, -1)) != 1) { pa_assert(k < 0); pa_assert(errno == EINTR); - } else if ((s = read(pipe_fd[0], &x, 1)) != 1) { + } else if ((s = pa_read(pipe_fd[0], &x, 1, NULL)) != 1) { pa_assert(s < 0); pa_assert(errno == EAGAIN); } @@ -200,7 +200,7 @@ static void empty_pipe(void) { pa_assert(pipe_fd[0] >= 0); - if ((s = read(pipe_fd[0], &x, sizeof(x))) < 1) { + if ((s = pa_read(pipe_fd[0], &x, sizeof(x), NULL)) < 1) { pa_assert(s < 0); pa_assert(errno == EAGAIN); } -- cgit