summaryrefslogtreecommitdiffstats
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/.gitignore3
l---------src/daemon/Makefile1
-rw-r--r--src/daemon/caps.c142
-rw-r--r--src/daemon/caps.h16
-rw-r--r--src/daemon/cmdline.c234
-rw-r--r--src/daemon/cmdline.h12
-rw-r--r--src/daemon/cpulimit.c118
-rw-r--r--src/daemon/cpulimit.h12
-rw-r--r--src/daemon/daemon-conf.c712
-rw-r--r--src/daemon/daemon-conf.h90
-rw-r--r--src/daemon/daemon.conf.in128
-rwxr-xr-xsrc/daemon/default.pa.in159
-rw-r--r--src/daemon/default.pa.win3243
-rw-r--r--src/daemon/dumpmodules.c70
-rw-r--r--src/daemon/dumpmodules.h6
-rwxr-xr-xsrc/daemon/esdcompat.in6
-rw-r--r--src/daemon/ltdl-bind-now.c161
-rw-r--r--src/daemon/ltdl-bind-now.h30
-rw-r--r--src/daemon/main.c1049
-rw-r--r--src/daemon/pulseaudio-kde.desktop.in11
-rw-r--r--src/daemon/pulseaudio-system.conf37
-rw-r--r--src/daemon/pulseaudio.desktop.in10
-rw-r--r--src/daemon/server-lookup.c522
-rw-r--r--src/daemon/server-lookup.h40
-rwxr-xr-xsrc/daemon/start-pulseaudio-kde.in30
-rwxr-xr-xsrc/daemon/start-pulseaudio-x11.in32
-rwxr-xr-xsrc/daemon/system.pa.in59
27 files changed, 2896 insertions, 837 deletions
diff --git a/src/daemon/.gitignore b/src/daemon/.gitignore
new file mode 100644
index 00000000..54e4299b
--- /dev/null
+++ b/src/daemon/.gitignore
@@ -0,0 +1,3 @@
+org.pulseaudio.policy
+pulseaudio.desktop
+pulseaudio-kde.desktop
diff --git a/src/daemon/Makefile b/src/daemon/Makefile
deleted file mode 120000
index c110232d..00000000
--- a/src/daemon/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-../pulse/Makefile \ No newline at end of file
diff --git a/src/daemon/caps.c b/src/daemon/caps.c
index 957824d9..74ccb1c8 100644
--- a/src/daemon/caps.c
+++ b/src/daemon/caps.c
@@ -1,18 +1,19 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -23,19 +24,22 @@
#include <config.h>
#endif
-#include <assert.h>
#include <unistd.h>
#include <errno.h>
-#include <string.h>
#include <sys/types.h>
+#include <pulse/i18n.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/log.h>
+
#ifdef HAVE_SYS_CAPABILITY_H
#include <sys/capability.h>
#endif
-#include <pulsecore/core-error.h>
-
-#include <pulsecore/log.h>
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
#include "caps.h"
@@ -45,105 +49,47 @@ int setresgid(gid_t r, gid_t e, gid_t s);
int setresuid(uid_t r, uid_t e, uid_t s);
#endif
-#ifdef HAVE_GETUID
-
/* Drop root rights when called SUID root */
void pa_drop_root(void) {
- uid_t uid = getuid();
-
- if (uid == 0 || geteuid() != 0)
- return;
- pa_log_info(__FILE__": dropping root rights.");
+#ifdef HAVE_GETUID
+ uid_t uid;
+ gid_t gid;
+
+ pa_log_debug(_("Cleaning up privileges."));
+ uid = getuid();
+ gid = getgid();
#if defined(HAVE_SETRESUID)
- setresuid(uid, uid, uid);
+ pa_assert_se(setresuid(uid, uid, uid) >= 0);
+ pa_assert_se(setresgid(gid, gid, gid) >= 0);
#elif defined(HAVE_SETREUID)
- setreuid(uid, uid);
+ pa_assert_se(setreuid(uid, uid) >= 0);
+ pa_assert_se(setregid(gid, gid) >= 0);
#else
- setuid(uid);
- seteuid(uid);
+ pa_assert_se(setuid(uid) >= 0);
+ pa_assert_se(seteuid(uid) >= 0);
+ pa_assert_se(setgid(gid) >= 0);
+ pa_assert_se(setegid(gid) >= 0);
#endif
-}
-
-#else
-void pa_drop_root(void) {
-}
+ pa_assert_se(getuid() == uid);
+ pa_assert_se(geteuid() == uid);
+ pa_assert_se(getgid() == gid);
+ pa_assert_se(getegid() == gid);
+#endif
+#ifdef HAVE_SYS_PRCTL_H
+ pa_assert_se(prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0) == 0);
#endif
#ifdef HAVE_SYS_CAPABILITY_H
-
-/* Limit capabilities set to CAPSYS_NICE */
-int pa_limit_caps(void) {
- int r = -1;
- cap_t caps;
- cap_value_t nice_cap = CAP_SYS_NICE;
-
- /* Only drop caps when called SUID */
- if (getuid() != 0)
- return 0;
-
- caps = cap_init();
- assert(caps);
-
- cap_clear(caps);
-
- cap_set_flag(caps, CAP_EFFECTIVE, 1, &nice_cap, CAP_SET);
- cap_set_flag(caps, CAP_PERMITTED, 1, &nice_cap, CAP_SET);
-
- if (cap_set_proc(caps) < 0)
- goto fail;
-
- pa_log_info(__FILE__": dropped capabilities successfully.");
-
- r = 0;
-
-fail:
- cap_free (caps);
-
- return r;
-}
-
-/* Drop all capabilities, effectively becoming a normal user */
-int pa_drop_caps(void) {
- cap_t caps;
- int r = -1;
-
- /* Only drop caps when called SUID */
- if (getuid() != 0)
- return 0;
-
- caps = cap_init();
- assert(caps);
-
- cap_clear(caps);
-
- if (cap_set_proc(caps) < 0) {
- pa_log(__FILE__": failed to drop capabilities: %s", pa_cstrerror(errno));
- goto fail;
+ if (uid != 0) {
+ cap_t caps;
+ pa_assert_se(caps = cap_init());
+ pa_assert_se(cap_clear(caps) == 0);
+ pa_assert_se(cap_set_proc(caps) == 0);
+ pa_assert_se(cap_free(caps) == 0);
}
-
- r = 0;
-
-fail:
- cap_free (caps);
-
- return r;
-}
-
-#else
-
-/* NOOPs in case capabilities are not available. */
-int pa_limit_caps(void) {
- return 0;
-}
-
-int pa_drop_caps(void) {
- pa_drop_root();
- return 0;
-}
-
#endif
-
+}
diff --git a/src/daemon/caps.h b/src/daemon/caps.h
index 8a618286..5d0ee62e 100644
--- a/src/daemon/caps.h
+++ b/src/daemon/caps.h
@@ -1,29 +1,29 @@
#ifndef foocapshfoo
#define foocapshfoo
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
+#include <pulsecore/macro.h>
+
void pa_drop_root(void);
-int pa_limit_caps(void);
-int pa_drop_caps(void);
#endif
diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c
index ab876edf..ec37d46b 100644
--- a/src/daemon/cmdline.c
+++ b/src/daemon/cmdline.c
@@ -1,18 +1,18 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -23,17 +23,17 @@
#include <config.h>
#endif
-#include <string.h>
-#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
-#include <sys/stat.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
+#include <pulse/util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/strbuf.h>
+#include <pulsecore/macro.h>
#include "cmdline.h"
@@ -47,11 +47,15 @@ enum {
ARG_FAIL,
ARG_LOG_LEVEL,
ARG_HIGH_PRIORITY,
+ ARG_REALTIME,
ARG_DISALLOW_MODULE_LOADING,
+ ARG_DISALLOW_EXIT,
ARG_EXIT_IDLE_TIME,
- ARG_MODULE_IDLE_TIME,
ARG_SCACHE_IDLE_TIME,
ARG_LOG_TARGET,
+ ARG_LOG_META,
+ ARG_LOG_TIME,
+ ARG_LOG_BACKTRACE,
ARG_LOAD,
ARG_FILE,
ARG_DL_SEARCH_PATH,
@@ -59,11 +63,16 @@ enum {
ARG_KILL,
ARG_USE_PID_FILE,
ARG_CHECK,
- ARG_SYSTEM
+ ARG_NO_CPU_LIMIT,
+ ARG_DISABLE_SHM,
+ ARG_DUMP_RESAMPLE_METHODS,
+ ARG_SYSTEM,
+ ARG_CLEANUP_SHM,
+ ARG_START
};
/* Tabel for getopt_long() */
-static struct option long_options[] = {
+static const struct option long_options[] = {
{"help", 0, 0, ARG_HELP},
{"version", 0, 0, ARG_VERSION},
{"dump-conf", 0, 0, ARG_DUMP_CONF},
@@ -73,46 +82,59 @@ static struct option long_options[] = {
{"verbose", 2, 0, ARG_LOG_LEVEL},
{"log-level", 2, 0, ARG_LOG_LEVEL},
{"high-priority", 2, 0, ARG_HIGH_PRIORITY},
+ {"realtime", 2, 0, ARG_REALTIME},
{"disallow-module-loading", 2, 0, ARG_DISALLOW_MODULE_LOADING},
+ {"disallow-exit", 2, 0, ARG_DISALLOW_EXIT},
{"exit-idle-time", 2, 0, ARG_EXIT_IDLE_TIME},
- {"module-idle-time", 2, 0, ARG_MODULE_IDLE_TIME},
{"scache-idle-time", 2, 0, ARG_SCACHE_IDLE_TIME},
{"log-target", 1, 0, ARG_LOG_TARGET},
+ {"log-meta", 2, 0, ARG_LOG_META},
+ {"log-time", 2, 0, ARG_LOG_TIME},
+ {"log-backtrace", 1, 0, ARG_LOG_BACKTRACE},
{"load", 1, 0, ARG_LOAD},
{"file", 1, 0, ARG_FILE},
{"dl-search-path", 1, 0, ARG_DL_SEARCH_PATH},
{"resample-method", 1, 0, ARG_RESAMPLE_METHOD},
{"kill", 0, 0, ARG_KILL},
+ {"start", 0, 0, ARG_START},
{"use-pid-file", 2, 0, ARG_USE_PID_FILE},
{"check", 0, 0, ARG_CHECK},
{"system", 2, 0, ARG_SYSTEM},
+ {"no-cpu-limit", 2, 0, ARG_NO_CPU_LIMIT},
+ {"disable-shm", 2, 0, ARG_DISABLE_SHM},
+ {"dump-resample-methods", 2, 0, ARG_DUMP_RESAMPLE_METHODS},
+ {"cleanup-shm", 2, 0, ARG_CLEANUP_SHM},
{NULL, 0, 0, 0}
};
void pa_cmdline_help(const char *argv0) {
- const char *e;
-
- if ((e = strrchr(argv0, '/')))
- e++;
- else
- e = argv0;
-
- printf("%s [options]\n\n"
+ pa_assert(argv0);
+
+ printf(_("%s [options]\n\n"
"COMMANDS:\n"
" -h, --help Show this help\n"
" --version Show version\n"
" --dump-conf Dump default configuration\n"
" --dump-modules Dump list of available modules\n"
+ " --dump-resample-methods Dump available resample methods\n"
+ " --cleanup-shm Cleanup stale shared memory segments\n"
+ " --start Start the daemon if it is not running\n"
" -k --kill Kill a running daemon\n"
- " --check Check for a running daemon\n\n"
+ " --check Check for a running daemon (only returns exit code)\n\n"
"OPTIONS:\n"
" --system[=BOOL] Run as system-wide instance\n"
" -D, --daemonize[=BOOL] Daemonize after startup\n"
" --fail[=BOOL] Quit when startup fails\n"
- " --high-priority[=BOOL] Try to set high process priority\n"
- " (only available as root)\n"
- " --disallow-module-loading[=BOOL] Disallow module loading after startup\n"
+ " --high-priority[=BOOL] Try to set high nice level\n"
+ " (only available as root, when SUID or\n"
+ " with elevated RLIMIT_NICE)\n"
+ " --realtime[=BOOL] Try to enable realtime scheduling\n"
+ " (only available as root, when SUID or\n"
+ " with elevated RLIMIT_RTPRIO)\n"
+ " --disallow-module-loading[=BOOL] Disallow module user requested module\n"
+ " loading/unloading after startup\n"
+ " --disallow-exit[=BOOL] Disallow user requested exit\n"
" --exit-idle-time=SECS Terminate the daemon when idle and this\n"
" time passed\n"
" --module-idle-time=SECS Unload autoloaded modules when idle and\n"
@@ -120,15 +142,21 @@ void pa_cmdline_help(const char *argv0) {
" --scache-idle-time=SECS Unload autoloaded samples when idle and\n"
" this time passed\n"
" --log-level[=LEVEL] Increase or set verbosity level\n"
- " -v Increase the verbosity level\n"
- " --log-target={auto,syslog,stderr} Specify the log target\n"
+ " -v Increase the verbosity level\n"
+ " --log-target={auto,syslog,stderr,file:PATH}\n"
+ " Specify the log target\n"
+ " --log-meta[=BOOL] Include code location in log messages\n"
+ " --log-time[=BOOL] Include timestamps in log messages\n"
+ " --log-backtrace=FRAMES Include a backtrace in log messages\n"
" -p, --dl-search-path=PATH Set the search path for dynamic shared\n"
" objects (plugins)\n"
- " --resample-method=[METHOD] Use the specified resampling method\n"
- " (one of src-sinc-medium-quality,\n"
- " src-sinc-best-quality,src-sinc-fastest\n"
- " src-zero-order-hold,src-linear,trivial)\n"
- " --use-pid-file[=BOOL] Create a PID file\n\n"
+ " --resample-method=METHOD Use the specified resampling method\n"
+ " (See --dump-resample-methods for\n"
+ " possible values)\n"
+ " --use-pid-file[=BOOL] Create a PID file\n"
+ " --no-cpu-limit[=BOOL] Do not install CPU load limiter on\n"
+ " platforms that support it.\n"
+ " --disable-shm[=BOOL] Disable shared memory support.\n\n"
"STARTUP SCRIPT:\n"
" -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with\n"
@@ -136,20 +164,24 @@ void pa_cmdline_help(const char *argv0) {
" -F, --file=FILENAME Run the specified script\n"
" -C Open a command line on the running TTY\n"
" after startup\n\n"
-
- " -n Don't load default script file\n", e);
+
+ " -n Don't load default script file\n"),
+ pa_path_get_filename(argv0));
}
int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d) {
pa_strbuf *buf = NULL;
int c;
- assert(conf && argc && argv);
+
+ pa_assert(conf);
+ pa_assert(argc > 0);
+ pa_assert(argv);
buf = pa_strbuf_new();
if (conf->script_commands)
pa_strbuf_puts(buf, conf->script_commands);
-
+
while ((c = getopt_long(argc, argv, "L:F:ChDnp:kv", long_options, NULL)) != -1) {
switch (c) {
case ARG_HELP:
@@ -169,40 +201,56 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
conf->cmd = PA_CMD_DUMP_MODULES;
break;
+ case ARG_DUMP_RESAMPLE_METHODS:
+ conf->cmd = PA_CMD_DUMP_RESAMPLE_METHODS;
+ break;
+
+ case ARG_CLEANUP_SHM:
+ conf->cmd = PA_CMD_CLEANUP_SHM;
+ break;
+
case 'k':
case ARG_KILL:
conf->cmd = PA_CMD_KILL;
break;
+ case ARG_START:
+ conf->cmd = PA_CMD_START;
+ conf->daemonize = TRUE;
+ break;
+
case ARG_CHECK:
conf->cmd = PA_CMD_CHECK;
break;
-
+
case ARG_LOAD:
case 'L':
pa_strbuf_printf(buf, "load-module %s\n", optarg);
break;
-
+
case ARG_FILE:
- case 'F':
- pa_strbuf_printf(buf, ".include %s\n", optarg);
+ case 'F': {
+ char *p;
+ pa_strbuf_printf(buf, ".include %s\n", p = pa_make_path_absolute(optarg));
+ pa_xfree(p);
break;
-
+ }
+
case 'C':
pa_strbuf_puts(buf, "load-module module-cli exit_on_eof=1\n");
break;
-
+
case ARG_DAEMONIZE:
case 'D':
- if ((conf->daemonize = optarg ? pa_parse_boolean(optarg) : 1) < 0) {
- pa_log(__FILE__": --daemonize expects boolean argument");
+ if ((conf->daemonize = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--daemonize expects boolean argument"));
goto fail;
}
break;
case ARG_FAIL:
- if ((conf->fail = optarg ? pa_parse_boolean(optarg) : 1) < 0) {
- pa_log(__FILE__": --fail expects boolean argument");
+ if ((conf->fail = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--fail expects boolean argument"));
goto fail;
}
break;
@@ -212,61 +260,88 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
if (optarg) {
if (pa_daemon_conf_set_log_level(conf, optarg) < 0) {
- pa_log(__FILE__": --log-level expects log level argument (either numeric in range 0..4 or one of debug, info, notice, warn, error).");
+ pa_log(_("--log-level expects log level argument (either numeric in range 0..4 or one of debug, info, notice, warn, error)."));
goto fail;
}
} else {
if (conf->log_level < PA_LOG_LEVEL_MAX-1)
conf->log_level++;
}
-
+
break;
case ARG_HIGH_PRIORITY:
- if ((conf->high_priority = optarg ? pa_parse_boolean(optarg) : 1) < 0) {
- pa_log(__FILE__": --high-priority expects boolean argument");
+ if ((conf->high_priority = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--high-priority expects boolean argument"));
+ goto fail;
+ }
+ break;
+
+ case ARG_REALTIME:
+ if ((conf->realtime_scheduling = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--realtime expects boolean argument"));
goto fail;
}
break;
case ARG_DISALLOW_MODULE_LOADING:
- if ((conf->disallow_module_loading = optarg ? pa_parse_boolean(optarg) : 1) < 0) {
- pa_log(__FILE__": --disallow-module-loading expects boolean argument");
+ if ((conf->disallow_module_loading = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--disallow-module-loading expects boolean argument"));
+ goto fail;
+ }
+ break;
+
+ case ARG_DISALLOW_EXIT:
+ if ((conf->disallow_exit = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--disallow-exit expects boolean argument"));
goto fail;
}
break;
case ARG_USE_PID_FILE:
- if ((conf->use_pid_file = optarg ? pa_parse_boolean(optarg) : 1) < 0) {
- pa_log(__FILE__": --use-pid-file expects boolean argument");
+ if ((conf->use_pid_file = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--use-pid-file expects boolean argument"));
goto fail;
}
break;
-
+
case 'p':
case ARG_DL_SEARCH_PATH:
pa_xfree(conf->dl_search_path);
conf->dl_search_path = *optarg ? pa_xstrdup(optarg) : NULL;
break;
-
+
case 'n':
- pa_xfree(conf->default_script_file);
- conf->default_script_file = NULL;
+ conf->load_default_script_file = FALSE;
break;
case ARG_LOG_TARGET:
if (pa_daemon_conf_set_log_target(conf, optarg) < 0) {
- pa_log(__FILE__": Invalid log target: use either 'syslog', 'stderr' or 'auto'.");
+ pa_log(_("Invalid log target: use either 'syslog', 'stderr' or 'auto' or a valid file name 'file:<path>'."));
goto fail;
}
break;
- case ARG_EXIT_IDLE_TIME:
- conf->exit_idle_time = atoi(optarg);
+ case ARG_LOG_TIME:
+ if ((conf->log_time = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--log-time expects boolean argument"));
+ goto fail;
+ }
+ break;
+
+ case ARG_LOG_META:
+ if ((conf->log_meta = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--log-meta expects boolean argument"));
+ goto fail;
+ }
break;
- case ARG_MODULE_IDLE_TIME:
- conf->module_idle_time = atoi(optarg);
+ case ARG_LOG_BACKTRACE:
+ conf->log_backtrace = (unsigned) atoi(optarg);
+ break;
+
+ case ARG_EXIT_IDLE_TIME:
+ conf->exit_idle_time = atoi(optarg);
break;
case ARG_SCACHE_IDLE_TIME:
@@ -275,18 +350,32 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
case ARG_RESAMPLE_METHOD:
if (pa_daemon_conf_set_resample_method(conf, optarg) < 0) {
- pa_log(__FILE__": Invalid resample method '%s'.", optarg);
+ pa_log(_("Invalid resample method '%s'."), optarg);
goto fail;
}
break;
case ARG_SYSTEM:
- if ((conf->system_instance = optarg ? pa_parse_boolean(optarg) : 1) < 0) {
- pa_log(__FILE__": --system expects boolean argument");
+ if ((conf->system_instance = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--system expects boolean argument"));
goto fail;
}
break;
-
+
+ case ARG_NO_CPU_LIMIT:
+ if ((conf->no_cpu_limit = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--no-cpu-limit expects boolean argument"));
+ goto fail;
+ }
+ break;
+
+ case ARG_DISABLE_SHM:
+ if ((conf->disable_shm = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
+ pa_log(_("--disable-shm expects boolean argument"));
+ goto fail;
+ }
+ break;
+
default:
goto fail;
}
@@ -295,18 +384,13 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
pa_xfree(conf->script_commands);
conf->script_commands = pa_strbuf_tostring_free(buf);
- if (!conf->script_commands) {
- pa_xfree(conf->script_commands);
- conf->script_commands = NULL;
- }
-
*d = optind;
-
+
return 0;
-
+
fail:
if (buf)
pa_strbuf_free(buf);
-
+
return -1;
}
diff --git a/src/daemon/cmdline.h b/src/daemon/cmdline.h
index 25453e55..e34d7f50 100644
--- a/src/daemon/cmdline.h
+++ b/src/daemon/cmdline.h
@@ -1,21 +1,21 @@
#ifndef foocmdlinehfoo
#define foocmdlinehfoo
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c
index b8740ea0..3a972975 100644
--- a/src/daemon/cpulimit.c
+++ b/src/daemon/cpulimit.c
@@ -1,18 +1,18 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2 of the
+ published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -23,11 +23,13 @@
#include <config.h>
#endif
-#include <pulse/error.h>
+#include <pulse/rtclock.h>
+#include <pulse/timeval.h>
#include <pulsecore/core-util.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
#include "cpulimit.h"
@@ -36,8 +38,6 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
-#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
@@ -67,7 +67,7 @@
#define CPUTIME_INTERVAL_HARD (5)
/* Time of the last CPU load check */
-static time_t last_time = 0;
+static pa_usec_t last_time = 0;
/* Pipe for communicating with the main loop */
static int the_pipe[2] = {-1, -1};
@@ -80,33 +80,28 @@ static pa_io_event *io_event = NULL;
static struct sigaction sigaction_prev;
/* Nonzero after pa_cpu_limit_init() */
-static int installed = 0;
+static pa_bool_t installed = FALSE;
/* The current state of operation */
-static enum {
+static enum {
PHASE_IDLE, /* Normal state */
PHASE_SOFT /* After CPU overload has been detected */
} phase = PHASE_IDLE;
/* Reset the SIGXCPU timer to the next t seconds */
static void reset_cpu_time(int t) {
- int r;
long n;
struct rlimit rl;
struct rusage ru;
/* Get the current CPU time of the current process */
- r = getrusage(RUSAGE_SELF, &ru);
- assert(r >= 0);
+ pa_assert_se(getrusage(RUSAGE_SELF, &ru) >= 0);
n = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec + t;
+ pa_assert_se(getrlimit(RLIMIT_CPU, &rl) >= 0);
- r = getrlimit(RLIMIT_CPU, &rl);
- assert(r >= 0);
-
- rl.rlim_cur = n;
- r = setrlimit(RLIMIT_CPU, &rl);
- assert(r >= 0);
+ rl.rlim_cur = (rlim_t) n;
+ pa_assert_se(setrlimit(RLIMIT_CPU, &rl) >= 0);
}
/* A simple, thread-safe puts() work-alike */
@@ -116,49 +111,62 @@ static void write_err(const char *p) {
/* The signal handler, called on every SIGXCPU */
static void signal_handler(int sig) {
- assert(sig == SIGXCPU);
+ int saved_errno;
+
+ saved_errno = errno;
+ pa_assert(sig == SIGXCPU);
if (phase == PHASE_IDLE) {
- time_t now;
+ pa_usec_t now, elapsed;
#ifdef PRINT_CPU_LOAD
char t[256];
#endif
- time(&now);
+ now = pa_rtclock_now();
+ elapsed = now - last_time;
#ifdef PRINT_CPU_LOAD
- snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", (double)CPUTIME_INTERVAL_SOFT/(now-last_time)*100);
+ pa_snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", ((double) CPUTIME_INTERVAL_SOFT * (double) PA_USEC_PER_SEC) / (double) elapsed * 100.0);
write_err(t);
#endif
-
- if (CPUTIME_INTERVAL_SOFT >= ((now-last_time)*(double)CPUTIME_PERCENT/100)) {
+
+ if (((double) CPUTIME_INTERVAL_SOFT * (double) PA_USEC_PER_SEC) >= ((double) elapsed * (double) CPUTIME_PERCENT / 100.0)) {
static const char c = 'X';
write_err("Soft CPU time limit exhausted, terminating.\n");
-
+
/* Try a soft cleanup */
- write(the_pipe[1], &c, sizeof(c));
+ (void) pa_write(the_pipe[1], &c, sizeof(c), NULL);
phase = PHASE_SOFT;
reset_cpu_time(CPUTIME_INTERVAL_HARD);
-
+
} else {
/* Everything's fine */
reset_cpu_time(CPUTIME_INTERVAL_SOFT);
last_time = now;
}
-
+
} else if (phase == PHASE_SOFT) {
write_err("Hard CPU time limit exhausted, terminating forcibly.\n");
- _exit(1); /* Forced exit */
+ abort(); /* Forced exit */
}
+
+ errno = saved_errno;
}
/* Callback for IO events on the FIFO */
static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags_t f, void *userdata) {
char c;
- assert(m && e && f == PA_IO_EVENT_INPUT && e == io_event && fd == the_pipe[0]);
+ pa_assert(m);
+ pa_assert(e);
+ pa_assert(f == PA_IO_EVENT_INPUT);
+ pa_assert(e == io_event);
+ pa_assert(fd == the_pipe[0]);
+
+ pa_log("Received request to terminate due to CPU overload.");
+
pa_read(the_pipe[0], &c, sizeof(c), NULL);
m->quit(m, 1); /* Quit the main loop */
}
@@ -166,20 +174,24 @@ static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags
/* Initializes CPU load limiter */
int pa_cpu_limit_init(pa_mainloop_api *m) {
struct sigaction sa;
- assert(m && !api && !io_event && the_pipe[0] == -1 && the_pipe[1] == -1 && !installed);
-
- time(&last_time);
+
+ pa_assert(m);
+ pa_assert(!api);
+ pa_assert(!io_event);
+ pa_assert(the_pipe[0] == -1);
+ pa_assert(the_pipe[1] == -1);
+ pa_assert(!installed);
+
+ last_time = pa_rtclock_now();
/* Prepare the main loop pipe */
- if (pipe(the_pipe) < 0) {
- pa_log(__FILE__": pipe() failed: %s", pa_cstrerror(errno));
+ if (pa_pipe_cloexec(the_pipe) < 0) {
+ pa_log("pipe() failed: %s", pa_cstrerror(errno));
return -1;
}
- pa_make_nonblock_fd(the_pipe[0]);
- pa_make_nonblock_fd(the_pipe[1]);
- pa_fd_set_cloexec(the_pipe[0], 1);
- pa_fd_set_cloexec(the_pipe[1], 1);
+ pa_make_fd_nonblock(the_pipe[0]);
+ pa_make_fd_nonblock(the_pipe[1]);
api = m;
io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
@@ -191,46 +203,40 @@ int pa_cpu_limit_init(pa_mainloop_api *m) {
sa.sa_handler = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
-
+
if (sigaction(SIGXCPU, &sa, &sigaction_prev) < 0) {
pa_cpu_limit_done();
return -1;
}
- installed = 1;
+ installed = TRUE;
reset_cpu_time(CPUTIME_INTERVAL_SOFT);
-
+
return 0;
}
/* Shutdown CPU load limiter */
void pa_cpu_limit_done(void) {
- int r;
if (io_event) {
- assert(api);
+ pa_assert(api);
api->io_free(io_event);
io_event = NULL;
api = NULL;
}
- if (the_pipe[0] >= 0)
- close(the_pipe[0]);
- if (the_pipe[1] >= 0)
- close(the_pipe[1]);
- the_pipe[0] = the_pipe[1] = -1;
+ pa_close_pipe(the_pipe);
if (installed) {
- r = sigaction(SIGXCPU, &sigaction_prev, NULL);
- assert(r >= 0);
- installed = 0;
+ pa_assert_se(sigaction(SIGXCPU, &sigaction_prev, NULL) >= 0);
+ installed = FALSE;
}
}
#else /* HAVE_SIGXCPU */
-int pa_cpu_limit_init(PA_GCC_UNUSED pa_mainloop_api *m) {
+int pa_cpu_limit_init(pa_mainloop_api *m) {
return 0;
}
diff --git a/src/daemon/cpulimit.h b/src/daemon/cpulimit.h
index 21bdd17b..ce78d483 100644
--- a/src/daemon/cpulimit.h
+++ b/src/daemon/cpulimit.h
@@ -1,21 +1,21 @@
#ifndef foocpulimithfoo
#define foocpulimithfoo
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 894c0434..bb929091 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -1,11 +1,12 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
@@ -26,29 +27,34 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SCHED_H
+#include <sched.h>
+#endif
#include <pulse/xmalloc.h>
+#include <pulse/timeval.h>
+#include <pulse/i18n.h>
+#include <pulse/version.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/strbuf.h>
#include <pulsecore/conf-parser.h>
#include <pulsecore/resampler.h>
+#include <pulsecore/macro.h>
#include "daemon-conf.h"
-#ifndef OS_IS_WIN32
-# define PATH_SEP "/"
-#else
-# define PATH_SEP "\\"
-#endif
+#define DEFAULT_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "default.pa"
+#define DEFAULT_SCRIPT_FILE_USER PA_PATH_SEP "default.pa"
+#define DEFAULT_SYSTEM_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "system.pa"
-#define DEFAULT_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PATH_SEP "default.pa"
-#define DEFAULT_SCRIPT_FILE_USER PATH_SEP "default.pa"
-#define DEFAULT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf"
-#define DEFAULT_CONFIG_FILE_USER PATH_SEP "daemon.conf"
+#define DEFAULT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "daemon.conf"
+#define DEFAULT_CONFIG_FILE_USER PA_PATH_SEP "daemon.conf"
#define ENV_SCRIPT_FILE "PULSE_SCRIPT"
#define ENV_CONFIG_FILE "PULSE_CONFIG"
@@ -56,52 +62,112 @@
static const pa_daemon_conf default_conf = {
.cmd = PA_CMD_DAEMON,
- .daemonize = 0,
- .fail = 1,
- .high_priority = 0,
- .disallow_module_loading = 0,
- .exit_idle_time = -1,
- .module_idle_time = 20,
+ .daemonize = FALSE,
+ .fail = TRUE,
+ .high_priority = TRUE,
+ .nice_level = -11,
+ .realtime_scheduling = TRUE,
+ .realtime_priority = 5, /* Half of JACK's default rtprio */
+ .disallow_module_loading = FALSE,
+ .disallow_exit = FALSE,
+ .flat_volumes = TRUE,
+ .exit_idle_time = 20,
.scache_idle_time = 20,
.auto_log_target = 1,
.script_commands = NULL,
.dl_search_path = NULL,
+ .load_default_script_file = TRUE,
.default_script_file = NULL,
.log_target = PA_LOG_SYSLOG,
.log_level = PA_LOG_NOTICE,
- .resample_method = PA_RESAMPLER_SRC_SINC_FASTEST,
+ .log_backtrace = 0,
+ .log_meta = FALSE,
+ .log_time = FALSE,
+ .resample_method = PA_RESAMPLER_AUTO,
+ .disable_remixing = FALSE,
+ .disable_lfe_remixing = TRUE,
.config_file = NULL,
- .use_pid_file = 1,
- .system_instance = 0
+ .use_pid_file = TRUE,
+ .system_instance = FALSE,
+#ifdef HAVE_DBUS
+ .local_server_type = PA_SERVER_TYPE_UNSET, /* The actual default is _USER, but we have to detect when the user doesn't specify this option. */
+#endif
+ .no_cpu_limit = TRUE,
+ .disable_shm = FALSE,
+ .lock_memory = FALSE,
+ .sync_volume = TRUE,
+ .default_n_fragments = 4,
+ .default_fragment_size_msec = 25,
+ .sync_volume_safety_margin_usec = 8000,
+ .sync_volume_extra_delay_usec = 0,
+ .default_sample_spec = { .format = PA_SAMPLE_S16NE, .rate = 44100, .channels = 2 },
+ .default_channel_map = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } },
+ .shm_size = 0
#ifdef HAVE_SYS_RESOURCE_H
- , .rlimit_as = { .value = 0, .is_set = 0 },
- .rlimit_core = { .value = 0, .is_set = 0 },
- .rlimit_data = { .value = 0, .is_set = 0 },
- .rlimit_fsize = { .value = 0, .is_set = 0 },
- .rlimit_nofile = { .value = 25, .is_set = 1 },
- .rlimit_stack = { .value = 0, .is_set = 0 }
+ ,.rlimit_fsize = { .value = 0, .is_set = FALSE },
+ .rlimit_data = { .value = 0, .is_set = FALSE },
+ .rlimit_stack = { .value = 0, .is_set = FALSE },
+ .rlimit_core = { .value = 0, .is_set = FALSE }
+#ifdef RLIMIT_RSS
+ ,.rlimit_rss = { .value = 0, .is_set = FALSE }
+#endif
#ifdef RLIMIT_NPROC
- , .rlimit_nproc = { .value = 0, .is_set = 0 }
+ ,.rlimit_nproc = { .value = 0, .is_set = FALSE }
+#endif
+#ifdef RLIMIT_NOFILE
+ ,.rlimit_nofile = { .value = 256, .is_set = TRUE }
#endif
#ifdef RLIMIT_MEMLOCK
- , .rlimit_memlock = { .value = 0, .is_set = 1 }
+ ,.rlimit_memlock = { .value = 0, .is_set = FALSE }
+#endif
+#ifdef RLIMIT_AS
+ ,.rlimit_as = { .value = 0, .is_set = FALSE }
+#endif
+#ifdef RLIMIT_LOCKS
+ ,.rlimit_locks = { .value = 0, .is_set = FALSE }
+#endif
+#ifdef RLIMIT_SIGPENDING
+ ,.rlimit_sigpending = { .value = 0, .is_set = FALSE }
+#endif
+#ifdef RLIMIT_MSGQUEUE
+ ,.rlimit_msgqueue = { .value = 0, .is_set = FALSE }
+#endif
+#ifdef RLIMIT_NICE
+ ,.rlimit_nice = { .value = 31, .is_set = TRUE } /* nice level of -11 */
+#endif
+#ifdef RLIMIT_RTPRIO
+ ,.rlimit_rtprio = { .value = 9, .is_set = TRUE } /* One below JACK's default for the server */
+#endif
+#ifdef RLIMIT_RTTIME
+ ,.rlimit_rttime = { .value = PA_USEC_PER_SEC, .is_set = TRUE }
#endif
#endif
};
-pa_daemon_conf* pa_daemon_conf_new(void) {
- FILE *f;
- pa_daemon_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf));
+pa_daemon_conf *pa_daemon_conf_new(void) {
+ pa_daemon_conf *c;
- if ((f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file, "r")))
- fclose(f);
+ c = pa_xnewdup(pa_daemon_conf, &default_conf, 1);
+
+#ifdef OS_IS_WIN32
+ c->dl_search_path = pa_sprintf_malloc("%s" PA_PATH_SEP "lib" PA_PATH_SEP "pulse-%d.%d" PA_PATH_SEP "modules",
+ pa_win32_get_toplevel(NULL), PA_MAJOR, PA_MINOR);
+#else
+ if (pa_run_from_build_tree()) {
+ pa_log_notice("Detected that we are run from the build tree, fixing search path.");
+ c->dl_search_path = pa_xstrdup(PA_BUILDDIR "/.libs/");
+ } else
+ c->dl_search_path = pa_xstrdup(PA_DLSEARCHPATH);
+#endif
- c->dl_search_path = pa_xstrdup(PA_DLSEARCHPATH);
return c;
}
void pa_daemon_conf_free(pa_daemon_conf *c) {
- assert(c);
+ pa_assert(c);
+
+ pa_log_set_fd(-1);
+
pa_xfree(c->script_commands);
pa_xfree(c->dl_search_path);
pa_xfree(c->default_script_file);
@@ -110,7 +176,8 @@ void pa_daemon_conf_free(pa_daemon_conf *c) {
}
int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) {
- assert(c && string);
+ pa_assert(c);
+ pa_assert(string);
if (!strcmp(string, "auto"))
c->auto_log_target = 1;
@@ -120,6 +187,21 @@ int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) {
} else if (!strcmp(string, "stderr")) {
c->auto_log_target = 0;
c->log_target = PA_LOG_STDERR;
+ } else if (pa_startswith(string, "file:")) {
+ char file_path[512];
+ int log_fd;
+
+ pa_strlcpy(file_path, string + 5, sizeof(file_path));
+
+ /* Open target file with user rights */
+ if ((log_fd = open(file_path, O_RDWR|O_TRUNC|O_CREAT, S_IRWXU)) >= 0) {
+ c->auto_log_target = 0;
+ c->log_target = PA_LOG_FD;
+ pa_log_set_fd(log_fd);
+ } else {
+ printf("Failed to open target file %s, error : %s\n", file_path, pa_cstrerror(errno));
+ return -1;
+ }
} else
return -1;
@@ -128,7 +210,8 @@ int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) {
int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) {
uint32_t u;
- assert(c && string);
+ pa_assert(c);
+ pa_assert(string);
if (pa_atou(string, &u) >= 0) {
if (u >= PA_LOG_LEVEL_MAX)
@@ -153,7 +236,8 @@ int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) {
int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string) {
int m;
- assert(c && string);
+ pa_assert(c);
+ pa_assert(string);
if ((m = pa_parse_resample_method(string)) < 0)
return -1;
@@ -162,49 +246,78 @@ int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string) {
return 0;
}
-static int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+int pa_daemon_conf_set_local_server_type(pa_daemon_conf *c, const char *string) {
+ pa_assert(c);
+ pa_assert(string);
+
+ if (!strcmp(string, "user"))
+ c->local_server_type = PA_SERVER_TYPE_USER;
+ else if (!strcmp(string, "system")) {
+ c->local_server_type = PA_SERVER_TYPE_SYSTEM;
+ } else if (!strcmp(string, "none")) {
+ c->local_server_type = PA_SERVER_TYPE_NONE;
+ } else
+ return -1;
+
+ return 0;
+}
+
+static int parse_log_target(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
- assert(filename && lvalue && rvalue && data);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
if (pa_daemon_conf_set_log_target(c, rvalue) < 0) {
- pa_log(__FILE__": [%s:%u] Invalid log target '%s'.", filename, line, rvalue);
+ pa_log(_("[%s:%u] Invalid log target '%s'."), filename, line, rvalue);
return -1;
}
return 0;
}
-static int parse_log_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_log_level(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
- assert(filename && lvalue && rvalue && data);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
if (pa_daemon_conf_set_log_level(c, rvalue) < 0) {
- pa_log(__FILE__": [%s:%u] Invalid log level '%s'.", filename, line, rvalue);
+ pa_log(_("[%s:%u] Invalid log level '%s'."), filename, line, rvalue);
return -1;
}
return 0;
}
-static int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_resample_method(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
- assert(filename && lvalue && rvalue && data);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
if (pa_daemon_conf_set_resample_method(c, rvalue) < 0) {
- pa_log(__FILE__": [%s:%u] Inavalid resample method '%s'.", filename, line, rvalue);
+ pa_log(_("[%s:%u] Invalid resample method '%s'."), filename, line, rvalue);
return -1;
}
return 0;
}
-static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
#ifdef HAVE_SYS_RESOURCE_H
+static int parse_rlimit(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
struct pa_rlimit *r = data;
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- assert(r);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(r);
if (rvalue[strspn(rvalue, "\t ")] == 0) {
/* Empty string */
@@ -213,113 +326,329 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue,
} else {
int32_t k;
if (pa_atoi(rvalue, &k) < 0) {
- pa_log(__FILE__": [%s:%u] Inavalid rlimit '%s'.", filename, line, rvalue);
+ pa_log(_("[%s:%u] Invalid rlimit '%s'."), filename, line, rvalue);
return -1;
}
r->is_set = k >= 0;
r->value = k >= 0 ? (rlim_t) k : 0;
}
-#else
- pa_log_warn(__FILE__": [%s:%u] rlimit not supported on this platform.", filename, line);
+
+ return 0;
+}
#endif
+static int parse_sample_format(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ pa_daemon_conf *c = data;
+ pa_sample_format_t f;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if ((f = pa_parse_sample_format(rvalue)) < 0) {
+ pa_log(_("[%s:%u] Invalid sample format '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ c->default_sample_spec.format = f;
+ return 0;
+}
+
+static int parse_sample_rate(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ pa_daemon_conf *c = data;
+ uint32_t r;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atou(rvalue, &r) < 0 || r > (uint32_t) PA_RATE_MAX || r <= 0) {
+ pa_log(_("[%s:%u] Invalid sample rate '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ c->default_sample_spec.rate = r;
+ return 0;
+}
+
+struct channel_conf_info {
+ pa_daemon_conf *conf;
+ pa_bool_t default_sample_spec_set;
+ pa_bool_t default_channel_map_set;
+};
+
+static int parse_sample_channels(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ struct channel_conf_info *i = data;
+ int32_t n;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &n) < 0 || n > (int32_t) PA_CHANNELS_MAX || n <= 0) {
+ pa_log(_("[%s:%u] Invalid sample channels '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ i->conf->default_sample_spec.channels = (uint8_t) n;
+ i->default_sample_spec_set = TRUE;
+ return 0;
+}
+
+static int parse_channel_map(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ struct channel_conf_info *i = data;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (!pa_channel_map_parse(&i->conf->default_channel_map, rvalue)) {
+ pa_log(_("[%s:%u] Invalid channel map '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ i->default_channel_map_set = TRUE;
+ return 0;
+}
+
+static int parse_fragments(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ pa_daemon_conf *c = data;
+ int32_t n;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &n) < 0 || n < 2) {
+ pa_log(_("[%s:%u] Invalid number of fragments '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ c->default_n_fragments = (unsigned) n;
+ return 0;
+}
+
+static int parse_fragment_size_msec(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ pa_daemon_conf *c = data;
+ int32_t n;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &n) < 0 || n < 1) {
+ pa_log(_("[%s:%u] Invalid fragment size '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ c->default_fragment_size_msec = (unsigned) n;
+ return 0;
+}
+
+static int parse_nice_level(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ pa_daemon_conf *c = data;
+ int32_t level;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &level) < 0 || level < -20 || level > 19) {
+ pa_log(_("[%s:%u] Invalid nice level '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ c->nice_level = (int) level;
+ return 0;
+}
+
+static int parse_rtprio(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+#ifdef OS_IS_WIN32
+ pa_log("[%s:%u] Realtime priority not available on win32.", filename, line);
+#else
+# ifdef HAVE_SCHED_H
+ pa_daemon_conf *c = data;
+ int32_t rtprio;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ 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;
+ }
+
+ c->realtime_priority = (int) rtprio;
+# endif
+#endif /* OS_IS_WIN32 */
+
return 0;
}
+#ifdef HAVE_DBUS
+static int parse_server_type(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ pa_daemon_conf *c = data;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_daemon_conf_set_local_server_type(c, rvalue) < 0) {
+ pa_log(_("[%s:%u] Invalid server type '%s'."), filename, line, rvalue);
+ return -1;
+ }
+
+ return 0;
+}
+#endif
+
int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
int r = -1;
FILE *f = NULL;
-
+ struct channel_conf_info ci;
pa_config_item table[] = {
- { "daemonize", pa_config_parse_bool, NULL },
- { "fail", pa_config_parse_bool, NULL },
- { "high-priority", pa_config_parse_bool, NULL },
- { "disallow-module-loading", pa_config_parse_bool, NULL },
- { "exit-idle-time", pa_config_parse_int, NULL },
- { "module-idle-time", pa_config_parse_int, NULL },
- { "scache-idle-time", pa_config_parse_int, NULL },
- { "dl-search-path", pa_config_parse_string, NULL },
- { "default-script-file", pa_config_parse_string, NULL },
- { "log-target", parse_log_target, NULL },
- { "log-level", parse_log_level, NULL },
- { "verbose", parse_log_level, NULL },
- { "resample-method", parse_resample_method, NULL },
- { "use-pid-file", pa_config_parse_bool, NULL },
- { "system-instance", pa_config_parse_bool, NULL },
+ { "daemonize", pa_config_parse_bool, &c->daemonize, NULL },
+ { "fail", pa_config_parse_bool, &c->fail, NULL },
+ { "high-priority", pa_config_parse_bool, &c->high_priority, NULL },
+ { "realtime-scheduling", pa_config_parse_bool, &c->realtime_scheduling, NULL },
+ { "disallow-module-loading", pa_config_parse_bool, &c->disallow_module_loading, NULL },
+ { "allow-module-loading", pa_config_parse_not_bool, &c->disallow_module_loading, NULL },
+ { "disallow-exit", pa_config_parse_bool, &c->disallow_exit, NULL },
+ { "allow-exit", pa_config_parse_not_bool, &c->disallow_exit, NULL },
+ { "use-pid-file", pa_config_parse_bool, &c->use_pid_file, NULL },
+ { "system-instance", pa_config_parse_bool, &c->system_instance, NULL },
+#ifdef HAVE_DBUS
+ { "local-server-type", parse_server_type, c, NULL },
+#endif
+ { "no-cpu-limit", pa_config_parse_bool, &c->no_cpu_limit, NULL },
+ { "cpu-limit", pa_config_parse_not_bool, &c->no_cpu_limit, NULL },
+ { "disable-shm", pa_config_parse_bool, &c->disable_shm, NULL },
+ { "enable-shm", pa_config_parse_not_bool, &c->disable_shm, NULL },
+ { "flat-volumes", pa_config_parse_bool, &c->flat_volumes, NULL },
+ { "lock-memory", pa_config_parse_bool, &c->lock_memory, NULL },
+ { "enable-sync-volume", pa_config_parse_bool, &c->sync_volume, NULL },
+ { "exit-idle-time", pa_config_parse_int, &c->exit_idle_time, NULL },
+ { "scache-idle-time", pa_config_parse_int, &c->scache_idle_time, NULL },
+ { "realtime-priority", parse_rtprio, c, NULL },
+ { "dl-search-path", pa_config_parse_string, &c->dl_search_path, NULL },
+ { "default-script-file", pa_config_parse_string, &c->default_script_file, NULL },
+ { "log-target", parse_log_target, c, NULL },
+ { "log-level", parse_log_level, c, NULL },
+ { "verbose", parse_log_level, c, NULL },
+ { "resample-method", parse_resample_method, c, NULL },
+ { "default-sample-format", parse_sample_format, c, NULL },
+ { "default-sample-rate", parse_sample_rate, c, NULL },
+ { "default-sample-channels", parse_sample_channels, &ci, NULL },
+ { "default-channel-map", parse_channel_map, &ci, NULL },
+ { "default-fragments", parse_fragments, c, NULL },
+ { "default-fragment-size-msec", parse_fragment_size_msec, c, NULL },
+ { "sync-volume-safety-margin-usec", pa_config_parse_unsigned, &c->sync_volume_safety_margin_usec, NULL },
+ { "sync-volume-extra-delay-usec", pa_config_parse_int, &c->sync_volume_extra_delay_usec, NULL },
+ { "nice-level", parse_nice_level, c, NULL },
+ { "disable-remixing", pa_config_parse_bool, &c->disable_remixing, NULL },
+ { "enable-remixing", pa_config_parse_not_bool, &c->disable_remixing, NULL },
+ { "disable-lfe-remixing", pa_config_parse_bool, &c->disable_lfe_remixing, NULL },
+ { "enable-lfe-remixing", pa_config_parse_not_bool, &c->disable_lfe_remixing, NULL },
+ { "load-default-script-file", pa_config_parse_bool, &c->load_default_script_file, NULL },
+ { "shm-size-bytes", pa_config_parse_size, &c->shm_size, NULL },
+ { "log-meta", pa_config_parse_bool, &c->log_meta, NULL },
+ { "log-time", pa_config_parse_bool, &c->log_time, NULL },
+ { "log-backtrace", pa_config_parse_unsigned, &c->log_backtrace, NULL },
#ifdef HAVE_SYS_RESOURCE_H
- { "rlimit-as", parse_rlimit, NULL },
- { "rlimit-core", parse_rlimit, NULL },
- { "rlimit-data", parse_rlimit, NULL },
- { "rlimit-fsize", parse_rlimit, NULL },
- { "rlimit-nofile", parse_rlimit, NULL },
- { "rlimit-stack", parse_rlimit, NULL },
-#ifdef RLIMIT_NPROC
- { "rlimit-nproc", parse_rlimit, NULL },
+ { "rlimit-fsize", parse_rlimit, &c->rlimit_fsize, NULL },
+ { "rlimit-data", parse_rlimit, &c->rlimit_data, NULL },
+ { "rlimit-stack", parse_rlimit, &c->rlimit_stack, NULL },
+ { "rlimit-core", parse_rlimit, &c->rlimit_core, NULL },
+#ifdef RLIMIT_RSS
+ { "rlimit-rss", parse_rlimit, &c->rlimit_rss, NULL },
#endif
-#ifdef RLIMIT_MEMLOCK
- { "rlimit-memlock", parse_rlimit, NULL },
+#ifdef RLIMIT_NOFILE
+ { "rlimit-nofile", parse_rlimit, &c->rlimit_nofile, NULL },
#endif
+#ifdef RLIMIT_AS
+ { "rlimit-as", parse_rlimit, &c->rlimit_as, NULL },
#endif
- { NULL, NULL, NULL },
- };
-
- table[0].data = &c->daemonize;
- table[1].data = &c->fail;
- table[2].data = &c->high_priority;
- table[3].data = &c->disallow_module_loading;
- table[4].data = &c->exit_idle_time;
- table[5].data = &c->module_idle_time;
- table[6].data = &c->scache_idle_time;
- table[7].data = &c->dl_search_path;
- table[8].data = &c->default_script_file;
- table[9].data = c;
- table[10].data = c;
- table[11].data = c;
- table[12].data = c;
- table[13].data = &c->use_pid_file;
- table[14].data = &c->system_instance;
-#ifdef HAVE_SYS_RESOURCE_H
- table[15].data = &c->rlimit_as;
- table[16].data = &c->rlimit_core;
- table[17].data = &c->rlimit_data;
- table[18].data = &c->rlimit_fsize;
- table[19].data = &c->rlimit_nofile;
- table[20].data = &c->rlimit_stack;
#ifdef RLIMIT_NPROC
- table[21].data = &c->rlimit_nproc;
+ { "rlimit-nproc", parse_rlimit, &c->rlimit_nproc, NULL },
#endif
#ifdef RLIMIT_MEMLOCK
-#ifndef RLIMIT_NPROC
-#error "Houston, we have a numbering problem!"
+ { "rlimit-memlock", parse_rlimit, &c->rlimit_memlock, NULL },
+#endif
+#ifdef RLIMIT_LOCKS
+ { "rlimit-locks", parse_rlimit, &c->rlimit_locks, NULL },
+#endif
+#ifdef RLIMIT_SIGPENDING
+ { "rlimit-sigpending", parse_rlimit, &c->rlimit_sigpending, NULL },
#endif
- table[22].data = &c->rlimit_memlock;
+#ifdef RLIMIT_MSGQUEUE
+ { "rlimit-msgqueue", parse_rlimit, &c->rlimit_msgqueue, NULL },
#endif
+#ifdef RLIMIT_NICE
+ { "rlimit-nice", parse_rlimit, &c->rlimit_nice, NULL },
#endif
-
-
+#ifdef RLIMIT_RTPRIO
+ { "rlimit-rtprio", parse_rlimit, &c->rlimit_rtprio, NULL },
+#endif
+#ifdef RLIMIT_RTTIME
+ { "rlimit-rttime", parse_rlimit, &c->rlimit_rttime, NULL },
+#endif
+#endif
+ { NULL, NULL, NULL, NULL },
+ };
+
pa_xfree(c->config_file);
c->config_file = NULL;
f = filename ?
- fopen(c->config_file = pa_xstrdup(filename), "r") :
- pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file, "r");
+ pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") :
+ pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file);
if (!f && errno != ENOENT) {
- pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", c->config_file, pa_cstrerror(errno));
+ pa_log_warn(_("Failed to open configuration file: %s"), pa_cstrerror(errno));
goto finish;
}
+ ci.default_channel_map_set = ci.default_sample_spec_set = FALSE;
+ ci.conf = c;
+
r = f ? pa_config_parse(c->config_file, f, table, NULL) : 0;
-
+
+ if (r >= 0) {
+
+ /* Make sure that channel map and sample spec fit together */
+
+ if (ci.default_sample_spec_set &&
+ ci.default_channel_map_set &&
+ c->default_channel_map.channels != c->default_sample_spec.channels) {
+ pa_log_error(_("The specified default channel map has a different number of channels than the specified default number of channels."));
+ r = -1;
+ goto finish;
+ } else if (ci.default_sample_spec_set)
+ pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
+ else if (ci.default_channel_map_set)
+ c->default_sample_spec.channels = c->default_channel_map.channels;
+ }
+
finish:
if (f)
fclose(f);
-
+
return r;
}
int pa_daemon_conf_env(pa_daemon_conf *c) {
char *e;
+ pa_assert(c);
if ((e = getenv(ENV_DL_SEARCH_PATH))) {
pa_xfree(c->dl_search_path);
@@ -333,50 +662,143 @@ int pa_daemon_conf_env(pa_daemon_conf *c) {
return 0;
}
-static const char* const log_level_to_string[] = {
- [PA_LOG_DEBUG] = "debug",
- [PA_LOG_INFO] = "info",
- [PA_LOG_NOTICE] = "notice",
- [PA_LOG_WARN] = "warning",
- [PA_LOG_ERROR] = "error"
-};
+const char *pa_daemon_conf_get_default_script_file(pa_daemon_conf *c) {
+ pa_assert(c);
+
+ if (!c->default_script_file) {
+ if (c->system_instance)
+ c->default_script_file = pa_find_config_file(DEFAULT_SYSTEM_SCRIPT_FILE, NULL, ENV_SCRIPT_FILE);
+ else
+ c->default_script_file = pa_find_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE);
+ }
+
+ return c->default_script_file;
+}
+
+FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) {
+ FILE *f;
+ pa_assert(c);
+
+ if (!c->default_script_file) {
+ if (c->system_instance)
+ f = pa_open_config_file(DEFAULT_SYSTEM_SCRIPT_FILE, NULL, ENV_SCRIPT_FILE, &c->default_script_file);
+ else
+ f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file);
+ } else
+ f = pa_fopen_cloexec(c->default_script_file, "r");
+
+ return f;
+}
char *pa_daemon_conf_dump(pa_daemon_conf *c) {
- pa_strbuf *s = pa_strbuf_new();
+ static const char* const log_level_to_string[] = {
+ [PA_LOG_DEBUG] = "debug",
+ [PA_LOG_INFO] = "info",
+ [PA_LOG_NOTICE] = "notice",
+ [PA_LOG_WARN] = "warning",
+ [PA_LOG_ERROR] = "error"
+ };
+
+#ifdef HAVE_DBUS
+ static const char* const server_type_to_string[] = {
+ [PA_SERVER_TYPE_UNSET] = "!!UNSET!!",
+ [PA_SERVER_TYPE_USER] = "user",
+ [PA_SERVER_TYPE_SYSTEM] = "system",
+ [PA_SERVER_TYPE_NONE] = "none"
+ };
+#endif
+
+ pa_strbuf *s;
+ char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+
+ pa_assert(c);
+
+ s = pa_strbuf_new();
if (c->config_file)
- pa_strbuf_printf(s, "### Read from configuration file: %s ###\n", c->config_file);
-
- assert(c->log_level <= PA_LOG_LEVEL_MAX);
-
- pa_strbuf_printf(s, "daemonize = %i\n", !!c->daemonize);
- pa_strbuf_printf(s, "fail = %i\n", !!c->fail);
- pa_strbuf_printf(s, "high-priority = %i\n", !!c->high_priority);
- pa_strbuf_printf(s, "disallow-module-loading = %i\n", !!c->disallow_module_loading);
+ pa_strbuf_printf(s, _("### Read from configuration file: %s ###\n"), c->config_file);
+
+ pa_assert(c->log_level < PA_LOG_LEVEL_MAX);
+
+ pa_strbuf_printf(s, "daemonize = %s\n", pa_yes_no(c->daemonize));
+ pa_strbuf_printf(s, "fail = %s\n", pa_yes_no(c->fail));
+ pa_strbuf_printf(s, "high-priority = %s\n", pa_yes_no(c->high_priority));
+ pa_strbuf_printf(s, "nice-level = %i\n", c->nice_level);
+ pa_strbuf_printf(s, "realtime-scheduling = %s\n", pa_yes_no(c->realtime_scheduling));
+ pa_strbuf_printf(s, "realtime-priority = %i\n", c->realtime_priority);
+ pa_strbuf_printf(s, "allow-module-loading = %s\n", pa_yes_no(!c->disallow_module_loading));
+ pa_strbuf_printf(s, "allow-exit = %s\n", pa_yes_no(!c->disallow_exit));
+ pa_strbuf_printf(s, "use-pid-file = %s\n", pa_yes_no(c->use_pid_file));
+ pa_strbuf_printf(s, "system-instance = %s\n", pa_yes_no(c->system_instance));
+#ifdef HAVE_DBUS
+ pa_strbuf_printf(s, "local-server-type = %s\n", server_type_to_string[c->local_server_type]);
+#endif
+ pa_strbuf_printf(s, "cpu-limit = %s\n", pa_yes_no(!c->no_cpu_limit));
+ pa_strbuf_printf(s, "enable-shm = %s\n", pa_yes_no(!c->disable_shm));
+ pa_strbuf_printf(s, "flat-volumes = %s\n", pa_yes_no(c->flat_volumes));
+ pa_strbuf_printf(s, "lock-memory = %s\n", pa_yes_no(c->lock_memory));
+ pa_strbuf_printf(s, "enable-sync-volume = %s\n", pa_yes_no(c->sync_volume));
pa_strbuf_printf(s, "exit-idle-time = %i\n", c->exit_idle_time);
- pa_strbuf_printf(s, "module-idle-time = %i\n", c->module_idle_time);
pa_strbuf_printf(s, "scache-idle-time = %i\n", c->scache_idle_time);
- pa_strbuf_printf(s, "dl-search-path = %s\n", c->dl_search_path ? c->dl_search_path : "");
- pa_strbuf_printf(s, "default-script-file = %s\n", c->default_script_file);
+ pa_strbuf_printf(s, "dl-search-path = %s\n", pa_strempty(c->dl_search_path));
+ pa_strbuf_printf(s, "default-script-file = %s\n", pa_strempty(pa_daemon_conf_get_default_script_file(c)));
+ pa_strbuf_printf(s, "load-default-script-file = %s\n", pa_yes_no(c->load_default_script_file));
pa_strbuf_printf(s, "log-target = %s\n", c->auto_log_target ? "auto" : (c->log_target == PA_LOG_SYSLOG ? "syslog" : "stderr"));
pa_strbuf_printf(s, "log-level = %s\n", log_level_to_string[c->log_level]);
pa_strbuf_printf(s, "resample-method = %s\n", pa_resample_method_to_string(c->resample_method));
- pa_strbuf_printf(s, "use-pid-file = %i\n", c->use_pid_file);
- pa_strbuf_printf(s, "system-instance = %i\n", !!c->system_instance);
+ pa_strbuf_printf(s, "enable-remixing = %s\n", pa_yes_no(!c->disable_remixing));
+ pa_strbuf_printf(s, "enable-lfe-remixing = %s\n", pa_yes_no(!c->disable_lfe_remixing));
+ pa_strbuf_printf(s, "default-sample-format = %s\n", pa_sample_format_to_string(c->default_sample_spec.format));
+ pa_strbuf_printf(s, "default-sample-rate = %u\n", c->default_sample_spec.rate);
+ pa_strbuf_printf(s, "default-sample-channels = %u\n", c->default_sample_spec.channels);
+ pa_strbuf_printf(s, "default-channel-map = %s\n", pa_channel_map_snprint(cm, sizeof(cm), &c->default_channel_map));
+ pa_strbuf_printf(s, "default-fragments = %u\n", c->default_n_fragments);
+ pa_strbuf_printf(s, "default-fragment-size-msec = %u\n", c->default_fragment_size_msec);
+ pa_strbuf_printf(s, "sync-volume-safety-margin-usec = %u\n", c->sync_volume_safety_margin_usec);
+ pa_strbuf_printf(s, "sync-volume-extra-delay-usec = %d\n", c->sync_volume_extra_delay_usec);
+ pa_strbuf_printf(s, "shm-size-bytes = %lu\n", (unsigned long) c->shm_size);
+ pa_strbuf_printf(s, "log-meta = %s\n", pa_yes_no(c->log_meta));
+ pa_strbuf_printf(s, "log-time = %s\n", pa_yes_no(c->log_time));
+ pa_strbuf_printf(s, "log-backtrace = %u\n", c->log_backtrace);
#ifdef HAVE_SYS_RESOURCE_H
- pa_strbuf_printf(s, "rlimit-as = %li\n", c->rlimit_as.is_set ? (long int) c->rlimit_as.value : -1);
- pa_strbuf_printf(s, "rlimit-core = %li\n", c->rlimit_core.is_set ? (long int) c->rlimit_core.value : -1);
- pa_strbuf_printf(s, "rlimit-data = %li\n", c->rlimit_data.is_set ? (long int) c->rlimit_data.value : -1);
pa_strbuf_printf(s, "rlimit-fsize = %li\n", c->rlimit_fsize.is_set ? (long int) c->rlimit_fsize.value : -1);
- pa_strbuf_printf(s, "rlimit-nofile = %li\n", c->rlimit_nofile.is_set ? (long int) c->rlimit_nofile.value : -1);
+ pa_strbuf_printf(s, "rlimit-data = %li\n", c->rlimit_data.is_set ? (long int) c->rlimit_data.value : -1);
pa_strbuf_printf(s, "rlimit-stack = %li\n", c->rlimit_stack.is_set ? (long int) c->rlimit_stack.value : -1);
+ pa_strbuf_printf(s, "rlimit-core = %li\n", c->rlimit_core.is_set ? (long int) c->rlimit_core.value : -1);
+#ifdef RLIMIT_RSS
+ pa_strbuf_printf(s, "rlimit-rss = %li\n", c->rlimit_rss.is_set ? (long int) c->rlimit_rss.value : -1);
+#endif
+#ifdef RLIMIT_AS
+ pa_strbuf_printf(s, "rlimit-as = %li\n", c->rlimit_as.is_set ? (long int) c->rlimit_as.value : -1);
+#endif
#ifdef RLIMIT_NPROC
pa_strbuf_printf(s, "rlimit-nproc = %li\n", c->rlimit_nproc.is_set ? (long int) c->rlimit_nproc.value : -1);
#endif
+#ifdef RLIMIT_NOFILE
+ pa_strbuf_printf(s, "rlimit-nofile = %li\n", c->rlimit_nofile.is_set ? (long int) c->rlimit_nofile.value : -1);
+#endif
#ifdef RLIMIT_MEMLOCK
pa_strbuf_printf(s, "rlimit-memlock = %li\n", c->rlimit_memlock.is_set ? (long int) c->rlimit_memlock.value : -1);
#endif
+#ifdef RLIMIT_LOCKS
+ pa_strbuf_printf(s, "rlimit-locks = %li\n", c->rlimit_locks.is_set ? (long int) c->rlimit_locks.value : -1);
+#endif
+#ifdef RLIMIT_SIGPENDING
+ pa_strbuf_printf(s, "rlimit-sigpending = %li\n", c->rlimit_sigpending.is_set ? (long int) c->rlimit_sigpending.value : -1);
+#endif
+#ifdef RLIMIT_MSGQUEUE
+ pa_strbuf_printf(s, "rlimit-msgqueue = %li\n", c->rlimit_msgqueue.is_set ? (long int) c->rlimit_msgqueue.value : -1);
#endif
-
+#ifdef RLIMIT_NICE
+ pa_strbuf_printf(s, "rlimit-nice = %li\n", c->rlimit_nice.is_set ? (long int) c->rlimit_nice.value : -1);
+#endif
+#ifdef RLIMIT_RTPRIO
+ pa_strbuf_printf(s, "rlimit-rtprio = %li\n", c->rlimit_rtprio.is_set ? (long int) c->rlimit_rtprio.value : -1);
+#endif
+#ifdef RLIMIT_RTTIME
+ pa_strbuf_printf(s, "rlimit-rttime = %li\n", c->rlimit_rttime.is_set ? (long int) c->rlimit_rttime.value : -1);
+#endif
+#endif
+
return pa_strbuf_tostring_free(s);
}
diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h
index a09773f1..9fd6aba6 100644
--- a/src/daemon/daemon-conf.h
+++ b/src/daemon/daemon-conf.h
@@ -1,14 +1,15 @@
#ifndef foodaemonconfhfoo
#define foodaemonconfhfoo
-/* $Id$ */
-
/***
This file is part of PulseAudio.
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
@@ -22,7 +23,13 @@
USA.
***/
+#include <pulse/sample.h>
+#include <pulse/channelmap.h>
+
#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/core.h>
+#include <pulsecore/core-util.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
@@ -31,50 +38,101 @@
/* The actual command to execute */
typedef enum pa_daemon_conf_cmd {
PA_CMD_DAEMON, /* the default */
+ PA_CMD_START,
PA_CMD_HELP,
PA_CMD_VERSION,
PA_CMD_DUMP_CONF,
PA_CMD_DUMP_MODULES,
PA_CMD_KILL,
- PA_CMD_CHECK
+ PA_CMD_CHECK,
+ PA_CMD_DUMP_RESAMPLE_METHODS,
+ PA_CMD_CLEANUP_SHM
} pa_daemon_conf_cmd_t;
#ifdef HAVE_SYS_RESOURCE_H
typedef struct pa_rlimit {
rlim_t value;
- int is_set;
+ pa_bool_t is_set;
} pa_rlimit;
#endif
/* A structure containing configuration data for the PulseAudio server . */
typedef struct pa_daemon_conf {
pa_daemon_conf_cmd_t cmd;
- int daemonize,
+ pa_bool_t daemonize,
fail,
high_priority,
+ realtime_scheduling,
disallow_module_loading,
- exit_idle_time,
- module_idle_time,
+ use_pid_file,
+ system_instance,
+ no_cpu_limit,
+ disable_shm,
+ disable_remixing,
+ disable_lfe_remixing,
+ load_default_script_file,
+ disallow_exit,
+ log_meta,
+ log_time,
+ flat_volumes,
+ lock_memory,
+ sync_volume;
+ pa_server_type_t local_server_type;
+ int exit_idle_time,
scache_idle_time,
auto_log_target,
- use_pid_file,
- system_instance;
+ realtime_priority,
+ nice_level,
+ resample_method;
char *script_commands, *dl_search_path, *default_script_file;
pa_log_target_t log_target;
pa_log_level_t log_level;
- int resample_method;
+ unsigned log_backtrace;
char *config_file;
-
+
#ifdef HAVE_SYS_RESOURCE_H
- pa_rlimit rlimit_as, rlimit_core, rlimit_data, rlimit_fsize, rlimit_nofile, rlimit_stack;
+ pa_rlimit rlimit_fsize, rlimit_data, rlimit_stack, rlimit_core;
+#ifdef RLIMIT_RSS
+ pa_rlimit rlimit_rss;
+#endif
+#ifdef RLIMIT_NOFILE
+ pa_rlimit rlimit_nofile;
+#endif
+#ifdef RLIMIT_AS
+ pa_rlimit rlimit_as;
+#endif
#ifdef RLIMIT_NPROC
pa_rlimit rlimit_nproc;
#endif
#ifdef RLIMIT_MEMLOCK
pa_rlimit rlimit_memlock;
#endif
+#ifdef RLIMIT_LOCKS
+ pa_rlimit rlimit_locks;
#endif
-
+#ifdef RLIMIT_SIGPENDING
+ pa_rlimit rlimit_sigpending;
+#endif
+#ifdef RLIMIT_MSGQUEUE
+ pa_rlimit rlimit_msgqueue;
+#endif
+#ifdef RLIMIT_NICE
+ pa_rlimit rlimit_nice;
+#endif
+#ifdef RLIMIT_RTPRIO
+ pa_rlimit rlimit_rtprio;
+#endif
+#ifdef RLIMIT_RTTIME
+ pa_rlimit rlimit_rttime;
+#endif
+#endif
+
+ unsigned default_n_fragments, default_fragment_size_msec;
+ unsigned sync_volume_safety_margin_usec;
+ int sync_volume_extra_delay_usec;
+ pa_sample_spec default_sample_spec;
+ pa_channel_map default_channel_map;
+ size_t shm_size;
} pa_daemon_conf;
/* Allocate a new structure and fill it with sane defaults */
@@ -99,5 +157,9 @@ int pa_daemon_conf_env(pa_daemon_conf *c);
int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string);
int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string);
int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string);
+int pa_daemon_conf_set_local_server_type(pa_daemon_conf *c, const char *string);
+
+const char *pa_daemon_conf_get_default_script_file(pa_daemon_conf *c);
+FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c);
#endif
diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in
index 787405f8..6437f8f1 100644
--- a/src/daemon/daemon.conf.in
+++ b/src/daemon/daemon.conf.in
@@ -1,5 +1,3 @@
-# $Id$
-#
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
@@ -17,77 +15,77 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
-## Configuration file for the pulseaudio daemon. Default values are
-## commented out. Use either ; or # for commenting
-
-# Extra verbositiy
-; verbose = 0
-
-## Daemonize after startup
-; daemonize = 0
-
-## Quit if startup fails
-; fail = 1
-
-## Renice the daemon to level -15 and try to get SCHED_FIFO
-## scheduling. This a good idea if you hear annyoing noise in the
-## playback. However, this is a certain security issue, since it works
-## when called SUID root only. root is dropped immediately after gaining
-## the nice level and SCHED_FIFO scheduling on startup.
-; high-priority = 0
-
-## Disallow module loading after startup
-; disallow-module-loading = 0
-
-## Terminate the daemon after the last client quit and this time
-## passed. Use a negative value to disable this feature.
-; exit-idle-time = -1
-
-## Unload autoloaded modules after being idle for this time
-; module-idle-time = 20
-
-## Unload autoloaded sample cache entries after being idle for this time
+## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
+## more information. Default values are commented out. Use either ; or # for
+## commenting.
+changequote(`[', `]')dnl Set up m4 quoting
+
+; daemonize = no
+; fail = yes
+; allow-module-loading = yes
+; allow-exit = yes
+; use-pid-file = yes
+; system-instance = no
+ifelse(@HAVE_DBUS@, 1, [dnl
+; local-server-type = user
+])dnl
+; enable-shm = yes
+; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
+; lock-memory = no
+; cpu-limit = no
+
+; high-priority = yes
+; nice-level = -11
+
+; realtime-scheduling = yes
+; realtime-priority = 5
+
+; exit-idle-time = 20
; scache-idle-time = 20
-## The path were to look for dynamic shared objects (DSOs aka
-## plugins). You may specify more than one path seperated by
-## colons.
-; dl-search-path = @PA_DLSEARCHPATH@
+; dl-search-path = (depends on architecture)
-## The default script file to load. Specify an empty string for not
-## loading a default script file. The
-; default-script-file = @PA_DEFAULT_CONFIG_FILE@
+; load-default-script-file = yes
+; default-script-file = @PA_DEFAULT_CONFIG_DIR@/default.pa
-## The default log target. Use either "stderr", "syslog" or
-## "auto". The latter is equivalent to "sylog" in case daemonize is
-## true, otherwise to "stderr".
; log-target = auto
+; log-level = notice
+; log-meta = no
+; log-time = no
+; log-backtrace = 0
-## The resampling algorithm to use. Use one of src-sinc-best-quality,
-## src-sinc-medium-quality, src-sinc-fastest, src-zero-order-hold,
-## src-linear, trivial. See the documentation of libsamplerate for an
-## explanation for the different methods. The method 'trivial' is the
-## only algorithm implemented without usage of floating point
-## numbers. If you're tight on CPU consider using this. On the other
-## hand it has the worst quality of all.
-; resample-method = sinc-fastest
-
-## Create a PID file in /tmp/pulseaudio-$USER/pid. Of this is enabled
-## you may use commands like "pulseaudio --kill" or "pulseaudio
-## --check". If you are planning to start more than one pulseaudio
-## process per user, you better disable this option since it
-## effectively disables multiple instances.
-; use-pid-file = 1
+; resample-method = speex-float-3
+; enable-remixing = yes
+; enable-lfe-remixing = no
-## Run the daemon as system-wide instance, requires root priviliges
-; system-instance = 0
+; flat-volumes = yes
-## Resource limits, see getrlimit(2) for more information
-; rlimit-as = -1
-; rlimit-core = -1
-; rlimit-data = -1
+ifelse(@HAVE_SYS_RESOURCE_H@, 1, [dnl
; rlimit-fsize = -1
-; rlimit-nofile = 25
+; rlimit-data = -1
; rlimit-stack = -1
+; rlimit-core = -1
+; rlimit-as = -1
+; rlimit-rss = -1
; rlimit-nproc = -1
-; rlimit-memlock = 25
+; rlimit-nofile = 256
+; rlimit-memlock = -1
+; rlimit-locks = -1
+; rlimit-sigpending = -1
+; rlimit-msgqueue = -1
+; rlimit-nice = 31
+; rlimit-rtprio = 9
+; rlimit-rttime = 1000000
+])dnl
+
+; default-sample-format = s16le
+; default-sample-rate = 44100
+; default-sample-channels = 2
+; default-channel-map = front-left,front-right
+
+; default-fragments = 4
+; default-fragment-size-msec = 25
+
+; enable-sync-volume = yes
+; sync-volume-safety-margin-usec = 8000
+; sync-volume-extra-delay-usec = 0
diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in
index ac10c0ca..55a7423f 100755
--- a/src/daemon/default.pa.in
+++ b/src/daemon/default.pa.in
@@ -1,5 +1,4 @@
-#!@PA_BINARY@ -nF
-
+#!@PA_BINARY@ -nF
#
# This file is part of PulseAudio.
#
@@ -17,55 +16,161 @@
# along with PulseAudio; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+# This startup script is used only if PulseAudio is started per-user
+# (i.e. not in system mode)
+changequote(`[', `]')dnl Set up m4 quoting
+
+.nofail
+
+### Load something into the sample cache
+ifelse(@OS_IS_WIN32@, 1, [dnl
+load-sample x11-bell %WINDIR%\Media\ding.wav
+load-sample-dir-lazy %WINDIR%\Media\*.wav
+], [dnl
+#load-sample-lazy x11-bell /usr/share/sounds/gtk-events/activate.wav
+#load-sample-lazy pulse-hotplug /usr/share/sounds/startup3.wav
+#load-sample-lazy pulse-coldplug /usr/share/sounds/startup3.wav
+#load-sample-lazy pulse-access /usr/share/sounds/generic.wav
+])dnl
+
+.fail
+
+### Automatically restore the volume of streams and devices
+load-module module-device-restore
+load-module module-stream-restore
+load-module module-card-restore
+
+### Automatically augment property information from .desktop files
+### stored in /usr/share/application
+load-module module-augment-properties
### Load audio drivers statically
+### (it's probably better to not load these drivers manually, but instead
+### use module-udev-detect -- see below -- for doing this automatically)
+ifelse(@HAVE_ALSA@, 1, [dnl
#load-module module-alsa-sink
-#load-module module-alsa-source device=plughw:1,0
+#load-module module-alsa-source device=hw:1,0
+])dnl
+ifelse(@HAVE_OSS_OUTPUT@, 1, [dnl
#load-module module-oss device="/dev/dsp" sink_name=output source_name=input
#load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
+])dnl
+ifelse(@HAVE_WAVEOUT@, 1, [dnl
+load-module module-waveout sink_name=output source_name=input
+])dnl
#load-module module-null-sink
+ifelse(@HAVE_MKFIFO@, 1, [dnl
#load-module module-pipe-sink
+])dnl
### Automatically load driver modules depending on the hardware available
+ifelse(1, @HAVE_UDEV@, [dnl
+.ifexists module-udev-detect@PA_SOEXT@
+load-module module-udev-detect
+.else
+], @HAVE_HAL@, [dnl
+.ifexists module-hal-detect@PA_SOEXT@
+load-module module-hal-detect
+.else
+], [dnl
+.ifexists module-detect@PA_SOEXT@
+])dnl
+### Use the static hardware detection module (for systems that lack udev support)
load-module module-detect
+.endif
-### Load audio drivers automatically on access
-#add-autoload-sink output module-oss device="/dev/dsp" sink_name=output source_name=input
-#add-autoload-source input module-oss device="/dev/dsp" sink_name=output source_name=input
-#add-autoload-sink output module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
-#add-autoload-source input module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
-#add-autoload-sink output module-alsa-sink sink_name=output
-#add-autoload-source input module-alsa-source source_name=input
+ifelse(@HAVE_BLUEZ@, 1, [dnl
+### Automatically load driver modules for Bluetooth hardware
+.ifexists module-bluetooth-discover@PA_SOEXT@
+load-module module-bluetooth-discover
+.endif
+])dnl
+ifelse(@HAVE_AF_UNIX@, 1, [dnl
### Load several protocols
-load-module module-esound-protocol-unix
-#load-module module-esound-protocol-tcp
+#.ifexists module-esound-protocol-unix@PA_SOEXT@
+#load-module module-esound-protocol-unix
+#.endif
load-module module-native-protocol-unix
+])dnl
+ifelse(@HAVE_DBUS@, 1, [dnl
+.ifexists module-dbus-protocol@PA_SOEXT@
+load-module module-dbus-protocol
+.endif
+])dnl
+
+### Network access (may be configured with paprefs, so leave this commented
+### here if you plan to use paprefs)
+#load-module module-esound-protocol-tcp
#load-module module-native-protocol-tcp
+ifelse(@HAVE_AVAHI@, 1, [dnl
+#load-module module-zeroconf-publish
+])dnl
-### Load the RTP reciever module
+ifelse(@OS_IS_WIN32@, 0, [dnl
+### Load the RTP receiver module (also configured via paprefs, see above)
#load-module module-rtp-recv
-### Load the RTP sender module
-#load-module module-null-sink sink_name=rtp
-#load-module module-rtp-send source=rtp_monitor
+### Load the RTP sender module (also configured via paprefs, see above)
+#load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 description="RTP Multicast Sink"
+#load-module module-rtp-send source=rtp.monitor
-### Automatically restore the volume of playback streams
-load-module module-volume-restore
+### Load additional modules from GConf settings. This can be configured with the paprefs tool.
+### Please keep in mind that the modules configured by paprefs might conflict with manually
+### loaded modules.
+.ifexists module-gconf@PA_SOEXT@
+.nofail
+load-module module-gconf
+.fail
+.endif
-### Make some devices default
-#set-default-sink output
-#set-default-source input
+### Automatically restore the default sink/source when changed by the user during runtime
+load-module module-default-device-restore
-.nofail
+### Automatically move streams to the default sink if the sink they are
+### connected to dies, similar for sources
+load-module module-rescue-streams
+
+### Make sure we always have a sink around, even if it is a null sink.
+load-module module-always-sink
+
+### Honour intended role device property
+load-module module-intended-roles
+
+### Automatically suspend sinks/sources that become idle for too long
+load-module module-suspend-on-idle
+
+### If autoexit on idle is enabled we want to make sure we only quit
+### when no local session needs us anymore.
+.ifexists module-console-kit@PA_SOEXT@
+load-module module-console-kit
+.endif
-### Load something to the sample cache
-load-sample x11-bell /usr/share/sounds/gtk-events/activate.wav
-#load-sample-dir-lazy /usr/share/sounds/*.wav
+### Enable positioned event sounds
+load-module module-position-event-sounds
+
+### Cork music streams when a phone stream is active
+load-module module-cork-music-on-phone
+])dnl
+
+ifelse(@HAVE_X11@, 1, [dnl
+# X11 modules should not be started from default.pa so that one daemon
+# can be shared by multiple sessions.
### Load X11 bell module
-load-module module-x11-bell sample=x11-bell
+#load-module module-x11-bell sample=bell-windowing-system
+
+### Register ourselves in the X11 session manager
+#load-module module-x11-xsmp
### Publish connection data in the X11 root window
-load-module module-x11-publish
+#.ifexists module-x11-publish@PA_SOEXT@
+#.nofail
+#load-module module-x11-publish
+#.fail
+#.endif
+])dnl
+### Make some devices default
+#set-default-sink output
+#set-default-source input
diff --git a/src/daemon/default.pa.win32 b/src/daemon/default.pa.win32
deleted file mode 100644
index d5a1e183..00000000
--- a/src/daemon/default.pa.win32
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# This file is part of PulseAudio.
-#
-# PulseAudio is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# PulseAudio is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with PulseAudio; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-
-# Load audio drivers statically
-
-load-module module-waveout sink_name=output source_name=input
-load-module module-null-sink
-
-# Load audio drivers automatically on access
-
-#add-autoload-sink output module-waveout sink_name=output source_name=input
-#add-autoload-source input module-waveout sink_name=output source_name=input
-
-# Load several protocols
-#load-module module-esound-protocol-tcp
-#load-module module-native-protocol-tcp
-#load-module module-simple-protocol-tcp
-#load-module module-cli-protocol-tcp
-
-# Make some devices default
-set-default-sink output
-set-default-source input
-
-.nofail
-
-# Load something to the sample cache
-load-sample x11-bell %WINDIR%\Media\ding.wav
-load-sample-dir-lazy %WINDIR%\Media\*.wav
diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c
index 06734ea6..68ab5bba 100644
--- a/src/daemon/dumpmodules.c
+++ b/src/daemon/dumpmodules.c
@@ -1,11 +1,12 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
@@ -24,73 +25,84 @@
#endif
#include <string.h>
-#include <getopt.h>
-#include <assert.h>
#include <stdio.h>
#include <ltdl.h>
#include <pulse/util.h>
+#include <pulse/i18n.h>
#include <pulsecore/modinfo.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
#include "dumpmodules.h"
#define PREFIX "module-"
-static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) {
- assert(name && i);
+static void short_info(const char *name, const char *path, pa_modinfo *i) {
+ pa_assert(name);
+ pa_assert(i);
+
printf("%-40s%s\n", name, i->description ? i->description : "n/a");
}
static void long_info(const char *name, const char *path, pa_modinfo *i) {
static int nl = 0;
- assert(name && i);
-
+ pa_assert(name);
+ pa_assert(i);
+
if (nl)
printf("\n");
nl = 1;
- printf("Name: %s\n", name);
-
+ printf(_("Name: %s\n"), name);
+
if (!i->description && !i->version && !i->author && !i->usage)
- printf("No module information available\n");
+ printf(_("No module information available\n"));
else {
if (i->version)
- printf("Version: %s\n", i->version);
+ printf(_("Version: %s\n"), i->version);
if (i->description)
- printf("Description: %s\n", i->description);
+ printf(_("Description: %s\n"), i->description);
if (i->author)
- printf("Author: %s\n", i->author);
+ printf(_("Author: %s\n"), i->author);
if (i->usage)
- printf("Usage: %s\n", i->usage);
+ printf(_("Usage: %s\n"), i->usage);
+ printf(_("Load Once: %s\n"), pa_yes_no(i->load_once));
+ if (i->deprecated)
+ printf(_("DEPRECATION WARNING: %s\n"), i->deprecated);
}
-
+
if (path)
- printf("Path: %s\n", path);
+ printf(_("Path: %s\n"), path);
}
static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
pa_modinfo *i;
-
+
+ pa_assert(name);
+
if ((i = pa_modinfo_get_by_name(path ? path : name))) {
info(name, path, i);
pa_modinfo_free(i);
}
}
+#ifndef OS_IS_WIN32
extern const lt_dlsymlist lt_preloaded_symbols[];
+#endif
static int is_preloaded(const char *name) {
const lt_dlsymlist *l;
for (l = lt_preloaded_symbols; l->name; l++) {
char buf[64], *e;
-
+
if (l->address)
continue;
-
- snprintf(buf, sizeof(buf), "%s", l->name);
+
+ pa_snprintf(buf, sizeof(buf), "%s", l->name);
if ((e = strrchr(buf, '.')))
*e = 0;
@@ -112,12 +124,14 @@ static int callback(const char *path, lt_ptr data) {
if (is_preloaded(e))
return 0;
-
+
show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
return 0;
}
void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
+ pa_assert(c);
+
if (argc > 0) {
int i;
for (i = 0; i < argc; i++)
@@ -127,20 +141,20 @@ void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
for (l = lt_preloaded_symbols; l->name; l++) {
char buf[64], *e;
-
+
if (l->address)
continue;
if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
continue;
-
- snprintf(buf, sizeof(buf), "%s", l->name);
+
+ pa_snprintf(buf, sizeof(buf), "%s", l->name);
if ((e = strrchr(buf, '.')))
*e = 0;
-
+
show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
}
-
+
lt_dlforeachfile(NULL, callback, c);
}
}
diff --git a/src/daemon/dumpmodules.h b/src/daemon/dumpmodules.h
index 05cd86e0..c3595e54 100644
--- a/src/daemon/dumpmodules.h
+++ b/src/daemon/dumpmodules.h
@@ -1,14 +1,14 @@
#ifndef foodumpmoduleshfoo
#define foodumpmoduleshfoo
-/* $Id*/
-
/***
This file is part of PulseAudio.
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
diff --git a/src/daemon/esdcompat.in b/src/daemon/esdcompat.in
index ece1f4f9..41a12a02 100755
--- a/src/daemon/esdcompat.in
+++ b/src/daemon/esdcompat.in
@@ -1,7 +1,5 @@
#!/bin/sh
-# $Id$
-#
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
@@ -28,7 +26,7 @@ fail() {
ARGS=" --log-target=syslog"
-for N in $(seq $#) ; do
+while [ "$#" -gt "0" ]; do
case "$1" in
"")
@@ -61,7 +59,7 @@ Ignored directives:
-terminate terminate esd daemone after last client exits
-nobeeps disable startup beeps
-trust start esd even if use of /tmp/.esd can be insecure
- -port PORT listen for connections at PORT (only for tcp/ip)
+ -port PORT listen for connections at PORT (only for tcp/ip)
-bind ADDRESS binds to ADDRESS (only for tcp/ip)
EOF
exit 0
diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c
new file mode 100644
index 00000000..2ba73ce7
--- /dev/null
+++ b/src/daemon/ltdl-bind-now.c
@@ -0,0 +1,161 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2004-2008 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#ifdef HAVE_SYS_DL_H
+#include <sys/dl.h>
+#endif
+
+#include <string.h>
+
+#include <ltdl.h>
+
+#include <pulse/i18n.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/log.h>
+
+#include "ltdl-bind-now.h"
+
+#ifdef RTLD_NOW
+#define PA_BIND_NOW RTLD_NOW
+#elif defined(DL_NOW)
+#define PA_BIND_NOW DL_NOW
+#else
+#undef PA_BIND_NOW
+#endif
+
+#ifdef OS_IS_WIN32
+#undef PA_BIND_NOW
+#endif
+
+#ifdef PA_BIND_NOW
+
+/*
+ To avoid lazy relocations during runtime in our RT threads we add
+ our own shared object loader with uses RTLD_NOW if it is
+ available. The standard ltdl loader prefers RTLD_LAZY.
+
+ Please note that this loader doesn't have any influence on
+ relocations on any libraries that are already loaded into our
+ process, i.e. because the pulseaudio binary links directly to
+ them. To disable lazy relocations for those libraries it is possible
+ to set $LT_BIND_NOW before starting the pulsaudio binary.
+*/
+
+static lt_module bind_now_open(lt_user_data d, const char *fname, lt_dladvise advise) {
+ lt_module m;
+
+ pa_assert(fname);
+
+ if (!(m = dlopen(fname, PA_BIND_NOW))) {
+ lt_dlseterror(LT_ERROR_CANNOT_OPEN);
+ return NULL;
+ }
+
+ return m;
+}
+
+static int bind_now_close(lt_user_data d, lt_module m) {
+
+ pa_assert(m);
+
+ if (dlclose(m) != 0){
+ lt_dlseterror(LT_ERROR_CANNOT_CLOSE);
+ return 1;
+ }
+
+ return 0;
+}
+
+static lt_ptr bind_now_find_sym(lt_user_data d, lt_module m, const char *symbol) {
+ lt_ptr ptr;
+
+ pa_assert(m);
+ pa_assert(symbol);
+
+ if (!(ptr = dlsym(m, symbol))) {
+ lt_dlseterror(LT_ERROR_SYMBOL_NOT_FOUND);
+ return NULL;
+ }
+
+ return ptr;
+}
+
+static lt_dlvtable *bindnow_loader = NULL;
+#endif
+
+void pa_ltdl_init(void) {
+
+#ifdef PA_BIND_NOW
+ const lt_dlvtable *dlopen_loader;
+#endif
+
+ pa_assert_se(lt_dlinit() == 0);
+
+#ifdef PA_BIND_NOW
+ /* Already initialised */
+ if (bindnow_loader)
+ return;
+
+ if (!(dlopen_loader = lt_dlloader_find((char*) "lt_dlopen"))) {
+ pa_log_warn(_("Failed to find original lt_dlopen loader."));
+ return;
+ }
+
+ if (!(bindnow_loader = malloc(sizeof(lt_dlvtable)))) {
+ pa_log_error(_("Failed to allocate new dl loader."));
+ return;
+ }
+
+ memcpy(bindnow_loader, dlopen_loader, sizeof(*bindnow_loader));
+ bindnow_loader->name = "bind-now-loader";
+ bindnow_loader->module_open = bind_now_open;
+ bindnow_loader->module_close = bind_now_close;
+ bindnow_loader->find_sym = bind_now_find_sym;
+ bindnow_loader->priority = LT_DLLOADER_PREPEND;
+
+ /* Add our BIND_NOW loader as the default module loader. */
+ if (lt_dlloader_add(bindnow_loader) != 0) {
+ pa_log_warn(_("Failed to add bind-now-loader."));
+ free(bindnow_loader);
+ bindnow_loader = NULL;
+ }
+#endif
+}
+
+void pa_ltdl_done(void) {
+ pa_assert_se(lt_dlexit() == 0);
+
+#ifdef PA_BIND_NOW
+ /* lt_dlexit() will free our loader vtable, hence reset our
+ * pointer to it here */
+ bindnow_loader = NULL;
+#endif
+}
diff --git a/src/daemon/ltdl-bind-now.h b/src/daemon/ltdl-bind-now.h
new file mode 100644
index 00000000..07600706
--- /dev/null
+++ b/src/daemon/ltdl-bind-now.h
@@ -0,0 +1,30 @@
+#ifndef foopulsecoreltdlbindnowhfoo
+#define foopulsecoreltdlbindnowhfoo
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2004-2006 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+
+void pa_ltdl_init(void);
+void pa_ltdl_done(void);
+
+#endif
+
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 3ced3bf6..94c87d15 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -1,18 +1,19 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -30,18 +31,15 @@
#include <stdio.h>
#include <signal.h>
#include <stddef.h>
-#include <assert.h>
#include <ltdl.h>
#include <limits.h>
-#include <fcntl.h>
#include <unistd.h>
#include <locale.h>
#include <sys/types.h>
+#include <sys/stat.h>
-#include <liboil/liboil.h>
-
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
#endif
#ifdef HAVE_PWD_H
@@ -56,16 +54,25 @@
#include <tcpd.h>
#endif
-#include "../pulsecore/winsock.h"
+#ifdef HAVE_DBUS
+#include <dbus/dbus.h>
+#endif
+#include <pulse/client-conf.h>
+#ifdef HAVE_X11
+#include <pulse/client-conf-x11.h>
+#endif
#include <pulse/mainloop.h>
#include <pulse/mainloop-signal.h>
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
+#include <pulsecore/lock-autospawn.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
+#include <pulsecore/core-rtclock.h>
#include <pulsecore/core.h>
-#include <pulsecore/memblock.h>
#include <pulsecore/module.h>
#include <pulsecore/cli-command.h>
#include <pulsecore/log.h>
@@ -73,14 +80,25 @@
#include <pulsecore/sioman.h>
#include <pulsecore/cli-text.h>
#include <pulsecore/pid.h>
-#include <pulsecore/namereg.h>
#include <pulsecore/random.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/shm.h>
+#include <pulsecore/memtrap.h>
+#include <pulsecore/strlist.h>
+#ifdef HAVE_DBUS
+#include <pulsecore/dbus-shared.h>
+#endif
+#include <pulsecore/cpu-arm.h>
+#include <pulsecore/cpu-x86.h>
+#include <pulsecore/cpu-orc.h>
#include "cmdline.h"
#include "cpulimit.h"
#include "daemon-conf.h"
#include "dumpmodules.h"
#include "caps.h"
+#include "ltdl-bind-now.h"
+#include "server-lookup.h"
#ifdef HAVE_LIBWRAP
/* Only one instance of these variables */
@@ -88,7 +106,7 @@ int allow_severity = LOG_INFO;
int deny_severity = LOG_WARNING;
#endif
-#ifdef HAVE_OSS
+#ifdef HAVE_OSS_WRAPPER
/* padsp looks for this symbol in the running process and disables
* itself if it finds it and it is set to 7 (which is actually a bit
* mask). For details see padsp. */
@@ -97,11 +115,11 @@ int __padsp_disabled__ = 7;
#ifdef OS_IS_WIN32
-static void message_cb(pa_mainloop_api*a, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void message_cb(pa_mainloop_api*a, pa_time_event*e, const struct timeval *tv, void *userdata) {
MSG msg;
struct timeval tvnext;
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
raise(SIGTERM);
else {
@@ -116,8 +134,8 @@ static void message_cb(pa_mainloop_api*a, pa_time_event*e, PA_GCC_UNUSED const s
#endif
-static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e, int sig, void *userdata) {
- pa_log_info(__FILE__": Got signal %s.", pa_strsignal(sig));
+static void signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
+ pa_log_info(_("Got signal %s."), pa_sig2str(sig));
switch (sig) {
#ifdef SIGUSR1
@@ -125,7 +143,7 @@ static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e,
pa_module_load(userdata, "module-cli", NULL);
break;
#endif
-
+
#ifdef SIGUSR2
case SIGUSR2:
pa_module_load(userdata, "module-cli-protocol-unix", NULL);
@@ -144,22 +162,12 @@ static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e,
case SIGINT:
case SIGTERM:
default:
- pa_log_info(__FILE__": Exiting.");
+ pa_log_info(_("Exiting."));
m->quit(m, 1);
break;
}
}
-static void close_pipe(int p[2]) {
- if (p[0] != -1)
- close(p[0]);
- if (p[1] != -1)
- close(p[1]);
- p[0] = p[1] = -1;
-}
-
-#define set_env(key, value) putenv(pa_sprintf_malloc("%s=%s", (key), (value)))
-
#if defined(HAVE_PWD_H) && defined(HAVE_GRP_H)
static int change_user(void) {
@@ -170,36 +178,43 @@ static int change_user(void) {
/* This function is called only in system-wide mode. It creates a
* runtime dir in /var/run/ with proper UID/GID and drops privs
* afterwards. */
-
+
if (!(pw = getpwnam(PA_SYSTEM_USER))) {
- pa_log(__FILE__": Failed to find user '%s'.", PA_SYSTEM_USER);
+ pa_log(_("Failed to find user '%s'."), PA_SYSTEM_USER);
return -1;
}
if (!(gr = getgrnam(PA_SYSTEM_GROUP))) {
- pa_log(__FILE__": Failed to find group '%s'.", PA_SYSTEM_GROUP);
+ pa_log(_("Failed to find group '%s'."), PA_SYSTEM_GROUP);
return -1;
}
- pa_log_info(__FILE__": Found user '%s' (UID %lu) and group '%s' (GID %lu).",
+ pa_log_info(_("Found user '%s' (UID %lu) and group '%s' (GID %lu)."),
PA_SYSTEM_USER, (unsigned long) pw->pw_uid,
PA_SYSTEM_GROUP, (unsigned long) gr->gr_gid);
if (pw->pw_gid != gr->gr_gid) {
- pa_log(__FILE__": GID of user '%s' and of group '%s' don't match.", PA_SYSTEM_USER, PA_SYSTEM_GROUP);
+ pa_log(_("GID of user '%s' and of group '%s' don't match."), PA_SYSTEM_USER, PA_SYSTEM_GROUP);
return -1;
}
if (strcmp(pw->pw_dir, PA_SYSTEM_RUNTIME_PATH) != 0)
- pa_log_warn(__FILE__": Warning: home directory of user '%s' is not '%s', ignoring.", PA_SYSTEM_USER, PA_SYSTEM_RUNTIME_PATH);
+ pa_log_warn(_("Home directory of user '%s' is not '%s', ignoring."), PA_SYSTEM_USER, PA_SYSTEM_RUNTIME_PATH);
if (pa_make_secure_dir(PA_SYSTEM_RUNTIME_PATH, 0755, pw->pw_uid, gr->gr_gid) < 0) {
- pa_log(__FILE__": Failed to create '%s': %s", PA_SYSTEM_RUNTIME_PATH, pa_cstrerror(errno));
+ pa_log(_("Failed to create '%s': %s"), PA_SYSTEM_RUNTIME_PATH, pa_cstrerror(errno));
+ return -1;
+ }
+
+ if (pa_make_secure_dir(PA_SYSTEM_STATE_PATH, 0700, pw->pw_uid, gr->gr_gid) < 0) {
+ pa_log(_("Failed to create '%s': %s"), PA_SYSTEM_STATE_PATH, pa_cstrerror(errno));
return -1;
}
-
+
+ /* We don't create the config dir here, because we don't need to write to it */
+
if (initgroups(PA_SYSTEM_USER, gr->gr_gid) != 0) {
- pa_log(__FILE__": Failed to change group list: %s", pa_cstrerror(errno));
+ pa_log(_("Failed to change group list: %s"), pa_cstrerror(errno));
return -1;
}
@@ -211,11 +226,11 @@ static int change_user(void) {
#elif defined(HAVE_SETREGID)
r = setregid(gr->gr_gid, gr->gr_gid);
#else
-#error "No API to drop priviliges"
+#error "No API to drop privileges"
#endif
if (r < 0) {
- pa_log(__FILE__": Failed to change GID: %s", pa_cstrerror(errno));
+ pa_log(_("Failed to change GID: %s"), pa_cstrerror(errno));
return -1;
}
@@ -227,23 +242,30 @@ static int change_user(void) {
#elif defined(HAVE_SETREUID)
r = setreuid(pw->pw_uid, pw->pw_uid);
#else
-#error "No API to drop priviliges"
+#error "No API to drop privileges"
#endif
if (r < 0) {
- pa_log(__FILE__": Failed to change UID: %s", pa_cstrerror(errno));
+ pa_log(_("Failed to change UID: %s"), pa_cstrerror(errno));
return -1;
}
- set_env("USER", PA_SYSTEM_USER);
- set_env("LOGNAME", PA_SYSTEM_GROUP);
- set_env("HOME", PA_SYSTEM_RUNTIME_PATH);
+ pa_set_env("USER", PA_SYSTEM_USER);
+ pa_set_env("USERNAME", PA_SYSTEM_USER);
+ pa_set_env("LOGNAME", PA_SYSTEM_USER);
+ pa_set_env("HOME", PA_SYSTEM_RUNTIME_PATH);
/* Relevant for pa_runtime_path() */
- set_env("PULSE_RUNTIME_PATH", PA_SYSTEM_RUNTIME_PATH);
- set_env("PULSE_CONFIG_PATH", PA_SYSTEM_RUNTIME_PATH);
+ if (!getenv("PULSE_RUNTIME_PATH"))
+ pa_set_env("PULSE_RUNTIME_PATH", PA_SYSTEM_RUNTIME_PATH);
+
+ if (!getenv("PULSE_CONFIG_PATH"))
+ pa_set_env("PULSE_CONFIG_PATH", PA_SYSTEM_CONFIG_PATH);
+
+ if (!getenv("PULSE_STATE_PATH"))
+ pa_set_env("PULSE_STATE_PATH", PA_SYSTEM_STATE_PATH);
- pa_log_info(__FILE__": Successfully dropped root privileges.");
+ pa_log_info(_("Successfully dropped root privileges."));
return 0;
}
@@ -251,116 +273,218 @@ static int change_user(void) {
#else /* HAVE_PWD_H && HAVE_GRP_H */
static int change_user(void) {
- pa_log(__FILE__": System wide mode unsupported on this platform.");
+ pa_log(_("System wide mode unsupported on this platform."));
return -1;
}
#endif /* HAVE_PWD_H && HAVE_GRP_H */
-static int create_runtime_dir(void) {
- char fn[PATH_MAX];
-
- pa_runtime_path(NULL, fn, sizeof(fn));
-
- /* This function is called only when the daemon is started in
- * per-user mode. We create the runtime directory somewhere in
- * /tmp/ with the current UID/GID */
-
- if (pa_make_secure_dir(fn, 0700, (uid_t)-1, (gid_t)-1) < 0) {
- pa_log(__FILE__": Failed to create '%s': %s", fn, pa_cstrerror(errno));
- return -1;
- }
-
- return 0;
-}
-
#ifdef HAVE_SYS_RESOURCE_H
-static void set_one_rlimit(const pa_rlimit *r, int resource, const char *name) {
+static int set_one_rlimit(const pa_rlimit *r, int resource, const char *name) {
struct rlimit rl;
- assert(r);
+ pa_assert(r);
if (!r->is_set)
- return;
+ return 0;
rl.rlim_cur = rl.rlim_max = r->value;
- if (setrlimit(resource, &rl) < 0)
- pa_log_warn(__FILE__": setrlimit(%s, (%u, %u)) failed: %s", name, (unsigned) r->value, (unsigned) r->value, pa_cstrerror(errno));
+ if (setrlimit(resource, &rl) < 0) {
+ pa_log_info(_("setrlimit(%s, (%u, %u)) failed: %s"), name, (unsigned) r->value, (unsigned) r->value, pa_cstrerror(errno));
+ return -1;
+ }
+
+ return 0;
}
static void set_all_rlimits(const pa_daemon_conf *conf) {
- set_one_rlimit(&conf->rlimit_as, RLIMIT_AS, "RLIMIT_AS");
- set_one_rlimit(&conf->rlimit_core, RLIMIT_CORE, "RLIMIT_CORE");
- set_one_rlimit(&conf->rlimit_data, RLIMIT_DATA, "RLIMIT_DATA");
set_one_rlimit(&conf->rlimit_fsize, RLIMIT_FSIZE, "RLIMIT_FSIZE");
- set_one_rlimit(&conf->rlimit_nofile, RLIMIT_NOFILE, "RLIMIT_NOFILE");
+ set_one_rlimit(&conf->rlimit_data, RLIMIT_DATA, "RLIMIT_DATA");
set_one_rlimit(&conf->rlimit_stack, RLIMIT_STACK, "RLIMIT_STACK");
+ set_one_rlimit(&conf->rlimit_core, RLIMIT_CORE, "RLIMIT_CORE");
+#ifdef RLIMIT_RSS
+ set_one_rlimit(&conf->rlimit_rss, RLIMIT_RSS, "RLIMIT_RSS");
+#endif
#ifdef RLIMIT_NPROC
set_one_rlimit(&conf->rlimit_nproc, RLIMIT_NPROC, "RLIMIT_NPROC");
#endif
+#ifdef RLIMIT_NOFILE
+ set_one_rlimit(&conf->rlimit_nofile, RLIMIT_NOFILE, "RLIMIT_NOFILE");
+#endif
#ifdef RLIMIT_MEMLOCK
set_one_rlimit(&conf->rlimit_memlock, RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK");
#endif
+#ifdef RLIMIT_AS
+ set_one_rlimit(&conf->rlimit_as, RLIMIT_AS, "RLIMIT_AS");
+#endif
+#ifdef RLIMIT_LOCKS
+ set_one_rlimit(&conf->rlimit_locks, RLIMIT_LOCKS, "RLIMIT_LOCKS");
+#endif
+#ifdef RLIMIT_SIGPENDING
+ set_one_rlimit(&conf->rlimit_sigpending, RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING");
+#endif
+#ifdef RLIMIT_MSGQUEUE
+ set_one_rlimit(&conf->rlimit_msgqueue, RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE");
+#endif
+#ifdef RLIMIT_NICE
+ set_one_rlimit(&conf->rlimit_nice, RLIMIT_NICE, "RLIMIT_NICE");
+#endif
+#ifdef RLIMIT_RTPRIO
+ set_one_rlimit(&conf->rlimit_rtprio, RLIMIT_RTPRIO, "RLIMIT_RTPRIO");
+#endif
+#ifdef RLIMIT_RTTIME
+ set_one_rlimit(&conf->rlimit_rttime, RLIMIT_RTTIME, "RLIMIT_RTTIME");
+#endif
}
#endif
-int main(int argc, char *argv[]) {
- pa_core *c;
- pa_strbuf *buf = NULL;
- pa_daemon_conf *conf;
- pa_mainloop *mainloop;
+static char *check_configured_address(void) {
+ char *default_server = NULL;
+ pa_client_conf *c = pa_client_conf_new();
- char *s;
- int r, retval = 1, d = 0;
- int daemon_pipe[2] = { -1, -1 };
- int suid_root, real_root;
- int valid_pid_file = 0;
+ pa_client_conf_load(c, NULL);
+#ifdef HAVE_X11
+ pa_client_conf_from_x11(c, NULL);
+#endif
+ pa_client_conf_env(c);
-#ifdef HAVE_GETUID
- gid_t gid = (gid_t) -1;
+ if (c->default_server && *c->default_server)
+ default_server = pa_xstrdup(c->default_server);
+
+ pa_client_conf_free(c);
+
+ return default_server;
+}
+
+#ifdef HAVE_DBUS
+static pa_dbus_connection *register_dbus_name(pa_core *c, DBusBusType bus, const char* name) {
+ DBusError error;
+ pa_dbus_connection *conn;
+
+ dbus_error_init(&error);
+
+ if (!(conn = pa_dbus_bus_get(c, bus, &error)) || dbus_error_is_set(&error)) {
+ pa_log_warn("Unable to contact D-Bus: %s: %s", error.name, error.message);
+ goto fail;
+ }
+
+ if (dbus_bus_request_name(pa_dbus_connection_get(conn), name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ pa_log_debug("Got %s!", name);
+ return conn;
+ }
+
+ if (dbus_error_is_set(&error))
+ pa_log_error("Failed to acquire %s: %s: %s", name, error.name, error.message);
+ else
+ pa_log_error("D-Bus name %s already taken. Weird shit!", name);
+
+ /* PA cannot be started twice by the same user and hence we can
+ * ignore mostly the case that a name is already taken. */
+
+fail:
+ if (conn)
+ pa_dbus_connection_unref(conn);
+
+ dbus_error_free(&error);
+ return NULL;
+}
#endif
+int main(int argc, char *argv[]) {
+ pa_core *c = NULL;
+ pa_strbuf *buf = NULL;
+ pa_daemon_conf *conf = NULL;
+ pa_mainloop *mainloop = NULL;
+ char *s;
+ char *configured_address;
+ int r = 0, retval = 1, d = 0;
+ pa_bool_t valid_pid_file = FALSE;
+ pa_bool_t ltdl_init = FALSE;
+ int passed_fd = -1;
+ const char *e;
+#ifdef HAVE_FORK
+ int daemon_pipe[2] = { -1, -1 };
+ int daemon_pipe2[2] = { -1, -1 };
+#endif
#ifdef OS_IS_WIN32
- pa_time_event *timer;
- struct timeval tv;
+ pa_time_event *win32_timer;
+ struct timeval win32_tv;
+#endif
+ int autospawn_fd = -1;
+ pa_bool_t autospawn_locked = FALSE;
+#ifdef HAVE_DBUS
+ pa_dbusobj_server_lookup *server_lookup = NULL; /* /org/pulseaudio/server_lookup */
+ pa_dbus_connection *lookup_service_bus = NULL; /* Always the user bus. */
+ pa_dbus_connection *server_bus = NULL; /* The bus where we reserve org.pulseaudio.Server, either the user or the system bus. */
+ pa_bool_t start_server;
#endif
- setlocale(LC_ALL, "");
+ pa_log_set_ident("pulseaudio");
+ pa_log_set_level(PA_LOG_NOTICE);
+ pa_log_set_flags(PA_LOG_COLORS|PA_LOG_PRINT_FILE|PA_LOG_PRINT_LEVEL, PA_LOG_RESET);
- pa_limit_caps();
+#if defined(__linux__) && defined(__OPTIMIZE__)
+ /*
+ Disable lazy relocations to make usage of external libraries
+ more deterministic for our RT threads. We abuse __OPTIMIZE__ as
+ a check whether we are a debug build or not. This all is
+ admittedly a bit snake-oilish.
+ */
-#ifdef HAVE_GETUID
- real_root = getuid() == 0;
- suid_root = !real_root && geteuid() == 0;
-
- if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0 || gid >= 1000)) {
- pa_log_warn(__FILE__": WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'.");
- pa_drop_root();
+ if (!getenv("LD_BIND_NOW")) {
+ char *rp;
+ char *canonical_rp;
+
+ /* We have to execute ourselves, because the libc caches the
+ * value of $LD_BIND_NOW on initialization. */
+
+ pa_set_env("LD_BIND_NOW", "1");
+
+ if ((canonical_rp = pa_realpath(PA_BINARY))) {
+
+ if ((rp = pa_readlink("/proc/self/exe"))) {
+
+ if (pa_streq(rp, canonical_rp))
+ pa_assert_se(execv(rp, argv) == 0);
+ else
+ pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp);
+
+ pa_xfree(rp);
+
+ } else
+ pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?");
+
+ pa_xfree(canonical_rp);
+
+ } else
+ pa_log_warn("Couldn't canonicalize binary path, cannot self execute.");
}
-#else
- real_root = 0;
- suid_root = 0;
#endif
-
- LTDL_SET_PRELOADED_SYMBOLS();
-
- r = lt_dlinit();
- assert(r == 0);
-#ifdef OS_IS_WIN32
- {
- WSADATA data;
- WSAStartup(MAKEWORD(2, 0), &data);
+ if ((e = getenv("PULSE_PASSED_FD"))) {
+ passed_fd = atoi(e);
+
+ if (passed_fd <= 2)
+ passed_fd = -1;
}
-#endif
- pa_random_seed();
-
- pa_log_set_ident("pulseaudio");
-
+ /* We might be autospawned, in which case have no idea in which
+ * context we have been started. Let's cleanup our execution
+ * context as good as possible */
+
+ pa_reset_personality();
+ pa_drop_root();
+ pa_close_all(passed_fd, -1);
+ pa_reset_sigs(-1);
+ pa_unblock_sigs(-1);
+ pa_reset_priority();
+
+ setlocale(LC_ALL, "");
+ pa_init_i18n();
+
conf = pa_daemon_conf_new();
-
+
if (pa_daemon_conf_load(conf, NULL) < 0)
goto finish;
@@ -368,24 +492,60 @@ int main(int argc, char *argv[]) {
goto finish;
if (pa_cmdline_parse(conf, argc, argv, &d) < 0) {
- pa_log(__FILE__": failed to parse command line.");
+ pa_log(_("Failed to parse command line."));
goto finish;
}
- pa_log_set_maximal_level(conf->log_level);
- pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target, NULL);
+ pa_log_set_level(conf->log_level);
+ pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target);
+ if (conf->log_meta)
+ pa_log_set_flags(PA_LOG_PRINT_META, PA_LOG_SET);
+ if (conf->log_time)
+ pa_log_set_flags(PA_LOG_PRINT_TIME, PA_LOG_SET);
+ pa_log_set_show_backtrace(conf->log_backtrace);
+
+#ifdef HAVE_DBUS
+ /* conf->system_instance and conf->local_server_type control almost the
+ * same thing; make them agree about what is requested. */
+ switch (conf->local_server_type) {
+ case PA_SERVER_TYPE_UNSET:
+ conf->local_server_type = conf->system_instance ? PA_SERVER_TYPE_SYSTEM : PA_SERVER_TYPE_USER;
+ break;
+ case PA_SERVER_TYPE_USER:
+ case PA_SERVER_TYPE_NONE:
+ conf->system_instance = FALSE;
+ break;
+ case PA_SERVER_TYPE_SYSTEM:
+ conf->system_instance = TRUE;
+ break;
+ default:
+ pa_assert_not_reached();
+ }
- if (conf->high_priority && conf->cmd == PA_CMD_DAEMON)
- pa_raise_priority();
+ start_server = conf->local_server_type == PA_SERVER_TYPE_USER || (getuid() == 0 && conf->local_server_type == PA_SERVER_TYPE_SYSTEM);
- pa_drop_caps();
+ if (!start_server && conf->local_server_type == PA_SERVER_TYPE_SYSTEM) {
+ pa_log_notice(_("System mode refused for non-root user. Only starting the D-Bus server lookup service."));
+ conf->system_instance = FALSE;
+ }
+#endif
- if (suid_root)
- pa_drop_root();
+ LTDL_SET_PRELOADED_SYMBOLS();
+ pa_ltdl_init();
+ ltdl_init = TRUE;
if (conf->dl_search_path)
lt_dlsetsearchpath(conf->dl_search_path);
+#ifdef OS_IS_WIN32
+ {
+ WSADATA data;
+ WSAStartup(MAKEWORD(2, 0), &data);
+ }
+#endif
+
+ pa_random_seed();
+
switch (conf->cmd) {
case PA_CMD_DUMP_MODULES:
pa_dump_modules(conf, argc-d, argv+d);
@@ -393,6 +553,12 @@ int main(int argc, char *argv[]) {
goto finish;
case PA_CMD_DUMP_CONF: {
+
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
+ goto finish;
+ }
+
s = pa_daemon_conf_dump(conf);
fputs(s, stdout);
pa_xfree(s);
@@ -400,12 +566,34 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ case PA_CMD_DUMP_RESAMPLE_METHODS: {
+ int i;
+
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
+ goto finish;
+ }
+
+ for (i = 0; i < PA_RESAMPLER_MAX; i++)
+ if (pa_resample_method_supported(i))
+ printf("%s\n", pa_resample_method_to_string(i));
+
+ retval = 0;
+ goto finish;
+ }
+
case PA_CMD_HELP :
pa_cmdline_help(argv[0]);
retval = 0;
goto finish;
case PA_CMD_VERSION :
+
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
+ goto finish;
+ }
+
printf(PACKAGE_NAME" "PACKAGE_VERSION"\n");
retval = 0;
goto finish;
@@ -413,10 +601,15 @@ int main(int argc, char *argv[]) {
case PA_CMD_CHECK: {
pid_t pid;
- if (pa_pid_file_check_running(&pid) < 0) {
- pa_log_info(__FILE__": daemon not running");
- } else {
- pa_log_info(__FILE__": daemon running as PID %u", pid);
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
+ goto finish;
+ }
+
+ if (pa_pid_file_check_running(&pid, "pulseaudio") < 0)
+ pa_log_info(_("Daemon not running"));
+ else {
+ pa_log_info(_("Daemon running as PID %u"), pid);
retval = 0;
}
@@ -425,87 +618,253 @@ int main(int argc, char *argv[]) {
}
case PA_CMD_KILL:
- if (pa_pid_file_kill(SIGINT, NULL) < 0)
- pa_log(__FILE__": failed to kill daemon.");
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
+ goto finish;
+ }
+
+ if (pa_pid_file_kill(SIGINT, NULL, "pulseaudio") < 0)
+ pa_log(_("Failed to kill daemon: %s"), pa_cstrerror(errno));
else
retval = 0;
-
+
+ goto finish;
+
+ case PA_CMD_CLEANUP_SHM:
+
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
+ goto finish;
+ }
+
+ if (pa_shm_cleanup() >= 0)
+ retval = 0;
+
goto finish;
-
+
default:
- assert(conf->cmd == PA_CMD_DAEMON);
+ pa_assert(conf->cmd == PA_CMD_DAEMON || conf->cmd == PA_CMD_START);
}
- if (real_root && !conf->system_instance) {
- pa_log_warn(__FILE__": This program is not intended to be run as root (unless --system is specified).");
- } else if (!real_root && conf->system_instance) {
- pa_log(__FILE__": Root priviliges required.");
+ if (d < argc) {
+ pa_log("Too many arguments.\n");
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. */
+ else if (getuid() != 0 && conf->system_instance) {
+ pa_log(_("Root privileges required."));
+ goto finish;
+ }
+#endif
+#endif /* HAVE_GETUID */
+
+ if (conf->cmd == PA_CMD_START && conf->system_instance) {
+ pa_log(_("--start not supported for system instances."));
+ goto finish;
+ }
+
+ if (conf->cmd == PA_CMD_START && (configured_address = check_configured_address())) {
+ /* There is an server address in our config, but where did it come from?
+ * By default a standard X11 login will load module-x11-publish which will
+ * inject PULSE_SERVER X11 property. If the PA daemon crashes, we will end
+ * up hitting this code path. So we have to check to see if our configured_address
+ * is the same as the value that would go into this property so that we can
+ * recover (i.e. autospawn) from a crash.
+ */
+ char *ufn;
+ pa_bool_t start_anyway = FALSE;
+
+ if ((ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET))) {
+ char *id;
+
+ if ((id = pa_machine_id())) {
+ pa_strlist *server_list;
+ char formatted_ufn[256];
+
+ pa_snprintf(formatted_ufn, sizeof(formatted_ufn), "{%s}unix:%s", id, ufn);
+ pa_xfree(id);
+
+ if ((server_list = pa_strlist_parse(configured_address))) {
+ char *u = NULL;
+
+ /* We only need to check the first server */
+ server_list = pa_strlist_pop(server_list, &u);
+ pa_strlist_free(server_list);
+
+ start_anyway = (u && pa_streq(formatted_ufn, u));
+ pa_xfree(u);
+ }
+ }
+ pa_xfree(ufn);
+ }
+
+ if (!start_anyway) {
+ pa_log_notice(_("User-configured server at %s, refusing to start/autospawn."), configured_address);
+ pa_xfree(configured_address);
+ retval = 0;
+ goto finish;
+ }
+
+ pa_log_notice(_("User-configured server at %s, which appears to be local. Probing deeper."), configured_address);
+ pa_xfree(configured_address);
+ }
+
+ if (conf->system_instance && !conf->disallow_exit)
+ pa_log_warn(_("Running in system mode, but --disallow-exit not set!"));
+
+ if (conf->system_instance && !conf->disallow_module_loading)
+ pa_log_warn(_("Running in system mode, but --disallow-module-loading not set!"));
+
+ if (conf->system_instance && !conf->disable_shm) {
+ pa_log_notice(_("Running in system mode, forcibly disabling SHM mode!"));
+ conf->disable_shm = TRUE;
+ }
+
+ if (conf->system_instance && conf->exit_idle_time >= 0) {
+ pa_log_notice(_("Running in system mode, forcibly disabling exit idle time!"));
+ conf->exit_idle_time = -1;
+ }
+
+ if (conf->cmd == PA_CMD_START) {
+ /* If we shall start PA only when it is not running yet, we
+ * first take the autospawn lock to make things
+ * synchronous. */
+
+ if ((autospawn_fd = pa_autospawn_lock_init()) < 0) {
+ pa_log("Failed to initialize autospawn lock");
+ goto finish;
+ }
+
+ if ((pa_autospawn_lock_acquire(TRUE) < 0)) {
+ pa_log("Failed to acquire autospawn lock");
+ goto finish;
+ }
+
+ autospawn_locked = TRUE;
+ }
+
if (conf->daemonize) {
+#ifdef HAVE_FORK
pid_t child;
- int tty_fd;
+#endif
if (pa_stdio_acquire() < 0) {
- pa_log(__FILE__": failed to acquire stdio.");
+ pa_log(_("Failed to acquire stdio."));
goto finish;
}
#ifdef HAVE_FORK
if (pipe(daemon_pipe) < 0) {
- pa_log(__FILE__": failed to create pipe.");
+ pa_log(_("pipe() failed: %s"), pa_cstrerror(errno));
goto finish;
}
-
+
if ((child = fork()) < 0) {
- pa_log(__FILE__": fork() failed: %s", pa_cstrerror(errno));
+ pa_log(_("fork() failed: %s"), pa_cstrerror(errno));
+ pa_close_pipe(daemon_pipe);
goto finish;
}
if (child != 0) {
+ ssize_t n;
/* Father */
- close(daemon_pipe[1]);
+ pa_assert_se(pa_close(daemon_pipe[1]) == 0);
daemon_pipe[1] = -1;
- if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval), NULL) != sizeof(retval)) {
- pa_log(__FILE__": read() failed: %s", pa_cstrerror(errno));
+ if ((n = pa_loop_read(daemon_pipe[0], &retval, sizeof(retval), NULL)) != sizeof(retval)) {
+
+ if (n < 0)
+ pa_log(_("read() failed: %s"), pa_cstrerror(errno));
+
retval = 1;
}
if (retval)
- pa_log(__FILE__": daemon startup failed.");
+ pa_log(_("Daemon startup failed."));
else
- pa_log_info(__FILE__": daemon startup successful.");
-
+ pa_log_info(_("Daemon startup successful."));
+
goto finish;
}
- close(daemon_pipe[0]);
+ if (autospawn_fd >= 0) {
+ /* The lock file is unlocked from the parent, so we need
+ * to close it in the child */
+
+ pa_autospawn_lock_release();
+ pa_autospawn_lock_done(TRUE);
+
+ autospawn_locked = FALSE;
+ autospawn_fd = -1;
+ }
+
+ pa_assert_se(pa_close(daemon_pipe[0]) == 0);
daemon_pipe[0] = -1;
#endif
if (conf->auto_log_target)
- pa_log_set_target(PA_LOG_SYSLOG, NULL);
+ pa_log_set_target(PA_LOG_SYSLOG);
#ifdef HAVE_SETSID
- setsid();
-#endif
-#ifdef HAVE_SETPGID
- setpgid(0,0);
+ if (setsid() < 0) {
+ pa_log(_("setsid() failed: %s"), pa_cstrerror(errno));
+ goto finish;
+ }
#endif
-#ifndef OS_IS_WIN32
- close(0);
- close(1);
- close(2);
+#ifdef HAVE_FORK
+ /* We now are a session and process group leader. Let's fork
+ * again and let the father die, so that we'll become a
+ * process that can never acquire a TTY again, in a session and
+ * process group without leader */
- open("/dev/null", O_RDONLY);
- open("/dev/null", O_WRONLY);
- open("/dev/null", O_WRONLY);
-#else
- FreeConsole();
+ if (pipe(daemon_pipe2) < 0) {
+ pa_log(_("pipe() failed: %s"), pa_cstrerror(errno));
+ goto finish;
+ }
+
+ if ((child = fork()) < 0) {
+ pa_log(_("fork() failed: %s"), pa_cstrerror(errno));
+ pa_close_pipe(daemon_pipe2);
+ goto finish;
+ }
+
+ if (child != 0) {
+ ssize_t n;
+ /* Father */
+
+ pa_assert_se(pa_close(daemon_pipe2[1]) == 0);
+ daemon_pipe2[1] = -1;
+
+ if ((n = pa_loop_read(daemon_pipe2[0], &retval, sizeof(retval), NULL)) != sizeof(retval)) {
+
+ if (n < 0)
+ pa_log(_("read() failed: %s"), pa_cstrerror(errno));
+
+ retval = 1;
+ }
+
+ /* We now have to take care of signalling the first fork with
+ * the return value we've received from this fork... */
+ pa_assert(daemon_pipe[1] >= 0);
+
+ pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
+ pa_close(daemon_pipe[1]);
+ daemon_pipe[1] = -1;
+
+ goto finish;
+ }
+
+ pa_assert_se(pa_close(daemon_pipe2[0]) == 0);
+ daemon_pipe2[0] = -1;
+
+ /* We no longer need the (first) daemon_pipe as it's handled in our child above */
+ pa_close_pipe(daemon_pipe);
#endif
#ifdef SIGTTOU
@@ -517,57 +876,174 @@ int main(int argc, char *argv[]) {
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif
-
-#ifdef TIOCNOTTY
- if ((tty_fd = open("/dev/tty", O_RDWR)) >= 0) {
- ioctl(tty_fd, TIOCNOTTY, (char*) 0);
- close(tty_fd);
- }
-#endif
+
+ pa_nullify_stdfds();
}
- chdir("/");
+ pa_set_env_and_record("PULSE_INTERNAL", "1");
+ pa_assert_se(chdir("/") == 0);
umask(0022);
-
- if (conf->system_instance) {
+
+#ifdef HAVE_SYS_RESOURCE_H
+ set_all_rlimits(conf);
+#endif
+ pa_rtclock_hrtimer_enable();
+
+ pa_raise_priority(conf->nice_level);
+
+ if (conf->system_instance)
if (change_user() < 0)
goto finish;
- } else if (create_runtime_dir() < 0)
+
+ pa_set_env_and_record("PULSE_SYSTEM", conf->system_instance ? "1" : "0");
+
+ pa_log_info(_("This is PulseAudio %s"), PACKAGE_VERSION);
+ pa_log_debug(_("Compilation host: %s"), CANONICAL_HOST);
+ pa_log_debug(_("Compilation CFLAGS: %s"), PA_CFLAGS);
+
+ s = pa_uname_string();
+ pa_log_debug(_("Running on host: %s"), s);
+ pa_xfree(s);
+
+ pa_log_debug(_("Found %u CPUs."), pa_ncpus());
+
+ pa_log_info(_("Page size is %lu bytes"), (unsigned long) PA_PAGE_SIZE);
+
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ pa_log_debug(_("Compiled with Valgrind support: yes"));
+#else
+ pa_log_debug(_("Compiled with Valgrind support: no"));
+#endif
+
+ pa_log_debug(_("Running in valgrind mode: %s"), pa_yes_no(pa_in_valgrind()));
+
+ pa_log_debug(_("Running in VM: %s"), pa_yes_no(pa_running_in_vm()));
+
+#ifdef __OPTIMIZE__
+ pa_log_debug(_("Optimized build: yes"));
+#else
+ pa_log_debug(_("Optimized build: no"));
+#endif
+
+#ifdef NDEBUG
+ pa_log_debug(_("NDEBUG defined, all asserts disabled."));
+#elif defined(FASTPATH)
+ pa_log_debug(_("FASTPATH defined, only fast path asserts disabled."));
+#else
+ pa_log_debug(_("All asserts enabled."));
+#endif
+
+ if (!(s = pa_machine_id())) {
+ pa_log(_("Failed to get machine ID"));
goto finish;
-
+ }
+ pa_log_info(_("Machine ID is %s."), s);
+ pa_xfree(s);
+
+ if ((s = pa_session_id())) {
+ pa_log_info(_("Session ID is %s."), s);
+ pa_xfree(s);
+ }
+
+ if (!(s = pa_get_runtime_dir()))
+ goto finish;
+ pa_log_info(_("Using runtime directory %s."), s);
+ pa_xfree(s);
+
+ if (!(s = pa_get_state_dir()))
+ goto finish;
+ pa_log_info(_("Using state directory %s."), s);
+ pa_xfree(s);
+
+ pa_log_info(_("Using modules directory %s."), conf->dl_search_path);
+
+ pa_log_info(_("Running in system mode: %s"), pa_yes_no(pa_in_system_mode()));
+
+ if (pa_in_system_mode())
+ pa_log_warn(_("OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.\n"
+ "If you do it nonetheless then it's your own fault if things don't work as expected.\n"
+ "Please read http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode for an explanation why system mode is usually a bad idea."));
+
if (conf->use_pid_file) {
- if (pa_pid_file_create() < 0) {
- pa_log(__FILE__": pa_pid_file_create() failed.");
-#ifdef HAVE_FORK
- if (conf->daemonize)
- pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
-#endif
+ int z;
+
+ if ((z = pa_pid_file_create("pulseaudio")) != 0) {
+
+ if (conf->cmd == PA_CMD_START && z > 0) {
+ /* If we are already running and with are run in
+ * --start mode, then let's return this as success. */
+
+ retval = 0;
+ goto finish;
+ }
+
+ pa_log(_("pa_pid_file_create() failed."));
goto finish;
}
- valid_pid_file = 1;
+ valid_pid_file = TRUE;
}
-#ifdef HAVE_SYS_RESOURCE_H
- set_all_rlimits(conf);
-#endif
-
-#ifdef SIGPIPE
- signal(SIGPIPE, SIG_IGN);
+ pa_disable_sigpipe();
+
+ if (pa_rtclock_hrtimer())
+ pa_log_info(_("Fresh high-resolution timers available! Bon appetit!"));
+ else
+ pa_log_info(_("Dude, your kernel stinks! The chef's recommendation today is Linux with high-resolution timers enabled!"));
+
+ if (conf->lock_memory) {
+#ifdef HAVE_SYS_MMAN_H
+ if (mlockall(MCL_FUTURE) < 0)
+ pa_log_warn("mlockall() failed: %s", pa_cstrerror(errno));
+ else
+ pa_log_info("Successfully locked process into memory.");
+#else
+ pa_log_warn("Memory locking requested but not supported on platform.");
#endif
+ }
+
+ pa_memtrap_install();
+
+ pa_assert_se(mainloop = pa_mainloop_new());
- mainloop = pa_mainloop_new();
- assert(mainloop);
+ if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm, conf->shm_size))) {
+ pa_log(_("pa_core_new() failed."));
+ goto finish;
+ }
- c = pa_core_new(pa_mainloop_get_api(mainloop));
- assert(c);
- c->is_system_instance = !!conf->system_instance;
+ c->default_sample_spec = conf->default_sample_spec;
+ c->default_channel_map = conf->default_channel_map;
+ c->default_n_fragments = conf->default_n_fragments;
+ c->default_fragment_size_msec = conf->default_fragment_size_msec;
+ c->sync_volume_safety_margin_usec = conf->sync_volume_safety_margin_usec;
+ c->sync_volume_extra_delay_usec = conf->sync_volume_extra_delay_usec;
+ c->exit_idle_time = conf->exit_idle_time;
+ c->scache_idle_time = conf->scache_idle_time;
+ c->resample_method = conf->resample_method;
+ c->realtime_priority = conf->realtime_priority;
+ c->realtime_scheduling = !!conf->realtime_scheduling;
+ c->disable_remixing = !!conf->disable_remixing;
+ c->disable_lfe_remixing = !!conf->disable_lfe_remixing;
+ c->sync_volume = !!conf->sync_volume;
+ c->running_as_daemon = !!conf->daemonize;
+ c->disallow_exit = conf->disallow_exit;
+ c->flat_volumes = conf->flat_volumes;
+#ifdef HAVE_DBUS
+ c->server_type = conf->local_server_type;
+#endif
+
+ c->cpu_info.cpu_type = PA_CPU_UNDEFINED;
+ if (!getenv("PULSE_NO_SIMD")) {
+ if (pa_cpu_init_x86(&(c->cpu_info.flags.x86)))
+ c->cpu_info.cpu_type = PA_CPU_X86;
+ if (pa_cpu_init_arm(&(c->cpu_info.flags.arm)))
+ c->cpu_info.cpu_type = PA_CPU_ARM;
+ pa_cpu_init_orc(c->cpu_info);
+ }
- r = pa_signal_init(pa_mainloop_get_api(mainloop));
- assert(r == 0);
+ pa_assert_se(pa_signal_init(pa_mainloop_get_api(mainloop)) == 0);
pa_signal_new(SIGINT, signal_callback, c);
pa_signal_new(SIGTERM, signal_callback, c);
-
#ifdef SIGUSR1
pa_signal_new(SIGUSR1, signal_callback, c);
#endif
@@ -577,95 +1053,152 @@ int main(int argc, char *argv[]) {
#ifdef SIGHUP
pa_signal_new(SIGHUP, signal_callback, c);
#endif
-
+
#ifdef OS_IS_WIN32
- timer = pa_mainloop_get_api(mainloop)->time_new(
- pa_mainloop_get_api(mainloop), pa_gettimeofday(&tv), message_cb, NULL);
- assert(timer);
+ win32_timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL);
#endif
- if (conf->daemonize)
- c->running_as_daemon = 1;
+ if (!conf->no_cpu_limit)
+ pa_assert_se(pa_cpu_limit_init(pa_mainloop_get_api(mainloop)) == 0);
- oil_init();
-
- r = pa_cpu_limit_init(pa_mainloop_get_api(mainloop));
- assert(r == 0);
-
buf = pa_strbuf_new();
- if (conf->default_script_file)
- r = pa_cli_command_execute_file(c, conf->default_script_file, buf, &conf->fail);
- if (r >= 0)
- r = pa_cli_command_execute(c, conf->script_commands, buf, &conf->fail);
- pa_log_error("%s", s = pa_strbuf_tostring_free(buf));
- pa_xfree(s);
-
- if (r < 0 && conf->fail) {
- pa_log(__FILE__": failed to initialize daemon.");
-#ifdef HAVE_FORK
- if (conf->daemonize)
- pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
-#endif
- } else if (!c->modules || pa_idxset_size(c->modules) == 0) {
- pa_log(__FILE__": daemon startup without any loaded modules, refusing to work.");
-#ifdef HAVE_FORK
- if (conf->daemonize)
- pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
+#ifdef HAVE_DBUS
+ if (start_server) {
#endif
+ if (conf->load_default_script_file) {
+ FILE *f;
+
+ if ((f = pa_daemon_conf_open_default_script_file(conf))) {
+ r = pa_cli_command_execute_file_stream(c, f, buf, &conf->fail);
+ fclose(f);
+ }
+ }
+
+ if (r >= 0)
+ r = pa_cli_command_execute(c, conf->script_commands, buf, &conf->fail);
+
+ pa_log_error("%s", s = pa_strbuf_tostring_free(buf));
+ pa_xfree(s);
+
+ if (r < 0 && conf->fail) {
+ pa_log(_("Failed to initialize daemon."));
+ goto finish;
+ }
+
+ if (!c->modules || pa_idxset_size(c->modules) == 0) {
+ pa_log(_("Daemon startup without any loaded modules, refusing to work."));
+ goto finish;
+ }
+#ifdef HAVE_DBUS
} else {
+ /* When we just provide the D-Bus server lookup service, we don't want
+ * any modules to be loaded. We haven't loaded any so far, so one might
+ * think there's no way to contact the server, but receiving certain
+ * signals could still cause modules to load. */
+ conf->disallow_module_loading = TRUE;
+ }
+#endif
+
+ /* We completed the initial module loading, so let's disable it
+ * from now on, if requested */
+ c->disallow_module_loading = !!conf->disallow_module_loading;
+
+#ifdef HAVE_DBUS
+ if (!conf->system_instance) {
+ if (!(server_lookup = pa_dbusobj_server_lookup_new(c)))
+ goto finish;
+ if (!(lookup_service_bus = register_dbus_name(c, DBUS_BUS_SESSION, "org.PulseAudio1")))
+ goto finish;
+ }
+
+ if (start_server && !(server_bus = register_dbus_name(c, conf->system_instance ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, "org.pulseaudio.Server")))
+ goto finish;
+#endif
- retval = 0;
#ifdef HAVE_FORK
- if (conf->daemonize)
- pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
+ if (daemon_pipe2[1] >= 0) {
+ int ok = 0;
+ pa_loop_write(daemon_pipe2[1], &ok, sizeof(ok), NULL);
+ pa_close(daemon_pipe2[1]);
+ daemon_pipe2[1] = -1;
+ }
#endif
- c->disallow_module_loading = conf->disallow_module_loading;
- c->exit_idle_time = conf->exit_idle_time;
- c->module_idle_time = conf->module_idle_time;
- c->scache_idle_time = conf->scache_idle_time;
- c->resample_method = conf->resample_method;
+ pa_log_info(_("Daemon startup complete."));
- if (c->default_sink_name &&
- pa_namereg_get(c, c->default_sink_name, PA_NAMEREG_SINK, 1) == NULL) {
- pa_log_error("%s : Fatal error. Default sink name (%s) does not exist in name register.", __FILE__, c->default_sink_name);
- retval = 1;
- } else {
- pa_log_info(__FILE__": Daemon startup complete.");
- if (pa_mainloop_run(mainloop, &retval) < 0)
- retval = 1;
- pa_log_info(__FILE__": Daemon shutdown initiated.");
- }
+ retval = 0;
+ if (pa_mainloop_run(mainloop, &retval) < 0)
+ goto finish;
+
+ pa_log_info(_("Daemon shutdown initiated."));
+
+finish:
+#ifdef HAVE_DBUS
+ if (server_bus)
+ pa_dbus_connection_unref(server_bus);
+ if (lookup_service_bus)
+ pa_dbus_connection_unref(lookup_service_bus);
+ if (server_lookup)
+ pa_dbusobj_server_lookup_free(server_lookup);
+#endif
+
+ if (autospawn_fd >= 0) {
+ if (autospawn_locked)
+ pa_autospawn_lock_release();
+
+ pa_autospawn_lock_done(FALSE);
}
#ifdef OS_IS_WIN32
- pa_mainloop_get_api(mainloop)->time_free(timer);
+ if (mainloop && win32_timer)
+ pa_mainloop_get_api(mainloop)->time_free(win32_timer);
#endif
- pa_core_free(c);
+ if (c) {
+ pa_core_unref(c);
+ pa_log_info(_("Daemon terminated."));
+ }
+
+ if (!conf->no_cpu_limit)
+ pa_cpu_limit_done();
- pa_cpu_limit_done();
pa_signal_done();
- pa_mainloop_free(mainloop);
-
- pa_log_info(__FILE__": Daemon terminated.");
-
-finish:
+
+#ifdef HAVE_FORK
+ /* If we have daemon_pipe[1] still open, this means we've failed after
+ * the first fork, but before the second. Therefore just write to it. */
+ if (daemon_pipe[1] >= 0)
+ pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
+ else if (daemon_pipe2[1] >= 0)
+ pa_loop_write(daemon_pipe2[1], &retval, sizeof(retval), NULL);
+
+ pa_close_pipe(daemon_pipe2);
+ pa_close_pipe(daemon_pipe);
+#endif
+
+ if (mainloop)
+ pa_mainloop_free(mainloop);
if (conf)
pa_daemon_conf_free(conf);
if (valid_pid_file)
pa_pid_file_remove();
-
- close_pipe(daemon_pipe);
+
+ /* This has no real purpose except making things valgrind-clean */
+ pa_unset_env_recorded();
#ifdef OS_IS_WIN32
WSACleanup();
#endif
- lt_dlexit();
-
+ if (ltdl_init)
+ pa_ltdl_done();
+
+#ifdef HAVE_DBUS
+ dbus_shutdown();
+#endif
+
return retval;
}
diff --git a/src/daemon/pulseaudio-kde.desktop.in b/src/daemon/pulseaudio-kde.desktop.in
new file mode 100644
index 00000000..06846421
--- /dev/null
+++ b/src/daemon/pulseaudio-kde.desktop.in
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Version=1.0
+Encoding=UTF-8
+_Name=PulseAudio Sound System KDE Routing Policy
+_Comment=Start the PulseAudio Sound System with KDE Routing Policy
+Exec=start-pulseaudio-kde
+Terminal=false
+Type=Application
+Categories=
+GenericName=
+OnlyShowIn=KDE;
diff --git a/src/daemon/pulseaudio-system.conf b/src/daemon/pulseaudio-system.conf
new file mode 100644
index 00000000..edddaf93
--- /dev/null
+++ b/src/daemon/pulseaudio-system.conf
@@ -0,0 +1,37 @@
+<?xml version="1.0"?><!--*-nxml-*-->
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+
+<!--
+This file is part of PulseAudio.
+
+PulseAudio is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of the
+License, or (at your option) any later version.
+
+PulseAudio is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with PulseAudio; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+USA.
+-->
+
+<busconfig>
+
+ <!-- System-wide PulseAudio runs as 'pulse' user. This fragment is
+ not necessary for user PulseAudio instances. -->
+
+ <policy user="pulse">
+ <allow own="org.pulseaudio.Server"/>
+
+ <!-- Allow pulseaudio to talk to HAL for device detection -->
+ <allow send_destination="org.freedesktop.Hal" send_interface="org.freedesktop.Hal.Manager"/>
+ <allow send_destination="org.freedesktop.Hal" send_interface="org.freedesktop.Hal.Device"/>
+ </policy>
+
+</busconfig>
diff --git a/src/daemon/pulseaudio.desktop.in b/src/daemon/pulseaudio.desktop.in
new file mode 100644
index 00000000..99bdbd00
--- /dev/null
+++ b/src/daemon/pulseaudio.desktop.in
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Version=1.0
+Encoding=UTF-8
+_Name=PulseAudio Sound System
+_Comment=Start the PulseAudio Sound System
+Exec=start-pulseaudio-x11
+Terminal=false
+Type=Application
+Categories=
+GenericName=
diff --git a/src/daemon/server-lookup.c b/src/daemon/server-lookup.c
new file mode 100644
index 00000000..45796e72
--- /dev/null
+++ b/src/daemon/server-lookup.c
@@ -0,0 +1,522 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2009 Tanu Kaskinen
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <dbus/dbus.h>
+
+#include <pulse/client-conf.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/core.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/dbus-shared.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/protocol-dbus.h>
+
+#include "server-lookup.h"
+
+#define OBJECT_PATH "/org/pulseaudio/server_lookup1"
+#define INTERFACE "org.PulseAudio.ServerLookup1"
+
+struct pa_dbusobj_server_lookup {
+ pa_core *core;
+ pa_dbus_connection *conn;
+ pa_bool_t path_registered;
+};
+
+static const char introspection[] =
+ DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
+ "<node>"
+ " <!-- If you are looking for documentation make sure to check out\n"
+ " http://pulseaudio.org/wiki/DBusInterface -->\n"
+ " <interface name=\"" INTERFACE "\">\n"
+ " <property name=\"Address\" type=\"s\" access=\"read\"/>\n"
+ " </interface>\n"
+ " <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n"
+ " <method name=\"Introspect\">\n"
+ " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"
+ " </method>\n"
+ " </interface>\n"
+ " <interface name=\"" DBUS_INTERFACE_PROPERTIES "\">\n"
+ " <method name=\"Get\">\n"
+ " <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n"
+ " <arg name=\"property_name\" type=\"s\" direction=\"in\"/>\n"
+ " <arg name=\"value\" type=\"v\" direction=\"out\"/>\n"
+ " </method>\n"
+ " <method name=\"Set\">\n"
+ " <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n"
+ " <arg name=\"property_name\" type=\"s\" direction=\"in\"/>\n"
+ " <arg name=\"value\" type=\"v\" direction=\"in\"/>\n"
+ " </method>\n"
+ " <method name=\"GetAll\">\n"
+ " <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n"
+ " <arg name=\"props\" type=\"a{sv}\" direction=\"out\"/>\n"
+ " </method>\n"
+ " </interface>\n"
+ "</node>\n";
+
+static void unregister_cb(DBusConnection *conn, void *user_data) {
+ pa_dbusobj_server_lookup *sl = user_data;
+
+ pa_assert(sl);
+ pa_assert(sl->path_registered);
+
+ sl->path_registered = FALSE;
+}
+
+static DBusHandlerResult handle_introspect(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_server_lookup *sl) {
+ DBusHandlerResult r = DBUS_HANDLER_RESULT_HANDLED;
+ const char *i = introspection;
+ DBusMessage *reply = NULL;
+
+ pa_assert(conn);
+ pa_assert(msg);
+
+ if (!(reply = dbus_message_new_method_return(msg))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &i, DBUS_TYPE_INVALID)) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+
+finish:
+ if (reply)
+ dbus_message_unref(reply);
+
+ return r;
+}
+
+enum get_address_result_t {
+ SUCCESS,
+ FAILED_TO_LOAD_CLIENT_CONF,
+ SERVER_FROM_TYPE_FAILED
+};
+
+/* Caller frees the returned address. */
+static enum get_address_result_t get_address(pa_server_type_t server_type, char **address) {
+ enum get_address_result_t r = SUCCESS;
+ pa_client_conf *conf = pa_client_conf_new();
+
+ *address = NULL;
+
+ if (pa_client_conf_load(conf, NULL) < 0) {
+ r = FAILED_TO_LOAD_CLIENT_CONF;
+ goto finish;
+ }
+
+ if (conf->default_dbus_server)
+ *address = pa_xstrdup(conf->default_dbus_server);
+ else if (!(*address = pa_get_dbus_address_from_server_type(server_type))) {
+ r = SERVER_FROM_TYPE_FAILED;
+ goto finish;
+ }
+
+finish:
+ pa_client_conf_free(conf);
+ return r;
+}
+
+static DBusHandlerResult handle_get_address(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_server_lookup *sl) {
+ DBusHandlerResult r = DBUS_HANDLER_RESULT_HANDLED;
+ DBusMessage *reply = NULL;
+ char *address = NULL;
+ DBusMessageIter msg_iter;
+ DBusMessageIter variant_iter;
+
+ pa_assert(conn);
+ pa_assert(msg);
+ pa_assert(sl);
+
+ switch (get_address(sl->core->server_type, &address)) {
+ case SUCCESS:
+ if (!(reply = dbus_message_new_method_return(msg))) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ dbus_message_iter_init_append(reply, &msg_iter);
+ if (!dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_VARIANT, "s", &variant_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_STRING, &address)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_close_container(&msg_iter, &variant_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+
+ case FAILED_TO_LOAD_CLIENT_CONF:
+ if (!(reply = dbus_message_new_error(msg, "org.pulseaudio.ClientConfLoadError", "Failed to load client.conf."))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+
+ case SERVER_FROM_TYPE_FAILED:
+ if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, "PulseAudio internal error: get_dbus_server_from_type() failed."))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+
+ default:
+ pa_assert_not_reached();
+ }
+
+finish:
+ pa_xfree(address);
+ if (reply)
+ dbus_message_unref(reply);
+
+ return r;
+}
+
+static DBusHandlerResult handle_get(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_server_lookup *sl) {
+ DBusHandlerResult r = DBUS_HANDLER_RESULT_HANDLED;
+ const char* interface;
+ const char* property;
+ DBusMessage *reply = NULL;
+
+ pa_assert(conn);
+ pa_assert(msg);
+ pa_assert(sl);
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
+ if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, "Invalid arguments"))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+ }
+
+ if (*interface && !pa_streq(interface, INTERFACE)) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+
+ if (!pa_streq(property, "Address")) {
+ if (!(reply = dbus_message_new_error_printf(msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s: No such property", property))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+ }
+
+ r = handle_get_address(conn, msg, sl);
+
+finish:
+ if (reply)
+ dbus_message_unref(reply);
+
+ return r;
+}
+
+static DBusHandlerResult handle_set(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_server_lookup *sl) {
+ DBusHandlerResult r = DBUS_HANDLER_RESULT_HANDLED;
+ const char* interface;
+ const char* property;
+ DBusMessage *reply = NULL;
+
+ pa_assert(conn);
+ pa_assert(msg);
+ pa_assert(sl);
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
+ if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, "Invalid arguments"))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+ }
+
+ if (*interface && !pa_streq(interface, INTERFACE)) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+
+ if (!pa_streq(property, "Address")) {
+ if (!(reply = dbus_message_new_error_printf(msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s: No such property", property))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+ }
+
+ if (!(reply = dbus_message_new_error_printf(msg, DBUS_ERROR_ACCESS_DENIED, "%s: Property not settable", property))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+
+finish:
+ if (reply)
+ dbus_message_unref(reply);
+
+ return r;
+}
+
+static DBusHandlerResult handle_get_all(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_server_lookup *sl) {
+ DBusHandlerResult r = DBUS_HANDLER_RESULT_HANDLED;
+ DBusMessage *reply = NULL;
+ const char *property = "Address";
+ char *interface = NULL;
+ char *address = NULL;
+ DBusMessageIter msg_iter;
+ DBusMessageIter dict_iter;
+ DBusMessageIter dict_entry_iter;
+ DBusMessageIter variant_iter;
+
+ pa_assert(conn);
+ pa_assert(msg);
+ pa_assert(sl);
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID)) {
+ if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, "Invalid arguments"))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+ }
+
+ switch (get_address(sl->core->server_type, &address)) {
+ case SUCCESS:
+ if (!(reply = dbus_message_new_method_return(msg))) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ dbus_message_iter_init_append(reply, &msg_iter);
+ if (!dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_DICT_ENTRY, NULL, &dict_entry_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_append_basic(&dict_entry_iter, DBUS_TYPE_STRING, &property)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_open_container(&dict_entry_iter, DBUS_TYPE_VARIANT, "s", &variant_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_STRING, &address)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_close_container(&dict_entry_iter, &variant_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_close_container(&dict_iter, &dict_entry_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_message_iter_close_container(&msg_iter, &dict_iter)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+
+ case FAILED_TO_LOAD_CLIENT_CONF:
+ if (!(reply = dbus_message_new_error(msg, "org.pulseaudio.ClientConfLoadError", "Failed to load client.conf."))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+
+ case SERVER_FROM_TYPE_FAILED:
+ if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, "PulseAudio internal error: get_dbus_server_from_type() failed."))) {
+ r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto finish;
+ }
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ r = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto finish;
+ }
+ r = DBUS_HANDLER_RESULT_HANDLED;
+ goto finish;
+
+ default:
+ pa_assert_not_reached();
+ }
+
+finish:
+ pa_xfree(address);
+ if (reply)
+ dbus_message_unref(reply);
+
+ return r;
+}
+
+static DBusHandlerResult message_cb(DBusConnection *conn, DBusMessage *msg, void *user_data) {
+ pa_dbusobj_server_lookup *sl = user_data;
+
+ pa_assert(conn);
+ pa_assert(msg);
+ pa_assert(sl);
+
+ /* pa_log("Got message! type = %s path = %s iface = %s member = %s dest = %s", dbus_message_type_to_string(dbus_message_get_type(msg)), dbus_message_get_path(msg), dbus_message_get_interface(msg), dbus_message_get_member(msg), dbus_message_get_destination(msg)); */
+
+ if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_METHOD_CALL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect") ||
+ (!dbus_message_get_interface(msg) && dbus_message_has_member(msg, "Introspect")))
+ return handle_introspect(conn, msg, sl);
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_PROPERTIES, "Get") ||
+ (!dbus_message_get_interface(msg) && dbus_message_has_member(msg, "Get")))
+ return handle_get(conn, msg, sl);
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_PROPERTIES, "Set") ||
+ (!dbus_message_get_interface(msg) && dbus_message_has_member(msg, "Set")))
+ return handle_set(conn, msg, sl);
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_PROPERTIES, "GetAll") ||
+ (!dbus_message_get_interface(msg) && dbus_message_has_member(msg, "GetAll")))
+ return handle_get_all(conn, msg, sl);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusObjectPathVTable vtable = {
+ .unregister_function = unregister_cb,
+ .message_function = message_cb,
+ .dbus_internal_pad1 = NULL,
+ .dbus_internal_pad2 = NULL,
+ .dbus_internal_pad3 = NULL,
+ .dbus_internal_pad4 = NULL
+};
+
+pa_dbusobj_server_lookup *pa_dbusobj_server_lookup_new(pa_core *c) {
+ pa_dbusobj_server_lookup *sl;
+ DBusError error;
+
+ dbus_error_init(&error);
+
+ sl = pa_xnew(pa_dbusobj_server_lookup, 1);
+ sl->core = c;
+ sl->path_registered = FALSE;
+
+ if (!(sl->conn = pa_dbus_bus_get(c, DBUS_BUS_SESSION, &error)) || dbus_error_is_set(&error)) {
+ pa_log("Unable to contact D-Bus: %s: %s", error.name, error.message);
+ goto fail;
+ }
+
+ if (!dbus_connection_register_object_path(pa_dbus_connection_get(sl->conn), OBJECT_PATH, &vtable, sl)) {
+ pa_log("dbus_connection_register_object_path() failed for " OBJECT_PATH ".");
+ goto fail;
+ }
+
+ sl->path_registered = TRUE;
+
+ return sl;
+
+fail:
+ dbus_error_free(&error);
+
+ pa_dbusobj_server_lookup_free(sl);
+
+ return NULL;
+}
+
+void pa_dbusobj_server_lookup_free(pa_dbusobj_server_lookup *sl) {
+ pa_assert(sl);
+
+ if (sl->path_registered) {
+ pa_assert(sl->conn);
+ if (!dbus_connection_unregister_object_path(pa_dbus_connection_get(sl->conn), OBJECT_PATH))
+ pa_log_debug("dbus_connection_unregister_object_path() failed for " OBJECT_PATH ".");
+ }
+
+ if (sl->conn)
+ pa_dbus_connection_unref(sl->conn);
+
+ pa_xfree(sl);
+}
diff --git a/src/daemon/server-lookup.h b/src/daemon/server-lookup.h
new file mode 100644
index 00000000..c930d5b7
--- /dev/null
+++ b/src/daemon/server-lookup.h
@@ -0,0 +1,40 @@
+#ifndef fooserverlookuphfoo
+#define fooserverlookuphfoo
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2009 Tanu Kaskinen
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/* This object implements the D-Bus object at path
+ * /org/pulseaudio/server_lookup. Implemented interfaces
+ * are org.pulseaudio.ServerLookup and org.freedesktop.DBus.Introspectable.
+ *
+ * See http://pulseaudio.org/wiki/DBusInterface for the ServerLookup interface
+ * documentation.
+ */
+
+#include <pulsecore/core.h>
+
+typedef struct pa_dbusobj_server_lookup pa_dbusobj_server_lookup;
+
+pa_dbusobj_server_lookup *pa_dbusobj_server_lookup_new(pa_core *c);
+void pa_dbusobj_server_lookup_free(pa_dbusobj_server_lookup *sl);
+
+#endif
diff --git a/src/daemon/start-pulseaudio-kde.in b/src/daemon/start-pulseaudio-kde.in
new file mode 100755
index 00000000..c319e7dd
--- /dev/null
+++ b/src/daemon/start-pulseaudio-kde.in
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# This file is part of PulseAudio.
+#
+# PulseAudio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# PulseAudio is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with PulseAudio; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+set -e
+
+[ -z "$PULSE_SERVER" ]
+
+@PA_BINARY@ --start "$@"
+
+if [ x"$DISPLAY" != x ] ; then
+
+ @PACTL_BINARY@ load-module module-device-manager "do_routing=1" > /dev/null
+
+fi
diff --git a/src/daemon/start-pulseaudio-x11.in b/src/daemon/start-pulseaudio-x11.in
new file mode 100755
index 00000000..391a6d3c
--- /dev/null
+++ b/src/daemon/start-pulseaudio-x11.in
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# This file is part of PulseAudio.
+#
+# PulseAudio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# PulseAudio is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with PulseAudio; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+set -e
+
+@PA_BINARY@ --start "$@"
+
+if [ x"$DISPLAY" != x ] ; then
+
+ @PACTL_BINARY@ load-module module-x11-publish "display=$DISPLAY" > /dev/null
+ @PACTL_BINARY@ load-module module-x11-cork-request "display=$DISPLAY" > /dev/null
+
+ if [ x"$SESSION_MANAGER" != x ] ; then
+ @PACTL_BINARY@ load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null
+ fi
+fi
diff --git a/src/daemon/system.pa.in b/src/daemon/system.pa.in
new file mode 100755
index 00000000..aaefd1d1
--- /dev/null
+++ b/src/daemon/system.pa.in
@@ -0,0 +1,59 @@
+#!@PA_BINARY@ -nF
+#
+# This file is part of PulseAudio.
+#
+# PulseAudio is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# PulseAudio is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with PulseAudio; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+# This startup script is used only if PulseAudio is started in system
+# mode.
+
+### Automatically load driver modules depending on the hardware available
+.ifexists module-udev-detect@PA_SOEXT@
+load-module module-udev-detect
+.else
+### Alternatively use the static hardware detection module (for systems that
+### lack udev support)
+load-module module-detect
+.endif
+
+### Load several protocols
+.ifexists module-esound-protocol-unix@PA_SOEXT@
+load-module module-esound-protocol-unix
+.endif
+.ifexists module-dbus-protocol@PA_SOEXT@
+### If you want to allow TCP connections, set access to "remote" or "local,remote".
+load-module module-dbus-protocol access=local
+.endif
+load-module module-native-protocol-unix
+
+### Automatically restore the volume of streams and devices
+load-module module-stream-restore
+load-module module-device-restore
+
+### Automatically restore the default sink/source when changed by the user during runtime
+load-module module-default-device-restore
+
+### Automatically move streams to the default sink if the sink they are
+### connected to dies, similar for sources
+load-module module-rescue-streams
+
+### Make sure we always have a sink around, even if it is a null sink.
+load-module module-always-sink
+
+### Automatically suspend sinks/sources that become idle for too long
+load-module module-suspend-on-idle
+
+### Enable positioned event sounds
+load-module module-position-event-sounds