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