From: Maarten Bosmans Date: Wed, 5 Jan 2011 23:51:33 +0000 (+0100) Subject: Apply #ifdefs around functionality not available on win32 X-Git-Tag: 1.0_branch~697^2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb12ff83564d43566089dd979639c6993ba76665;p=profile%2Fivi%2Fpulseaudio.git Apply #ifdefs around functionality not available on win32 And also the reverse: around some win32 specific functionality --- diff --git a/configure.ac b/configure.ac index 08c947a..42d9c3b 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 74e8135..3339f3b 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 92470b4..d0504dc 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 276b2a0..2ba73ce 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 cab275f..5aeb9bc 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 30df69d..bdeee29 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 c5ff456..90ce3b6 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 9eba8ac..5a1391d 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 ca81650..8f632b5 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 3206e94..c5cfc8c 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 110158b..a69b466 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 3b393ed..6253536 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 3ce5edb..4c4fbfe 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 7e1b203..77ace6a 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 9d9c476..913efc4 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 b515057..1a082db 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 4fc1821..b56d806 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 4a70aea..dabcfa5 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 aea0276..79b61ae 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 c93fee9..21f33bf 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 (;;) {