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(-) (limited to 'src/pulsecore') 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/pulsecore/lock-autospawn.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/pulsecore') 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/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 -------------------------- 22 files changed, 62 insertions(+), 102 deletions(-) create mode 100644 src/pulsecore/socket.h delete mode 100644 src/pulsecore/winsock.h (limited to 'src/pulsecore') 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 -- 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/pulsecore/mutex-win32.c | 25 ++++++++++++++++++++++++- src/pulsecore/thread-win32.c | 5 +++-- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src/pulsecore') 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 --- 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 +- 9 files changed, 67 insertions(+), 3 deletions(-) (limited to 'src/pulsecore') 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) \ -- 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 --- src/pulsecore/core-util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/pulsecore') 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/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 + 6 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/pulsecore') 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" -- 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(-) (limited to 'src/pulsecore') 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/pulsecore/authkey.c | 2 +- src/pulsecore/core-util.c | 62 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src/pulsecore') 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(+) (limited to 'src/pulsecore') 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/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 - 5 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src/pulsecore') 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(-) (limited to 'src/pulsecore') 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 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 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/pulsecore') 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: -- 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/pulsecore/fdsem.c | 18 +++++++++--------- src/pulsecore/lock-autospawn.c | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/pulsecore') 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