Merge remote-tracking branch 'mkbosmans/mingw32-build'

This commit is contained in:
Colin Guthrie 2011-02-25 09:24:07 +00:00
commit a3dbdb0446
67 changed files with 719 additions and 449 deletions

View file

@ -31,7 +31,6 @@
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
@ -151,7 +150,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;

View file

@ -40,12 +40,20 @@
#include <unistd.h>
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#include <pulse/timeval.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-error.h>
#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
}
@ -174,6 +204,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 +229,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) {

View file

@ -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);

View file

@ -34,16 +34,24 @@
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <dirent.h>
#include <regex.h>
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
#ifdef HAVE_UNAME
#include <sys/utsname.h>
#include <sys/socket.h>
#endif
#if defined(HAVE_REGEX_H)
#include <regex.h>
#elif defined(HAVE_PCREPOSIX_H)
#include <pcreposix.h>
#endif
#ifdef HAVE_STRTOF_L
#include <locale.h>
@ -81,6 +89,10 @@
#include <windows.h>
#endif
#ifndef ENOTSUP
#define ENOTSUP 135
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
@ -110,7 +122,7 @@
#include <pulse/utf8.h>
#include <pulsecore/core-error.h>
#include <pulsecore/winsock.h>
#include <pulsecore/socket.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/thread.h>
@ -118,6 +130,7 @@
#include <pulsecore/usergroup.h>
#include <pulsecore/strlist.h>
#include <pulsecore/cpu-x86.h>
#include <pulsecore/pipe.h>
#include "core-util.h"
@ -136,20 +149,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;
@ -217,7 +228,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|
@ -255,7 +266,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
@ -611,6 +621,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;
@ -634,6 +645,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 */
@ -684,14 +696,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_warn("SetThreadPriority() failed: 0x%08X", GetLastError());
errno = EPERM;
#else
errno = ENOTSUP;
#endif
pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno));
return -1;
#else
errno = ENOTSUP;
return -1;
#endif
}
static int set_nice(int nice_level) {
@ -703,10 +722,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 */
@ -827,6 +848,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])
@ -837,6 +859,7 @@ int pa_parse_boolean(const char *v) {
if (expr[0])
if (pa_match(expr, v) > 0)
return 0;
#endif
errno = EINVAL;
return -1;
@ -1150,23 +1173,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;
}
@ -1339,11 +1362,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);
@ -1441,7 +1466,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);
@ -1464,6 +1493,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;
@ -1476,6 +1506,10 @@ 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);
return 0;
@ -1534,6 +1568,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 */
@ -1546,6 +1581,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;
}
@ -1560,6 +1600,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) {
@ -1579,6 +1620,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;
@ -2218,6 +2260,7 @@ void pa_close_pipe(int fds[2]) {
}
char *pa_readlink(const char *p) {
#ifdef HAVE_READLINK
size_t l = 100;
for (;;) {
@ -2239,6 +2282,9 @@ char *pa_readlink(const char *p) {
pa_xfree(c);
l *= 2;
}
#else
return NULL;
#endif
}
int pa_close_all(int except_fd, ...) {
@ -2277,6 +2323,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;
@ -2366,6 +2413,7 @@ int pa_close_allv(const int except_fds[]) {
if (pa_close(fd) < 0 && errno != EBADF)
return -1;
}
#endif /* !OS_IS_WIN32 */
return 0;
}
@ -2406,6 +2454,7 @@ int pa_unblock_sigs(int except, ...) {
}
int pa_unblock_sigsv(const int except[]) {
#ifndef OS_IS_WIN32
int i;
sigset_t ss;
@ -2417,6 +2466,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, ...) {
@ -2455,6 +2507,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++) {
@ -2491,6 +2544,7 @@ int pa_reset_sigsv(const int except[]) {
return -1;
}
}
#endif
return 0;
}
@ -2501,7 +2555,11 @@ void pa_set_env(const char *key, const char *value) {
/* This is not thread-safe */
putenv(pa_sprintf_malloc("%s=%s", key, value));
#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) {
@ -2526,7 +2584,11 @@ void pa_unset_env_recorded(void) {
if (!s)
break;
#ifdef OS_IS_WIN32
SetEnvironmentVariable(s, NULL);
#else
unsetenv(s);
#endif
pa_xfree(s);
}
}
@ -2625,9 +2687,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) {
@ -2640,11 +2706,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
@ -2793,10 +2870,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."

View file

@ -28,7 +28,6 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
@ -36,6 +35,7 @@
#include <pulse/gccmacro.h>
#include <pulsecore/macro.h>
#include <pulsecore/socket.h>
#ifndef PACKAGE
#error "Please include config.h before including this file!"

View file

@ -28,9 +28,7 @@
#error "Please include config.h before including this file!"
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <pulsecore/socket.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>

View file

@ -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");

View file

@ -28,11 +28,9 @@
#ifndef HAVE_INET_NTOP
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include "winsock.h"
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include <pulsecore/socket.h>
#include "inet_ntop.h"
@ -42,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:

View file

@ -1,12 +1,12 @@
#ifndef fooinet_ntophfoo
#define fooinet_ntophfoo
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifndef HAVE_INET_NTOP
#include "winsock.h"
#include <pulsecore/socket.h>
const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
#endif
#endif

View file

@ -28,11 +28,8 @@
#ifndef HAVE_INET_PTON
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include "winsock.h"
#include <pulsecore/macro.h>
#include <pulsecore/socket.h>
#include "inet_pton.h"
@ -42,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:

View file

@ -1,12 +1,12 @@
#ifndef fooinet_ptonhfoo
#define fooinet_ptonhfoo
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifndef HAVE_INET_PTON
#include "winsock.h"
#include <pulsecore/socket.h>
int inet_pton(int af, const char *src, void *dst);
#endif
#endif

View file

@ -28,19 +28,16 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#include "winsock.h"
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>

View file

@ -30,7 +30,7 @@
#include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>

View file

@ -28,9 +28,6 @@
#include <sys/types.h>
#include <string.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@ -50,10 +47,10 @@
#include <pulsecore/llist.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/winsock.h>
#include <pulsecore/socket.h>
#ifndef HAVE_INET_PTON
#include "inet_pton.h"
#include <pulsecore/inet_pton.h>
#endif
#include "ipacl.h"

View file

@ -26,9 +26,11 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/poll.h>
#include <signal.h>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
#include <pulse/i18n.h>
#include <pulse/xmalloc.h>
@ -159,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);
@ -186,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);
}
@ -198,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);
}
@ -207,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."));

View file

@ -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);

View file

@ -23,8 +23,6 @@
#include <config.h>
#endif
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View file

@ -24,7 +24,10 @@
#endif
#include <signal.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#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
}

View file

@ -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;
}

View file

@ -25,14 +25,17 @@
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#include <sys/socket.h>
#endif
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include <pulsecore/inet_pton.h>
#include "parseaddr.h"

View file

@ -29,11 +29,8 @@
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include "winsock.h"
#include <pulsecore/socket.h>
#include <pulsecore/core-util.h>
#include "pipe.h"

View file

@ -45,8 +45,7 @@
#include <sys/select.h>
#endif
#include "winsock.h"
#include <pulsecore/socket.h>
#include <pulsecore/core-util.h>
#include <pulse/util.h>
@ -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 ||

View file

@ -25,7 +25,7 @@
#include <string.h>
#include <locale.h>
#include <dlfcn.h>
#include <libintl.h>
#ifdef __APPLE__
#include <crt_externs.h>

View file

@ -28,9 +28,6 @@
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@ -38,10 +35,9 @@
#include <netinet/in.h>
#endif
#include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/socket.h>
#include <pulsecore/queue.h>
#include <pulsecore/log.h>
#include <pulsecore/core-scache.h>

View file

@ -31,6 +31,11 @@
#include <stdlib.h>
#include <time.h>
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#include <wincrypt.h>
#endif
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
@ -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 */

View file

@ -40,7 +40,6 @@
#include <pulsecore/llist.h>
#include <pulsecore/flist.h>
#include <pulsecore/core-util.h>
#include <pulsecore/winsock.h>
#include <pulsecore/ratelimit.h>
#include <pulse/rtclock.h>

View file

@ -32,9 +32,6 @@
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@ -56,9 +53,9 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/socket-util.h>
@ -525,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);

View file

@ -32,9 +32,6 @@
#include <unistd.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#ifndef SUN_LEN
@ -54,18 +51,16 @@
#endif
#ifndef HAVE_INET_NTOP
#include "inet_ntop.h"
#include <pulsecore/inet_ntop.h>
#endif
#ifndef HAVE_INET_PTON
#include "inet_pton.h"
#include <pulsecore/inet_pton.h>
#endif
#include "winsock.h"
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>

View file

@ -36,9 +36,6 @@
#include <unistd.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@ -62,17 +59,16 @@
#endif
#ifndef HAVE_INET_NTOP
#include "inet_ntop.h"
#include <pulsecore/inet_ntop.h>
#endif
#include "winsock.h"
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/socket.h>
#include "socket-util.h"

View file

@ -24,8 +24,8 @@
***/
#include <sys/types.h>
#include <sys/socket.h>
#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
void pa_socket_peer_to_string(int fd, char *c, size_t l);

View file

@ -1,5 +1,9 @@
#ifndef foowinsockhfoo
#define foowinsockhfoo
#ifndef foopulsecoresockethfoo
#define foopulsecoresockethfoo
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
@ -14,6 +18,7 @@
#define ECONNREFUSED WSAECONNREFUSED
#define EHOSTUNREACH WSAEHOSTUNREACH
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EADDRINUSE WSAEADDRINUSE
typedef long suseconds_t;

View file

@ -40,6 +40,7 @@
#include <pulsecore/core-util.h>
#include <pulsecore/core-error.h>
#include <pulsecore/pipe.h>
#include "start-child.h"
@ -47,6 +48,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 +106,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);

View file

@ -35,7 +35,7 @@
#include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
#include "tagstruct.h"

View file

@ -25,7 +25,6 @@
#include <inttypes.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <pulse/sample.h>
#include <pulse/channelmap.h>

View file

@ -27,7 +27,7 @@
#include <pulsecore/rtpoll.h>
/* 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 {

View file

@ -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);

View file

@ -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) \