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. ####
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")
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+
+#ifdef HAVE_SCHED_H
#include <sched.h>
+#endif
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
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;
}
}
+#ifndef OS_IS_WIN32
extern const lt_dlsymlist lt_preloaded_symbols[];
+#endif
static int is_preloaded(const char *name) {
const lt_dlsymlist *l;
#undef PA_BIND_NOW
#endif
+#ifdef OS_IS_WIN32
+#undef PA_BIND_NOW
+#endif
+
#ifdef PA_BIND_NOW
/*
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. */
goto finish;
}
#endif
+#endif /* HAVE_GETUID */
if (conf->cmd == PA_CMD_START && conf->system_instance) {
pa_log(_("--start not supported for system instances."));
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))) {
}
closedir(desktopfiles_dir);
}
+#endif
}
if (!found) {
r->good = FALSE;
* 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.");
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
+
+#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
+#endif
+
+#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
+#endif
#ifdef HAVE_LINUX_SOCKIOS_H
#include <linux/sockios.h>
return NULL;
}
+#ifdef HAVE_GETUID
if (st.st_uid != getuid()) {
pa_xfree(p);
return NULL;
}
+#endif
return p;
}
return NULL;
}
+#ifdef HAVE_GETUID
if (st.st_uid != getuid()) {
pa_xfree(p);
return NULL;
}
+#endif
return p;
}
/* 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 {
if (api)
c->spawn_api = *api;
}
+#endif
}
pa_context_set_state(c, PA_CONTEXT_CONNECTING);
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
return tv;
}
+#ifdef HAVE_CLOCK_GETTIME
pa_usec_t pa_timespec_load(const struct timespec *ts) {
if (PA_UNLIKELY(!ts))
return ts;
}
+#endif
static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
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);
#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>
+#endif
#ifdef HAVE_STRTOF_L
#include <locale.h>
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|
#endif
pa_assert_se(pa_close(fd) >= 0);
-
#endif
#ifdef HAVE_LSTAT
}
static int set_scheduler(int rtprio) {
+#ifdef HAVE_SCHED_H
struct sched_param sp;
#ifdef HAVE_DBUS
int r;
pa_log_debug("SCHED_RR worked.");
return 0;
}
+#endif /* HAVE_SCHED_H */
#ifdef HAVE_DBUS
/* Try to talk to RealtimeKit */
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 */
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])
if (expr[0])
if (pa_match(expr, v) > 0)
return 0;
+#endif
errno = EINVAL;
return -1;
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);
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);
if (!(p = make_random_dir(m)))
return -1;
+#ifdef HAVE_SYMLINK
if (symlink(p, k) < 0) {
int saved_errno = errno;
errno = saved_errno;
return -1;
}
+#endif
pa_xfree(p);
return 0;
/* Hmm, so this symlink is still around, make sure nobody fools
* us */
+#ifdef HAVE_LSTAT
if (lstat(p, &st) < 0) {
if (errno != ENOENT) {
pa_log_info("Hmm, runtime path exists, but points to an invalid directory. Changing runtime directory.");
}
+#endif
pa_xfree(p);
p = NULL;
}
char *pa_readlink(const char *p) {
+#ifdef HAVE_READLINK
size_t l = 100;
for (;;) {
pa_xfree(c);
l *= 2;
}
+#else
+ return NULL;
+#endif
}
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;
if (pa_close(fd) < 0 && errno != EBADF)
return -1;
}
+#endif /* !OS_IS_WIN32 */
return 0;
}
}
int pa_unblock_sigsv(const int except[]) {
+#ifndef OS_IS_WIN32
int i;
sigset_t ss;
return -1;
return sigprocmask(SIG_SETMASK, &ss, NULL);
+#else
+ return 0;
+#endif
}
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++) {
return -1;
}
}
+#endif
return 0;
}
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) {
#ifndef fooinet_ntophfoo
#define fooinet_ntophfoo
+#ifndef HAVE_INET_NTOP
+
#include <pulsecore/socket.h>
const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
#endif
+
+#endif
#ifndef fooinet_ptonhfoo
#define fooinet_ptonhfoo
+#ifndef HAVE_INET_PTON
+
#include <pulsecore/socket.h>
int inet_pton(int af, const char *src, void *dst);
#endif
+
+#endif
#include <errno.h>
#include <string.h>
#include <signal.h>
+
+#ifdef HAVE_PTHREAD
#include <pthread.h>
+#endif
#include <pulse/i18n.h>
#include <pulse/xmalloc.h>
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."));
#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)
(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;
sigsafe_error("Failed to handle SIGBUS.\n");
abort();
}
+#endif
static void memtrap_link(pa_memtrap *m, unsigned j) {
pa_assert(m);
}
void pa_memtrap_install(void) {
+#ifdef HAVE_SIGACTION
struct sigaction sa;
allocate_aupdate();
sa.sa_flags = SA_RESTART|SA_SIGINFO;
pa_assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
+#endif
}
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;
execl(name, name, argv1, NULL);
_exit(1);
}
+#endif
fail:
pa_close_pipe(pipe_fds);
} \
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) \
#include <sched.h>
#include <inttypes.h>
#include <string.h>
+
+#ifdef HAVE_PTHREAD
#include <pthread.h>
+#endif
#include <pulse/timeval.h>
#include <pulse/gccmacro.h>
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));
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 (;;) {