From e205b25d65ccb380fa158711e24d55b6de5d9bc1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 16 Feb 2006 19:19:58 +0000 Subject: Reorganised the source tree. We now have src/ with a couple of subdirs: * daemon/ - Contains the files specific to the polypaudio daemon. * modules/ - All loadable modules. * polyp/ - Files that are part of the public, application interface or are only used in libpolyp. * polypcore/ - All other shared files. * tests/ - Test programs. * utils/ - Utility programs. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@487 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 131 +++++++++++++ src/daemon/caps.h | 29 +++ src/daemon/cmdline.c | 300 ++++++++++++++++++++++++++++++ src/daemon/cmdline.h | 35 ++++ src/daemon/cpulimit.c | 236 ++++++++++++++++++++++++ src/daemon/cpulimit.h | 34 ++++ src/daemon/daemon-conf.c | 297 +++++++++++++++++++++++++++++ src/daemon/daemon-conf.h | 80 ++++++++ src/daemon/dumpmodules.c | 99 ++++++++++ src/daemon/dumpmodules.h | 31 ++++ src/daemon/main.c | 472 +++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1744 insertions(+) create mode 100644 src/daemon/caps.c create mode 100644 src/daemon/caps.h create mode 100644 src/daemon/cmdline.c create mode 100644 src/daemon/cmdline.h create mode 100644 src/daemon/cpulimit.c create mode 100644 src/daemon/cpulimit.h create mode 100644 src/daemon/daemon-conf.c create mode 100644 src/daemon/daemon-conf.h create mode 100644 src/daemon/dumpmodules.c create mode 100644 src/daemon/dumpmodules.h create mode 100644 src/daemon/main.c (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c new file mode 100644 index 00000000..8d429459 --- /dev/null +++ b/src/daemon/caps.c @@ -0,0 +1,131 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#ifdef HAVE_SYS_CAPABILITY_H +#include +#endif + +#include +#include "caps.h" + +#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.\n"); + +#if defined(HAVE_SETRESUID) + setresuid(uid, uid, uid); +#elif defined(HAVE_SETREUID) + setreuid(uid, uid); +#else + setuid(uid); + seteuid(uid); +#endif +} + +#else + +void pa_drop_root(void) { +} + +#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; + + 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.\n"); + + 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; + + caps = cap_init(); + assert(caps); + + cap_clear(caps); + + if (cap_set_proc(caps) < 0) { + pa_log(__FILE__": failed to drop capabilities: %s\n", strerror(errno)); + goto fail; + } + + 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 new file mode 100644 index 00000000..3bb861d1 --- /dev/null +++ b/src/daemon/caps.h @@ -0,0 +1,29 @@ +#ifndef foocapshfoo +#define foocapshfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +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 new file mode 100644 index 00000000..0b5f9ec7 --- /dev/null +++ b/src/daemon/cmdline.c @@ -0,0 +1,300 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include "cmdline.h" +#include +#include +#include + +/* Argument codes for getopt_long() */ +enum { + ARG_HELP = 256, + ARG_VERSION, + ARG_DUMP_CONF, + ARG_DUMP_MODULES, + ARG_DAEMONIZE, + ARG_FAIL, + ARG_LOG_LEVEL, + ARG_HIGH_PRIORITY, + ARG_DISALLOW_MODULE_LOADING, + ARG_EXIT_IDLE_TIME, + ARG_MODULE_IDLE_TIME, + ARG_SCACHE_IDLE_TIME, + ARG_LOG_TARGET, + ARG_LOAD, + ARG_FILE, + ARG_DL_SEARCH_PATH, + ARG_RESAMPLE_METHOD, + ARG_KILL, + ARG_USE_PID_FILE, + ARG_CHECK +}; + +/* Tabel for getopt_long() */ +static struct option long_options[] = { + {"help", 0, 0, ARG_HELP}, + {"version", 0, 0, ARG_VERSION}, + {"dump-conf", 0, 0, ARG_DUMP_CONF}, + {"dump-modules", 0, 0, ARG_DUMP_MODULES}, + {"daemonize", 2, 0, ARG_DAEMONIZE}, + {"fail", 2, 0, ARG_FAIL}, + {"verbose", 2, 0, ARG_LOG_LEVEL}, + {"log-level", 2, 0, ARG_LOG_LEVEL}, + {"high-priority", 2, 0, ARG_HIGH_PRIORITY}, + {"disallow-module-loading", 2, 0, ARG_DISALLOW_MODULE_LOADING}, + {"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}, + {"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}, + {"use-pid-file", 2, 0, ARG_USE_PID_FILE}, + {"check", 0, 0, ARG_CHECK}, + {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" + "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" + " -k --kill Kill a running daemon\n" + " --check Check for a running daemon\n\n" + + "OPTIONS:\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" + " --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" + " this time passed\n" + " --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" + " -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" + + "STARTUP SCRIPT:\n" + " -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with\n" + " the specified argument\n" + " -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); +} + +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); + + 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: + case 'h': + conf->cmd = PA_CMD_HELP; + break; + + case ARG_VERSION: + conf->cmd = PA_CMD_VERSION; + break; + + case ARG_DUMP_CONF: + conf->cmd = PA_CMD_DUMP_CONF; + break; + + case ARG_DUMP_MODULES: + conf->cmd = PA_CMD_DUMP_MODULES; + break; + + case 'k': + case ARG_KILL: + conf->cmd = PA_CMD_KILL; + 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); + break; + + case 'C': + pa_strbuf_puts(buf, "load-module module-cli\n"); + break; + + case ARG_DAEMONIZE: + case 'D': + if ((conf->daemonize = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + pa_log(__FILE__": --daemonize expects boolean argument\n"); + goto fail; + } + break; + + case ARG_FAIL: + if ((conf->fail = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + pa_log(__FILE__": --fail expects boolean argument\n"); + goto fail; + } + break; + + case 'v': + case ARG_LOG_LEVEL: + + 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).\n"); + 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\n"); + 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\n"); + 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\n"); + 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; + 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'.\n"); + goto fail; + } + break; + + case ARG_EXIT_IDLE_TIME: + conf->exit_idle_time = atoi(optarg); + break; + + case ARG_MODULE_IDLE_TIME: + conf->module_idle_time = atoi(optarg); + break; + + case ARG_SCACHE_IDLE_TIME: + conf->scache_idle_time = atoi(optarg); + break; + + case ARG_RESAMPLE_METHOD: + if (pa_daemon_conf_set_resample_method(conf, optarg) < 0) { + pa_log(__FILE__": Invalid resample method '%s'.\n", optarg); + goto fail; + } + break; + + default: + goto fail; + } + } + + 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 new file mode 100644 index 00000000..e2eaf0d2 --- /dev/null +++ b/src/daemon/cmdline.h @@ -0,0 +1,35 @@ +#ifndef foocmdlinehfoo +#define foocmdlinehfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include "daemon-conf.h" + +/* Parese the command line and store its data in *c. Return the index + * of the first unparsed argument in *d. */ +int pa_cmdline_parse(pa_daemon_conf*c, int argc, char *const argv [], int *d); + +/* Show the command line help. The command name is extracted from + * argv[0] which should be passed in argv0. */ +void pa_cmdline_help(const char *argv0); + +#endif diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c new file mode 100644 index 00000000..6887796f --- /dev/null +++ b/src/daemon/cpulimit.c @@ -0,0 +1,236 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "cpulimit.h" +#include +#include + +#ifdef HAVE_SIGXCPU + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +/* This module implements a watchdog that makes sure that the current + * process doesn't consume more than 70% CPU time for 10 seconds. This + * is very useful when using SCHED_FIFO scheduling which effectively + * disables multitasking. */ + +/* Method of operation: Using SIGXCPU a signal handler is called every + * 10s process CPU time. That function checks if less than 14s system + * time have passed. In that case, it tries to contact the main event + * loop through a pipe. After two additional seconds it is checked + * whether the main event loop contact was successful. If not, the + * program is terminated forcibly. */ + +/* Utilize this much CPU time at maximum */ +#define CPUTIME_PERCENT 70 + +/* Check every 10s */ +#define CPUTIME_INTERVAL_SOFT (10) + +/* Recheck after 2s */ +#define CPUTIME_INTERVAL_HARD (2) + +/* Time of the last CPU load check */ +static time_t last_time = 0; + +/* Pipe for communicating with the main loop */ +static int the_pipe[2] = {-1, -1}; + +/* Main event loop and IO event for the FIFO */ +static pa_mainloop_api *api = NULL; +static pa_io_event *io_event = NULL; + +/* Saved sigaction struct for SIGXCPU */ +static struct sigaction sigaction_prev; + +/* Nonzero after pa_cpu_limit_init() */ +static int installed = 0; + +/* The current state of operation */ +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); + + n = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec + t; + + r = getrlimit(RLIMIT_CPU, &rl); + assert(r >= 0); + + rl.rlim_cur = n; + r = setrlimit(RLIMIT_CPU, &rl); + assert(r >= 0); +} + +/* A simple, thread-safe puts() work-alike */ +static void write_err(const char *p) { + pa_loop_write(2, p, strlen(p)); +} + +/* The signal handler, called on every SIGXCPU */ +static void signal_handler(int sig) { + assert(sig == SIGXCPU); + + if (phase == PHASE_IDLE) { + time_t now; + +#ifdef PRINT_CPU_LOAD + char t[256]; +#endif + + time(&now); + +#ifdef PRINT_CPU_LOAD + snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", (double)CPUTIME_INTERVAL_SOFT/(now-last_time)*100); + write_err(t); +#endif + + if (CPUTIME_INTERVAL_SOFT >= ((now-last_time)*(double)CPUTIME_PERCENT/100)) { + 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)); + 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 */ + } +} + +/* Callback for IO events on the FIFO */ +static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags f, void *userdata) { + char c; + assert(m && e && f == PA_IO_EVENT_INPUT && e == io_event && fd == the_pipe[0]); + read(the_pipe[0], &c, sizeof(c)); + m->quit(m, 1); /* Quit the main loop */ +} + +/* 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); + + /* Prepare the main loop pipe */ + if (pipe(the_pipe) < 0) { + pa_log(__FILE__": pipe() failed: %s\n", strerror(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); + + api = m; + io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL); + + phase = PHASE_IDLE; + + /* Install signal handler for SIGXCPU */ + memset(&sa, 0, sizeof(sa)); + 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; + + 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); + 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; + + if (installed) { + r = sigaction(SIGXCPU, &sigaction_prev, NULL); + assert(r >= 0); + installed = 0; + } +} + +#else /* HAVE_SIGXCPU */ + +int pa_cpu_limit_init(PA_GCC_UNUSED pa_mainloop_api *m) { + return 0; +} + +void pa_cpu_limit_done(void) { +} + +#endif diff --git a/src/daemon/cpulimit.h b/src/daemon/cpulimit.h new file mode 100644 index 00000000..f3c5534d --- /dev/null +++ b/src/daemon/cpulimit.h @@ -0,0 +1,34 @@ +#ifndef foocpulimithfoo +#define foocpulimithfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include + +/* This kills the polypaudio process if it eats more than 70% of the + * CPU time. This is build around setrlimit() and SIGXCPU. It is handy + * in case of using SCHED_FIFO which may freeze the whole machine */ + +int pa_cpu_limit_init(pa_mainloop_api *m); +void pa_cpu_limit_done(void); + +#endif diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c new file mode 100644 index 00000000..8fe3c4cc --- /dev/null +++ b/src/daemon/daemon-conf.c @@ -0,0 +1,297 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "daemon-conf.h" +#include +#include +#include +#include +#include + +#ifndef DEFAULT_CONFIG_DIR +# ifndef OS_IS_WIN32 +# define DEFAULT_CONFIG_DIR "/etc/polypaudio" +# else +# define DEFAULT_CONFIG_DIR "%POLYP_ROOT%" +# endif +#endif + +#ifndef OS_IS_WIN32 +# define PATH_SEP "/" +#else +# define PATH_SEP "\\" +#endif + +#define DEFAULT_SCRIPT_FILE DEFAULT_CONFIG_DIR PATH_SEP "default.pa" +#define DEFAULT_SCRIPT_FILE_USER ".polypaudio" PATH_SEP "default.pa" +#define DEFAULT_CONFIG_FILE DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf" +#define DEFAULT_CONFIG_FILE_USER ".polypaudio" PATH_SEP "daemon.conf" + +#define ENV_SCRIPT_FILE "POLYP_SCRIPT" +#define ENV_CONFIG_FILE "POLYP_CONFIG" +#define ENV_DL_SEARCH_PATH "POLYP_DLPATH" + +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, + .scache_idle_time = 20, + .auto_log_target = 1, + .script_commands = NULL, + .dl_search_path = NULL, + .default_script_file = NULL, + .log_target = PA_LOG_SYSLOG, + .log_level = PA_LOG_NOTICE, + .resample_method = PA_RESAMPLER_SRC_SINC_FASTEST, + .config_file = NULL, + .use_pid_file = 1 +}; + +pa_daemon_conf* pa_daemon_conf_new(void) { + FILE *f; + pa_daemon_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); + + if ((f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file))) + fclose(f); + +#ifdef DLSEARCHPATH + c->dl_search_path = pa_xstrdup(DLSEARCHPATH); +#endif + return c; +} + +void pa_daemon_conf_free(pa_daemon_conf *c) { + assert(c); + pa_xfree(c->script_commands); + pa_xfree(c->dl_search_path); + pa_xfree(c->default_script_file); + pa_xfree(c->config_file); + pa_xfree(c); +} + +int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) { + assert(c && string); + + if (!strcmp(string, "auto")) + c->auto_log_target = 1; + else if (!strcmp(string, "syslog")) { + c->auto_log_target = 0; + c->log_target = PA_LOG_SYSLOG; + } else if (!strcmp(string, "stderr")) { + c->auto_log_target = 0; + c->log_target = PA_LOG_STDERR; + } else + return -1; + + return 0; +} + +int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) { + uint32_t u; + assert(c && string); + + if (pa_atou(string, &u) >= 0) { + if (u >= PA_LOG_LEVEL_MAX) + return -1; + + c->log_level = (pa_log_level_t) u; + } else if (pa_startswith(string, "debug")) + c->log_level = PA_LOG_DEBUG; + else if (pa_startswith(string, "info")) + c->log_level = PA_LOG_INFO; + else if (pa_startswith(string, "notice")) + c->log_level = PA_LOG_NOTICE; + else if (pa_startswith(string, "warn")) + c->log_level = PA_LOG_WARN; + else if (pa_startswith(string, "err")) + c->log_level = PA_LOG_ERROR; + else + return -1; + + return 0; +} + +int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string) { + int m; + assert(c && string); + + if ((m = pa_parse_resample_method(string)) < 0) + return -1; + + c->resample_method = m; + 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) { + pa_daemon_conf *c = data; + assert(filename && lvalue && rvalue && data); + + if (pa_daemon_conf_set_log_target(c, rvalue) < 0) { + pa_log(__FILE__": [%s:%u] Invalid log target '%s'.\n", 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) { + pa_daemon_conf *c = data; + assert(filename && lvalue && rvalue && data); + + if (pa_daemon_conf_set_log_level(c, rvalue) < 0) { + pa_log(__FILE__": [%s:%u] Invalid log level '%s'.\n", 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) { + pa_daemon_conf *c = data; + assert(filename && lvalue && rvalue && data); + + if (pa_daemon_conf_set_resample_method(c, rvalue) < 0) { + pa_log(__FILE__": [%s:%u] Inavalid resample method '%s'.\n", filename, line, rvalue); + return -1; + } + + return 0; +} + +int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { + int r = -1; + FILE *f = NULL; + + 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 }, + { 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; + + 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); + + if (!f && errno != ENOENT) { + pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s\n", filename, strerror(errno)); + goto finish; + } + + r = f ? pa_config_parse(c->config_file, f, table, NULL) : 0; + +finish: + if (f) + fclose(f); + + return r; +} + +int pa_daemon_conf_env(pa_daemon_conf *c) { + char *e; + + if ((e = getenv(ENV_DL_SEARCH_PATH))) { + pa_xfree(c->dl_search_path); + c->dl_search_path = pa_xstrdup(e); + } + if ((e = getenv(ENV_SCRIPT_FILE))) { + pa_xfree(c->default_script_file); + c->default_script_file = pa_xstrdup(e); + } + + 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" +}; + +char *pa_daemon_conf_dump(pa_daemon_conf *c) { + pa_strbuf *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, "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, "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); + + return pa_strbuf_tostring_free(s); +} diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h new file mode 100644 index 00000000..d5131419 --- /dev/null +++ b/src/daemon/daemon-conf.h @@ -0,0 +1,80 @@ +#ifndef foodaemonconfhfoo +#define foodaemonconfhfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include + +/* The actual command to execute */ +typedef enum pa_daemon_conf_cmd { + PA_CMD_DAEMON, /* the default */ + PA_CMD_HELP, + PA_CMD_VERSION, + PA_CMD_DUMP_CONF, + PA_CMD_DUMP_MODULES, + PA_CMD_KILL, + PA_CMD_CHECK +} pa_daemon_conf_cmd_t; + +/* A structure containing configuration data for the Polypaudio server . */ +typedef struct pa_daemon_conf { + pa_daemon_conf_cmd_t cmd; + int daemonize, + fail, + high_priority, + disallow_module_loading, + exit_idle_time, + module_idle_time, + scache_idle_time, + auto_log_target, + use_pid_file; + char *script_commands, *dl_search_path, *default_script_file; + pa_log_target_t log_target; + pa_log_level_t log_level; + int resample_method; + char *config_file; +} pa_daemon_conf; + +/* Allocate a new structure and fill it with sane defaults */ +pa_daemon_conf* pa_daemon_conf_new(void); +void pa_daemon_conf_free(pa_daemon_conf*c); + +/* Load configuration data from the specified file overwriting the + * current settings in *c. If filename is NULL load the default daemon + * configuration file */ +int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename); + +/* Pretty print the current configuration data of the daemon. The + * returned string has to be freed manually. The output of this + * function may be parsed with pa_daemon_conf_load(). */ +char *pa_daemon_conf_dump(pa_daemon_conf *c); + +/* Load the configuration data from the process' environment + * overwriting the current settings in *c. */ +int pa_daemon_conf_env(pa_daemon_conf *c); + +/* Set these configuration variables in the structure by passing a string */ +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); + +#endif diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c new file mode 100644 index 00000000..8d8eb0b9 --- /dev/null +++ b/src/daemon/dumpmodules.c @@ -0,0 +1,99 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "dumpmodules.h" +#include +#include + +#define PREFIX "module-" + +static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) { + assert(name && 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); + + if (nl) + printf("\n"); + + nl = 1; + + printf("Name: %s\n", name); + + if (!i->description && !i->version && !i->author && !i->usage) + printf("No module information available\n"); + else { + if (i->version) + printf("Version: %s\n", i->version); + if (i->description) + printf("Description: %s\n", i->description); + if (i->author) + printf("Author: %s\n", i->author); + if (i->usage) + printf("Usage: %s\n", i->usage); + } + + if (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; + + if ((i = pa_modinfo_get_by_name(path ? path : name))) { + info(name, path, i); + pa_modinfo_free(i); + } +} + +static int callback(const char *path, lt_ptr data) { + const char *e; + pa_daemon_conf *c = (data); + + e = pa_path_get_filename(path); + + if (strlen(e) > sizeof(PREFIX)-1 && !strncmp(e, PREFIX, sizeof(PREFIX)-1)) + 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[]) { + if (argc > 0) { + int i; + for (i = 0; i < argc; i++) + show_info(argv[i], NULL, long_info); + } else + lt_dlforeachfile(NULL, callback, c); +} diff --git a/src/daemon/dumpmodules.h b/src/daemon/dumpmodules.h new file mode 100644 index 00000000..968d2de9 --- /dev/null +++ b/src/daemon/dumpmodules.h @@ -0,0 +1,31 @@ +#ifndef foodumpmoduleshfoo +#define foodumpmoduleshfoo + +/* $Id*/ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include "daemon-conf.h" + +/* Dump all available modules to STDOUT. If argc > 0 print information + * about the modules specified in argv[] instead. */ +void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]); + +#endif diff --git a/src/daemon/main.c b/src/daemon/main.c new file mode 100644 index 00000000..6be83d8c --- /dev/null +++ b/src/daemon/main.c @@ -0,0 +1,472 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_SYS_IOCTL_H +#include +#endif + +#ifdef HAVE_LIBWRAP +#include +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include "cmdline.h" +#include +#include +#include +#include +#include "cpulimit.h" +#include +#include "daemon-conf.h" +#include "dumpmodules.h" +#include "caps.h" +#include +#include +#include + +#ifdef HAVE_LIBWRAP +/* Only one instance of these variables */ +int allow_severity = LOG_INFO; +int deny_severity = LOG_WARNING; +#endif + +#ifdef OS_IS_WIN32 + +static void message_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { + MSG msg; + + while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) + raise(SIGTERM); + else { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +} + +#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.\n", pa_strsignal(sig)); + + switch (sig) { +#ifdef SIGUSR1 + case SIGUSR1: + pa_module_load(userdata, "module-cli", NULL); + break; +#endif + +#ifdef SIGUSR2 + case SIGUSR2: + pa_module_load(userdata, "module-cli-protocol-unix", NULL); + break; +#endif + +#ifdef SIGHUP + case SIGHUP: { + char *c = pa_full_status_string(userdata); + pa_log_notice(c); + pa_xfree(c); + return; + } +#endif + + case SIGINT: + case SIGTERM: + default: + pa_log_info(__FILE__": Exiting.\n"); + 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; +} + +int main(int argc, char *argv[]) { + pa_core *c; + pa_strbuf *buf = NULL; + pa_daemon_conf *conf; + pa_mainloop *mainloop; + + char *s; + int r, retval = 1, d = 0; + int daemon_pipe[2] = { -1, -1 }; + int suid_root; + int valid_pid_file = 0; + +#ifdef HAVE_GETUID + gid_t gid = (gid_t) -1; +#endif + +#ifdef OS_IS_WIN32 + pa_defer_event *defer; +#endif + + pa_limit_caps(); + +#ifdef HAVE_GETUID + suid_root = getuid() != 0 && geteuid() == 0; + + if (suid_root && (pa_uid_in_group("realtime", &gid) <= 0 || gid >= 1000)) { + pa_log_warn(__FILE__": WARNING: called SUID root, but not in group 'realtime'.\n"); + pa_drop_root(); + } +#else + 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); + } +#endif + + pa_log_set_ident("polypaudio"); + + conf = pa_daemon_conf_new(); + + if (pa_daemon_conf_load(conf, NULL) < 0) + goto finish; + + if (pa_daemon_conf_env(conf) < 0) + goto finish; + + if (pa_cmdline_parse(conf, argc, argv, &d) < 0) { + pa_log(__FILE__": failed to parse command line.\n"); + 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); + + if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) + pa_raise_priority(); + + pa_drop_caps(); + + if (suid_root) + pa_drop_root(); + + if (conf->dl_search_path) + lt_dlsetsearchpath(conf->dl_search_path); + + switch (conf->cmd) { + case PA_CMD_DUMP_MODULES: + pa_dump_modules(conf, argc-d, argv+d); + retval = 0; + goto finish; + + case PA_CMD_DUMP_CONF: { + s = pa_daemon_conf_dump(conf); + fputs(s, stdout); + pa_xfree(s); + retval = 0; + goto finish; + } + + case PA_CMD_HELP : + pa_cmdline_help(argv[0]); + retval = 0; + goto finish; + + case PA_CMD_VERSION : + printf(PACKAGE_NAME" "PACKAGE_VERSION"\n"); + retval = 0; + goto finish; + + case PA_CMD_CHECK: { + pid_t pid; + + if (pa_pid_file_check_running(&pid) < 0) { + pa_log_info(__FILE__": daemon not running\n"); + } else { + pa_log_info(__FILE__": daemon running as PID %u\n", pid); + retval = 0; + } + + goto finish; + + } + case PA_CMD_KILL: + + if (pa_pid_file_kill(SIGINT, NULL) < 0) + pa_log(__FILE__": failed to kill daemon.\n"); + else + retval = 0; + + goto finish; + + default: + assert(conf->cmd == PA_CMD_DAEMON); + } + + if (conf->daemonize) { + pid_t child; + int tty_fd; + + if (pa_stdio_acquire() < 0) { + pa_log(__FILE__": failed to acquire stdio.\n"); + goto finish; + } + +#ifdef HAVE_FORK + if (pipe(daemon_pipe) < 0) { + pa_log(__FILE__": failed to create pipe.\n"); + goto finish; + } + + if ((child = fork()) < 0) { + pa_log(__FILE__": fork() failed: %s\n", strerror(errno)); + goto finish; + } + + if (child != 0) { + /* Father */ + + close(daemon_pipe[1]); + daemon_pipe[1] = -1; + + if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval)) != sizeof(retval)) { + pa_log(__FILE__": read() failed: %s\n", strerror(errno)); + retval = 1; + } + + if (retval) + pa_log(__FILE__": daemon startup failed.\n"); + else + pa_log_info(__FILE__": daemon startup successful.\n"); + + goto finish; + } + + close(daemon_pipe[0]); + daemon_pipe[0] = -1; +#endif + + if (conf->auto_log_target) + pa_log_set_target(PA_LOG_SYSLOG, NULL); + +#ifdef HAVE_SETSID + setsid(); +#endif +#ifdef HAVE_SETPGID + setpgid(0,0); +#endif + +#ifndef OS_IS_WIN32 + close(0); + close(1); + close(2); + + open("/dev/null", O_RDONLY); + open("/dev/null", O_WRONLY); + open("/dev/null", O_WRONLY); +#else + FreeConsole(); +#endif + +#ifdef SIGTTOU + signal(SIGTTOU, SIG_IGN); +#endif +#ifdef SIGTTIN + signal(SIGTTIN, SIG_IGN); +#endif +#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 + } + + chdir("/"); + + if (conf->use_pid_file) { + if (pa_pid_file_create() < 0) { + pa_log(__FILE__": pa_pid_file_create() failed.\n"); +#ifdef HAVE_FORK + if (conf->daemonize) + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); +#endif + goto finish; + } + + valid_pid_file = 1; + } + + mainloop = pa_mainloop_new(); + assert(mainloop); + + c = pa_core_new(pa_mainloop_get_api(mainloop)); + assert(c); + + r = pa_signal_init(pa_mainloop_get_api(mainloop)); + assert(r == 0); + pa_signal_new(SIGINT, signal_callback, c); + pa_signal_new(SIGTERM, signal_callback, c); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif + +#ifdef OS_IS_WIN32 + defer = pa_mainloop_get_api(mainloop)->defer_new(pa_mainloop_get_api(mainloop), message_cb, NULL); + assert(defer); +#endif + + if (conf->daemonize) + c->running_as_daemon = 1; + +#ifdef SIGUSR1 + pa_signal_new(SIGUSR1, signal_callback, c); +#endif +#ifdef SIGUSR2 + pa_signal_new(SIGUSR2, signal_callback, c); +#endif +#ifdef SIGHUP + pa_signal_new(SIGHUP, signal_callback, c); +#endif + + oil_init(); + + r = pa_cpu_limit_init(pa_mainloop_get_api(mainloop)); + assert(r == 0); + + buf = pa_strbuf_new(); + assert(buf); + 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(s = pa_strbuf_tostring_free(buf)); + pa_xfree(s); + + if (r < 0 && conf->fail) { + pa_log(__FILE__": failed to initialize daemon.\n"); +#ifdef HAVE_FORK + if (conf->daemonize) + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); +#endif + } else if (!c->modules || pa_idxset_size(c->modules) == 0) { + pa_log(__FILE__": daemon startup without any loaded modules, refusing to work.\n"); +#ifdef HAVE_FORK + if (conf->daemonize) + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); +#endif + } else { + + retval = 0; +#ifdef HAVE_FORK + if (conf->daemonize) + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); +#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; + + 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.\n", __FILE__, c->default_sink_name); + retval = 1; + } else { + pa_log_info(__FILE__": Daemon startup complete.\n"); + if (pa_mainloop_run(mainloop, &retval) < 0) + retval = 1; + pa_log_info(__FILE__": Daemon shutdown initiated.\n"); + } + } + +#ifdef OS_IS_WIN32 + pa_mainloop_get_api(mainloop)->defer_free(defer); +#endif + + pa_core_free(c); + + pa_cpu_limit_done(); + pa_signal_done(); + pa_mainloop_free(mainloop); + + pa_log_info(__FILE__": Daemon terminated.\n"); + +finish: + + if (conf) + pa_daemon_conf_free(conf); + + if (valid_pid_file) + pa_pid_file_remove(); + + close_pipe(daemon_pipe); + +#ifdef OS_IS_WIN32 + WSACleanup(); +#endif + + lt_dlexit(); + + return retval; +} -- cgit From b56b9e50e027c22fc56c805d8d0cd10d99a4cd5b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2006 21:37:20 +0000 Subject: * svn:ignore some files * move configuration files to the directories they belong to * built esd-compat.sh in the src/ dir git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@488 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon.conf.in | 77 +++++++++++++++++++++++++++++++++++ src/daemon/default.pa.in | 66 ++++++++++++++++++++++++++++++ src/daemon/default.pa.win32 | 43 ++++++++++++++++++++ src/daemon/esdcompat.sh.in | 98 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 284 insertions(+) create mode 100644 src/daemon/daemon.conf.in create mode 100755 src/daemon/default.pa.in create mode 100644 src/daemon/default.pa.win32 create mode 100755 src/daemon/esdcompat.sh.in (limited to 'src/daemon') diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in new file mode 100644 index 00000000..d5373018 --- /dev/null +++ b/src/daemon/daemon.conf.in @@ -0,0 +1,77 @@ +# $Id$ +# +# This file is part of polypaudio. +# +# polypaudio 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. +# +# polypaudio 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 polypaudio; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +## Configuration file for the polypaudio 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 + +## 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 = @DLSEARCHPATH@ + +## The default script file to load. Specify an empty string for not +## loading a default script file. The +; default-script-file = @DEFAULT_CONFIG_FILE@ + +## 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 + +## 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/polypaudio-$USER/pid. Of this is enabled +## you may use commands like "polypaudio --kill" or "polypaudio +## --check". If you are planning to start more than one polypaudio +## process per user, you better disable this option since it +## effectively disables multiple instances. +; use-pid-file = 1 diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in new file mode 100755 index 00000000..3aaeeaf0 --- /dev/null +++ b/src/daemon/default.pa.in @@ -0,0 +1,66 @@ +#!@POLYPAUDIO_BINARY@ -nF + +# +# This file is part of polypaudio. +# +# polypaudio 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. +# +# polypaudio 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 polypaudio; 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-alsa-sink +# load-module module-alsa-source device=plughw:1,0 +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 +load-module module-null-sink +#load-module module-pipe-sink + +# 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 + +# Load several protocols +load-module module-esound-protocol-unix +#load-module module-esound-protocol-tcp +load-module module-native-protocol-unix +#load-module module-simple-protocol-tcp +#load-module module-cli-protocol-unix + +# Load the CLI module +load-module module-cli + +# Make some devices default +set-default-sink output +set-default-source input + +.nofail + +# Load something to the sample cache +load-sample x11-bell /usr/share/sounds/KDE_Notify.wav +load-sample-dir-lazy /usr/share/sounds/*.wav + +# Load X11 bell module +load-module module-x11-bell sample=x11-bell sink=output + +# Publish connection data in the X11 root window +load-module module-x11-publish + +#load-module module-pipe-source +#load-module module-pipe-sink diff --git a/src/daemon/default.pa.win32 b/src/daemon/default.pa.win32 new file mode 100644 index 00000000..3478adab --- /dev/null +++ b/src/daemon/default.pa.win32 @@ -0,0 +1,43 @@ +# +# This file is part of polypaudio. +# +# polypaudio 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. +# +# polypaudio 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 polypaudio; 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/esdcompat.sh.in b/src/daemon/esdcompat.sh.in new file mode 100755 index 00000000..76023f52 --- /dev/null +++ b/src/daemon/esdcompat.sh.in @@ -0,0 +1,98 @@ +#!/bin/sh + +# $Id$ +# +# This file is part of polypaudio. +# +# polypaudio 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. +# +# polypaudio 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 polypaudio; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +VERSION_STRING="@PACKAGE_NAME@ esd wrapper @PACKAGE_VERSION@" + +fail() { + echo "ERROR: $1" + exit 1 +} + +ARGS=" --log-target=syslog" + +for N in $(seq $#) ; do + + case "$1" in + "") + ;; + + -v|--version) + echo "$VERSION_STRING" + exit 0 + ;; + + -h|--help) + cat < Date: Thu, 16 Feb 2006 22:11:35 +0000 Subject: add a bunch of simple Makefile in the subdirs, just to make compilation with emacs easier they are not intended to be distributed or anything. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@490 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/Makefile | 1 + 1 file changed, 1 insertion(+) create mode 120000 src/daemon/Makefile (limited to 'src/daemon') diff --git a/src/daemon/Makefile b/src/daemon/Makefile new file mode 120000 index 00000000..cd2a5c9a --- /dev/null +++ b/src/daemon/Makefile @@ -0,0 +1 @@ +../polyp/Makefile \ No newline at end of file -- cgit From 5eda18bf608a325c136a450e58fa154eb0b270f4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 17 Feb 2006 12:10:58 +0000 Subject: Cleaned up the includes after the restructuring. Indicate which headers are public and which are internal through <> vs "". git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@500 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 1 + src/daemon/cmdline.c | 3 ++- src/daemon/cpulimit.c | 3 ++- src/daemon/daemon-conf.c | 3 ++- src/daemon/dumpmodules.c | 3 ++- src/daemon/main.c | 18 ++++++++++-------- 6 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 8d429459..e12d33fb 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -33,6 +33,7 @@ #endif #include + #include "caps.h" #ifdef HAVE_GETUID diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index 0b5f9ec7..b6ab1283 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -30,11 +30,12 @@ #include #include -#include "cmdline.h" #include #include #include +#include "cmdline.h" + /* Argument codes for getopt_long() */ enum { ARG_HELP = 256, diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 6887796f..d7a24b8e 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -23,10 +23,11 @@ #include #endif -#include "cpulimit.h" #include #include +#include "cpulimit.h" + #ifdef HAVE_SIGXCPU #include diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 8fe3c4cc..ecabce40 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -29,13 +29,14 @@ #include #include -#include "daemon-conf.h" #include #include #include #include #include +#include "daemon-conf.h" + #ifndef DEFAULT_CONFIG_DIR # ifndef OS_IS_WIN32 # define DEFAULT_CONFIG_DIR "/etc/polypaudio" diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index 8d8eb0b9..bf29a681 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -29,10 +29,11 @@ #include #include -#include "dumpmodules.h" #include #include +#include "dumpmodules.h" + #define PREFIX "module-" static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) { diff --git a/src/daemon/main.c b/src/daemon/main.c index 6be83d8c..638c2f3f 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -47,26 +47,28 @@ #include #endif -#include +#include "../polypcore/winsock.h" + +#include +#include #include #include -#include #include -#include -#include "cmdline.h" #include +#include #include #include #include +#include +#include +#include + +#include "cmdline.h" #include "cpulimit.h" -#include #include "daemon-conf.h" #include "dumpmodules.h" #include "caps.h" -#include -#include -#include #ifdef HAVE_LIBWRAP /* Only one instance of these variables */ -- cgit From cae2d8007650ac3bf9501177a389b69be7ae0eab Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Feb 2006 23:58:51 +0000 Subject: disable SIGPIPE before calling pa_core_new(), this way the warning message is not printed git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@542 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 638c2f3f..3124ad1d 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -357,6 +357,10 @@ int main(int argc, char *argv[]) { valid_pid_file = 1; } +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif + mainloop = pa_mainloop_new(); assert(mainloop); @@ -367,17 +371,6 @@ int main(int argc, char *argv[]) { assert(r == 0); pa_signal_new(SIGINT, signal_callback, c); pa_signal_new(SIGTERM, signal_callback, c); -#ifdef SIGPIPE - signal(SIGPIPE, SIG_IGN); -#endif - -#ifdef OS_IS_WIN32 - defer = pa_mainloop_get_api(mainloop)->defer_new(pa_mainloop_get_api(mainloop), message_cb, NULL); - assert(defer); -#endif - - if (conf->daemonize) - c->running_as_daemon = 1; #ifdef SIGUSR1 pa_signal_new(SIGUSR1, signal_callback, c); @@ -388,6 +381,14 @@ int main(int argc, char *argv[]) { #ifdef SIGHUP pa_signal_new(SIGHUP, signal_callback, c); #endif + +#ifdef OS_IS_WIN32 + defer = pa_mainloop_get_api(mainloop)->defer_new(pa_mainloop_get_api(mainloop), message_cb, NULL); + assert(defer); +#endif + + if (conf->daemonize) + c->running_as_daemon = 1; oil_init(); -- cgit From 4a64b0d1167e980d81b798d813f35209895f0674 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Feb 2006 02:27:19 +0000 Subject: change pa_log() and friends to not require a trailing \n on all logged strings git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@574 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 6 +++--- src/daemon/cmdline.c | 16 ++++++++-------- src/daemon/cpulimit.c | 2 +- src/daemon/daemon-conf.c | 8 ++++---- src/daemon/main.c | 45 ++++++++++++++++++++++----------------------- 5 files changed, 38 insertions(+), 39 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index e12d33fb..5c52b77a 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -45,7 +45,7 @@ void pa_drop_root(void) { if (uid == 0 || geteuid() != 0) return; - pa_log_info(__FILE__": dropping root rights.\n"); + pa_log_info(__FILE__": dropping root rights."); #if defined(HAVE_SETRESUID) setresuid(uid, uid, uid); @@ -83,7 +83,7 @@ int pa_limit_caps(void) { if (cap_set_proc(caps) < 0) goto fail; - pa_log_info(__FILE__": dropped capabilities successfully.\n"); + pa_log_info(__FILE__": dropped capabilities successfully."); r = 0; @@ -104,7 +104,7 @@ int pa_drop_caps(void) { cap_clear(caps); if (cap_set_proc(caps) < 0) { - pa_log(__FILE__": failed to drop capabilities: %s\n", strerror(errno)); + pa_log(__FILE__": failed to drop capabilities: %s", strerror(errno)); goto fail; } diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index b6ab1283..a6b95a81 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -191,14 +191,14 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d case ARG_DAEMONIZE: case 'D': if ((conf->daemonize = optarg ? pa_parse_boolean(optarg) : 1) < 0) { - pa_log(__FILE__": --daemonize expects boolean argument\n"); + pa_log(__FILE__": --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\n"); + pa_log(__FILE__": --fail expects boolean argument"); goto fail; } break; @@ -208,7 +208,7 @@ 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).\n"); + pa_log(__FILE__": --log-level expects log level argument (either numeric in range 0..4 or one of debug, info, notice, warn, error)."); goto fail; } } else { @@ -220,21 +220,21 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d case ARG_HIGH_PRIORITY: if ((conf->high_priority = optarg ? pa_parse_boolean(optarg) : 1) < 0) { - pa_log(__FILE__": --high-priority expects boolean argument\n"); + pa_log(__FILE__": --high-priority 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\n"); + pa_log(__FILE__": --disallow-module-loading 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\n"); + pa_log(__FILE__": --use-pid-file expects boolean argument"); goto fail; } break; @@ -252,7 +252,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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'.\n"); + pa_log(__FILE__": Invalid log target: use either 'syslog', 'stderr' or 'auto'."); goto fail; } break; @@ -271,7 +271,7 @@ 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'.\n", optarg); + pa_log(__FILE__": Invalid resample method '%s'.", optarg); goto fail; } break; diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index d7a24b8e..54f111da 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -169,7 +169,7 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { /* Prepare the main loop pipe */ if (pipe(the_pipe) < 0) { - pa_log(__FILE__": pipe() failed: %s\n", strerror(errno)); + pa_log(__FILE__": pipe() failed: %s", strerror(errno)); return -1; } diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index ecabce40..ac5fbb16 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -160,7 +160,7 @@ static int parse_log_target(const char *filename, unsigned line, const char *lva assert(filename && lvalue && rvalue && data); if (pa_daemon_conf_set_log_target(c, rvalue) < 0) { - pa_log(__FILE__": [%s:%u] Invalid log target '%s'.\n", filename, line, rvalue); + pa_log(__FILE__": [%s:%u] Invalid log target '%s'.", filename, line, rvalue); return -1; } @@ -172,7 +172,7 @@ static int parse_log_level(const char *filename, unsigned line, const char *lval assert(filename && lvalue && rvalue && data); if (pa_daemon_conf_set_log_level(c, rvalue) < 0) { - pa_log(__FILE__": [%s:%u] Invalid log level '%s'.\n", filename, line, rvalue); + pa_log(__FILE__": [%s:%u] Invalid log level '%s'.", filename, line, rvalue); return -1; } @@ -184,7 +184,7 @@ static int parse_resample_method(const char *filename, unsigned line, const char assert(filename && lvalue && rvalue && data); if (pa_daemon_conf_set_resample_method(c, rvalue) < 0) { - pa_log(__FILE__": [%s:%u] Inavalid resample method '%s'.\n", filename, line, rvalue); + pa_log(__FILE__": [%s:%u] Inavalid resample method '%s'.", filename, line, rvalue); return -1; } @@ -236,7 +236,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { 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\n", filename, strerror(errno)); + pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", filename, strerror(errno)); goto finish; } diff --git a/src/daemon/main.c b/src/daemon/main.c index 3124ad1d..4b972fe2 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -94,7 +94,7 @@ static void message_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { #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.\n", pa_strsignal(sig)); + pa_log_info(__FILE__": Got signal %s.", pa_strsignal(sig)); switch (sig) { #ifdef SIGUSR1 @@ -112,7 +112,7 @@ static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e, #ifdef SIGHUP case SIGHUP: { char *c = pa_full_status_string(userdata); - pa_log_notice(c); + pa_log_notice("%s", c); pa_xfree(c); return; } @@ -121,7 +121,7 @@ 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.\n"); + pa_log_info(__FILE__": Exiting."); m->quit(m, 1); break; } @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) { suid_root = getuid() != 0 && geteuid() == 0; if (suid_root && (pa_uid_in_group("realtime", &gid) <= 0 || gid >= 1000)) { - pa_log_warn(__FILE__": WARNING: called SUID root, but not in group 'realtime'.\n"); + pa_log_warn(__FILE__": WARNING: called SUID root, but not in group 'realtime'."); pa_drop_root(); } #else @@ -191,7 +191,7 @@ 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.\n"); + pa_log(__FILE__": failed to parse command line."); goto finish; } @@ -237,9 +237,9 @@ int main(int argc, char *argv[]) { pid_t pid; if (pa_pid_file_check_running(&pid) < 0) { - pa_log_info(__FILE__": daemon not running\n"); + pa_log_info(__FILE__": daemon not running"); } else { - pa_log_info(__FILE__": daemon running as PID %u\n", pid); + pa_log_info(__FILE__": daemon running as PID %u", pid); retval = 0; } @@ -249,7 +249,7 @@ 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.\n"); + pa_log(__FILE__": failed to kill daemon."); else retval = 0; @@ -264,18 +264,18 @@ int main(int argc, char *argv[]) { int tty_fd; if (pa_stdio_acquire() < 0) { - pa_log(__FILE__": failed to acquire stdio.\n"); + pa_log(__FILE__": failed to acquire stdio."); goto finish; } #ifdef HAVE_FORK if (pipe(daemon_pipe) < 0) { - pa_log(__FILE__": failed to create pipe.\n"); + pa_log(__FILE__": failed to create pipe."); goto finish; } if ((child = fork()) < 0) { - pa_log(__FILE__": fork() failed: %s\n", strerror(errno)); + pa_log(__FILE__": fork() failed: %s", strerror(errno)); goto finish; } @@ -286,14 +286,14 @@ int main(int argc, char *argv[]) { daemon_pipe[1] = -1; if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval)) != sizeof(retval)) { - pa_log(__FILE__": read() failed: %s\n", strerror(errno)); + pa_log(__FILE__": read() failed: %s", strerror(errno)); retval = 1; } if (retval) - pa_log(__FILE__": daemon startup failed.\n"); + pa_log(__FILE__": daemon startup failed."); else - pa_log_info(__FILE__": daemon startup successful.\n"); + pa_log_info(__FILE__": daemon startup successful."); goto finish; } @@ -346,7 +346,7 @@ int main(int argc, char *argv[]) { if (conf->use_pid_file) { if (pa_pid_file_create() < 0) { - pa_log(__FILE__": pa_pid_file_create() failed.\n"); + pa_log(__FILE__": pa_pid_file_create() failed."); #ifdef HAVE_FORK if (conf->daemonize) pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); @@ -396,23 +396,22 @@ int main(int argc, char *argv[]) { assert(r == 0); buf = pa_strbuf_new(); - assert(buf); 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(s = pa_strbuf_tostring_free(buf)); + 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.\n"); + pa_log(__FILE__": failed to initialize daemon."); #ifdef HAVE_FORK if (conf->daemonize) pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); #endif } else if (!c->modules || pa_idxset_size(c->modules) == 0) { - pa_log(__FILE__": daemon startup without any loaded modules, refusing to work.\n"); + 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)); @@ -433,13 +432,13 @@ int main(int argc, char *argv[]) { 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.\n", __FILE__, c->default_sink_name); + 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.\n"); + pa_log_info(__FILE__": Daemon startup complete."); if (pa_mainloop_run(mainloop, &retval) < 0) retval = 1; - pa_log_info(__FILE__": Daemon shutdown initiated.\n"); + pa_log_info(__FILE__": Daemon shutdown initiated."); } } @@ -453,7 +452,7 @@ int main(int argc, char *argv[]) { pa_signal_done(); pa_mainloop_free(mainloop); - pa_log_info(__FILE__": Daemon terminated.\n"); + pa_log_info(__FILE__": Daemon terminated."); finish: -- cgit From 435897741505fbdac30002b02c55a528f6ec8a40 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Feb 2006 17:14:23 +0000 Subject: * Add new "auth-group=" parameter to protocol-native-unix * Rename "public=" argument of protocol-{esound,native} to "auth-anonymous" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@601 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 4b972fe2..8457916a 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) { #ifdef HAVE_GETUID suid_root = getuid() != 0 && geteuid() == 0; - if (suid_root && (pa_uid_in_group("realtime", &gid) <= 0 || gid >= 1000)) { + if (suid_root && (pa_own_uid_in_group("realtime", &gid) <= 0 || gid >= 1000)) { pa_log_warn(__FILE__": WARNING: called SUID root, but not in group 'realtime'."); pa_drop_root(); } -- cgit From fe64b89fd846518efec535f1b567d3b2bfa9bd70 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 13 Apr 2006 17:33:06 +0000 Subject: add code to allow polypaudio dump preloaded modules using "--dump-modules" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@702 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/dumpmodules.c | 51 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index bf29a681..c541c168 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -78,15 +78,41 @@ static void show_info(const char *name, const char *path, void (*info)(const cha } } +extern const lt_dlsymlist lt_preloaded_symbols[]; + +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); + if ((e = strrchr(buf, '.'))) + *e = 0; + + if (!strcmp(name, buf)) + return 1; + } + + return 0; +} + static int callback(const char *path, lt_ptr data) { const char *e; pa_daemon_conf *c = (data); e = pa_path_get_filename(path); - if (strlen(e) > sizeof(PREFIX)-1 && !strncmp(e, PREFIX, sizeof(PREFIX)-1)) - show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info); + if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1)) + return 0; + + if (is_preloaded(e)) + return 0; + show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info); return 0; } @@ -95,6 +121,25 @@ void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) { int i; for (i = 0; i < argc; i++) show_info(argv[i], NULL, long_info); - } else + } else { + const lt_dlsymlist *l; + + 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); + 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); + } } -- cgit From 0990d8c796e9896e791d1ce23557e6d2f5ecf5b0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 16 Apr 2006 09:13:09 +0000 Subject: initialize random seed globaly from $RANDOM_DEVICE git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@719 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 8457916a..d783531a 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -135,6 +135,29 @@ static void close_pipe(int p[2]) { p[0] = p[1] = -1; } +static void set_random_seed(void) { + unsigned int seed = 0; + +#ifdef RANDOM_DEVICE + int fd; + + if ((fd = open(RANDOM_DEVICE, O_RDONLY)) >= 0) { + ssize_t r; + + if ((r = pa_loop_read(fd, &seed, sizeof(seed))) < 0 || (size_t) r != sizeof(seed)) { + pa_log_error(__FILE__": failed to read entropy from '"RANDOM_DEVICE"'"); + seed += (unsigned int) time(NULL); + } + + close(fd); + } +#else + seed = (unsigned int) time(NULL); +#endif + + srand(seed); +} + int main(int argc, char *argv[]) { pa_core *c; pa_strbuf *buf = NULL; @@ -180,6 +203,8 @@ int main(int argc, char *argv[]) { } #endif + set_random_seed(); + pa_log_set_ident("polypaudio"); conf = pa_daemon_conf_new(); -- cgit From c22a0c12e49181d6ea042993e6b4b47db69574b1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 18 Apr 2006 15:16:24 +0000 Subject: Make the probe for RNG sources at runtime since the configure script isn't compatible with cross-compiling. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@744 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index d783531a..4ae9fbf1 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -63,6 +63,7 @@ #include #include #include +#include #include "cmdline.h" #include "cpulimit.h" @@ -135,29 +136,6 @@ static void close_pipe(int p[2]) { p[0] = p[1] = -1; } -static void set_random_seed(void) { - unsigned int seed = 0; - -#ifdef RANDOM_DEVICE - int fd; - - if ((fd = open(RANDOM_DEVICE, O_RDONLY)) >= 0) { - ssize_t r; - - if ((r = pa_loop_read(fd, &seed, sizeof(seed))) < 0 || (size_t) r != sizeof(seed)) { - pa_log_error(__FILE__": failed to read entropy from '"RANDOM_DEVICE"'"); - seed += (unsigned int) time(NULL); - } - - close(fd); - } -#else - seed = (unsigned int) time(NULL); -#endif - - srand(seed); -} - int main(int argc, char *argv[]) { pa_core *c; pa_strbuf *buf = NULL; @@ -203,7 +181,7 @@ int main(int argc, char *argv[]) { } #endif - set_random_seed(); + pa_random_seed(); pa_log_set_ident("polypaudio"); -- cgit From 6ae8511a66c0f937bdab2786ecdc7e158bd3934d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 19 Apr 2006 11:53:24 +0000 Subject: Having constant deferred events isn't allowed and causes problems. Use timers instead. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@757 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 4ae9fbf1..e14837a9 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -79,8 +79,9 @@ int deny_severity = LOG_WARNING; #ifdef OS_IS_WIN32 -static void message_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { +static void message_cb(pa_mainloop_api*a, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { MSG msg; + struct timeval tvnext; while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) @@ -90,6 +91,9 @@ static void message_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { DispatchMessage(&msg); } } + + pa_timeval_add(pa_gettimeofday(&tvnext), 100000); + a->time_restart(e, &tvnext); } #endif @@ -153,7 +157,8 @@ int main(int argc, char *argv[]) { #endif #ifdef OS_IS_WIN32 - pa_defer_event *defer; + pa_time_event *timer; + struct timeval tv; #endif pa_limit_caps(); @@ -386,8 +391,9 @@ int main(int argc, char *argv[]) { #endif #ifdef OS_IS_WIN32 - defer = pa_mainloop_get_api(mainloop)->defer_new(pa_mainloop_get_api(mainloop), message_cb, NULL); - assert(defer); + timer = pa_mainloop_get_api(mainloop)->time_new( + pa_mainloop_get_api(mainloop), pa_gettimeofday(&tv), message_cb, NULL); + assert(timer); #endif if (conf->daemonize) @@ -446,7 +452,7 @@ int main(int argc, char *argv[]) { } #ifdef OS_IS_WIN32 - pa_mainloop_get_api(mainloop)->defer_free(defer); + pa_mainloop_get_api(mainloop)->time_free(timer); #endif pa_core_free(c); -- cgit From f426b58e5c1c584aba8fd37fe7f2e523410b78bc Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 25 Apr 2006 07:13:44 +0000 Subject: glibc <= 2.2 has a broken unistd.h, lacking setresuid(). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@795 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 5c52b77a..8740b7e8 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -36,6 +36,12 @@ #include "caps.h" +/* Glibc <= 2.2 has broken unistd.h */ +#if defined(linux) && (__GLIBC__ <= 2 && __GLIBC_MINOR__ <= 2) +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 */ -- cgit From be05b18c6fb6f0e2e2b74ffdf251692a45eaa045 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 14 May 2006 00:41:18 +0000 Subject: * add new parameter to pa_open_config_file() to specify open mode * modify pa_sink_input_new() to take initial volume settings as argument * call pa_sink_input_set_volume() when changing stream volume in protocol-esound.c to make sure that subscribe events are issued properly git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@858 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index ac5fbb16..f41bb4b1 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -84,7 +84,7 @@ pa_daemon_conf* pa_daemon_conf_new(void) { FILE *f; pa_daemon_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); - if ((f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file))) + if ((f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file, "r"))) fclose(f); #ifdef DLSEARCHPATH @@ -233,7 +233,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { 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); + pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file, "r"); if (!f && errno != ENOENT) { pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", filename, strerror(errno)); -- cgit From cdd3588f3a0fc9efeff7ce85215304bf33e2504e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 15:38:58 +0000 Subject: more sensible default.pa file git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@907 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 49 ++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index 3aaeeaf0..cba0172f 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -18,17 +18,18 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -# Load audio drivers statically - +### Load audio drivers statically #load-module module-alsa-sink -# load-module module-alsa-source device=plughw:1,0 -load-module module-oss device="/dev/dsp" sink_name=output source_name=input +#load-module module-alsa-source device=plughw:1,0 +#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 -load-module module-null-sink +#load-module module-null-sink #load-module module-pipe-sink -# Load audio drivers automatically on access +### Automatically load driver modules depending on the hardware available +load-module module-detect +### 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 @@ -36,31 +37,35 @@ load-module module-null-sink #add-autoload-sink output module-alsa-sink sink_name=output #add-autoload-source input module-alsa-source source_name=input -# Load several protocols +### Load several protocols load-module module-esound-protocol-unix #load-module module-esound-protocol-tcp load-module module-native-protocol-unix -#load-module module-simple-protocol-tcp -#load-module module-cli-protocol-unix +#load-module module-native-protocol-tcp + +### Load the RTP reciever module +#load-module module-rtp-recv -# Load the CLI module -load-module module-cli +### Load the RTP sender module +#load-module module-null-sink sink_name=rtp +#load-module module-rtp-send source=rtp_monitor -# Make some devices default -set-default-sink output -set-default-source input +### Automatically restore the volume of playback streams +load-module module-volume-restore + +### Make some devices default +#set-default-sink output +#set-default-source input .nofail -# Load something to the sample cache -load-sample x11-bell /usr/share/sounds/KDE_Notify.wav -load-sample-dir-lazy /usr/share/sounds/*.wav +### 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 -# Load X11 bell module -load-module module-x11-bell sample=x11-bell sink=output +### Load X11 bell module +load-module module-x11-bell sample=x11-bell -# Publish connection data in the X11 root window +### Publish connection data in the X11 root window load-module module-x11-publish -#load-module module-pipe-source -#load-module module-pipe-sink -- cgit From d9cc2cfcb97c1b0449bcbfb6ab0301a58d77bd55 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 17 May 2006 16:34:18 +0000 Subject: Move xmalloc to the public side (libpolyp). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@908 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 3 ++- src/daemon/daemon-conf.c | 3 ++- src/daemon/main.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index a6b95a81..1ed16a69 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -30,9 +30,10 @@ #include #include +#include + #include #include -#include #include "cmdline.h" diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index f41bb4b1..f82d3d24 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -29,8 +29,9 @@ #include #include +#include + #include -#include #include #include #include diff --git a/src/daemon/main.c b/src/daemon/main.c index e14837a9..a7144eba 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -59,7 +60,6 @@ #include #include #include -#include #include #include #include -- cgit From 53a285e75616281bcdd8b1dcf0e3b7ba59257516 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 20:44:55 +0000 Subject: fix include line for "core-util.h" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@923 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 2 +- src/daemon/cpulimit.c | 2 +- src/daemon/daemon-conf.c | 2 +- src/daemon/dumpmodules.c | 2 +- src/daemon/main.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index 1ed16a69..21fd5a25 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -32,7 +32,7 @@ #include -#include +#include #include #include "cmdline.h" diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 54f111da..69973384 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -23,7 +23,7 @@ #include #endif -#include +#include #include #include "cpulimit.h" diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index f82d3d24..0f4fcb97 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -31,7 +31,7 @@ #include -#include +#include #include #include #include diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index c541c168..b6a3bb7c 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include "dumpmodules.h" diff --git a/src/daemon/main.c b/src/daemon/main.c index a7144eba..9b9ea180 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include #include -- cgit From 24a781992bad4d66bb7bc3a2d1deeba7e959dbb1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 18 May 2006 07:04:41 +0000 Subject: Don't include util.h from core-util.h as it is not needed by many users. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@929 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/dumpmodules.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index b6a3bb7c..d56bb798 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -29,8 +29,9 @@ #include #include +#include + #include -#include #include "dumpmodules.h" -- cgit From 13798312efde92a618a024064b1b2f2f69dfddaa Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 18 May 2006 10:36:36 +0000 Subject: Convert log text to current locale before passing it on to stderr or syslog. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@933 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 9b9ea180..b4bc4e00 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -161,6 +162,8 @@ int main(int argc, char *argv[]) { struct timeval tv; #endif + setlocale(LC_ALL, ""); + pa_limit_caps(); #ifdef HAVE_GETUID -- cgit From 4e3dc7ce68561c16254712d713b2ccd472b8afe7 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 22 May 2006 15:20:46 +0000 Subject: Wrap strerror() in a function that makes it thread safe and converts the output to UTF-8. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@945 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 4 +++- src/daemon/cpulimit.c | 4 +++- src/daemon/daemon-conf.c | 3 ++- src/daemon/main.c | 5 +++-- 4 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 8740b7e8..4942868c 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -32,6 +32,8 @@ #include #endif +#include + #include #include "caps.h" @@ -110,7 +112,7 @@ int pa_drop_caps(void) { cap_clear(caps); if (cap_set_proc(caps) < 0) { - pa_log(__FILE__": failed to drop capabilities: %s", strerror(errno)); + pa_log(__FILE__": failed to drop capabilities: %s", pa_cstrerror(errno)); goto fail; } diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 69973384..2cc37be6 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -23,6 +23,8 @@ #include #endif +#include + #include #include @@ -169,7 +171,7 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { /* Prepare the main loop pipe */ if (pipe(the_pipe) < 0) { - pa_log(__FILE__": pipe() failed: %s", strerror(errno)); + pa_log(__FILE__": pipe() failed: %s", pa_cstrerror(errno)); return -1; } diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 0f4fcb97..809769f8 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -237,7 +238,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file, "r"); if (!f && errno != ENOENT) { - pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", filename, strerror(errno)); + pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", filename, pa_cstrerror(errno)); goto finish; } diff --git a/src/daemon/main.c b/src/daemon/main.c index b4bc4e00..2fadd496 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -50,6 +50,7 @@ #include "../polypcore/winsock.h" +#include #include #include #include @@ -286,7 +287,7 @@ int main(int argc, char *argv[]) { } if ((child = fork()) < 0) { - pa_log(__FILE__": fork() failed: %s", strerror(errno)); + pa_log(__FILE__": fork() failed: %s", pa_cstrerror(errno)); goto finish; } @@ -297,7 +298,7 @@ int main(int argc, char *argv[]) { daemon_pipe[1] = -1; if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval)) != sizeof(retval)) { - pa_log(__FILE__": read() failed: %s", strerror(errno)); + pa_log(__FILE__": read() failed: %s", pa_cstrerror(errno)); retval = 1; } -- cgit From 4413b89d7a45587b545a31463ad2196767f45563 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 25 May 2006 17:16:55 +0000 Subject: * split pa_cstrerror() into its own file polypcore/core-error.[ch] * fix building of padsp * remove a warning when compiling padsp.c git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@972 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 2 +- src/daemon/daemon-conf.c | 2 +- src/daemon/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 4942868c..5e24da82 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -32,7 +32,7 @@ #include #endif -#include +#include #include diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 809769f8..2d8d9558 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -29,9 +29,9 @@ #include #include -#include #include +#include #include #include #include diff --git a/src/daemon/main.c b/src/daemon/main.c index 2fadd496..b88f932c 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -50,11 +50,11 @@ #include "../polypcore/winsock.h" -#include #include #include #include +#include #include #include #include -- cgit From f5a888504fe70c0106c791e2d97caa3cd5675aef Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 26 May 2006 17:59:39 +0000 Subject: disable padsp for the polypaudio daemon itself by defining the __padsp_disabled__ symbol git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@983 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index b88f932c..16cc0f5e 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -79,6 +79,13 @@ int allow_severity = LOG_INFO; int deny_severity = LOG_WARNING; #endif +#ifdef HAVE_OSS +/* 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. */ +int __padsp_disabled__ = 7; +#endif + #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) { -- cgit From 632f5b44f5149477462a9b59c832c59fe6eaa7ae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 May 2006 12:59:10 +0000 Subject: drop the .sh suffix from esdcompat git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@986 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/esdcompat.in | 98 ++++++++++++++++++++++++++++++++++++++++++++++ src/daemon/esdcompat.sh.in | 98 ---------------------------------------------- 2 files changed, 98 insertions(+), 98 deletions(-) create mode 100755 src/daemon/esdcompat.in delete mode 100755 src/daemon/esdcompat.sh.in (limited to 'src/daemon') diff --git a/src/daemon/esdcompat.in b/src/daemon/esdcompat.in new file mode 100755 index 00000000..76023f52 --- /dev/null +++ b/src/daemon/esdcompat.in @@ -0,0 +1,98 @@ +#!/bin/sh + +# $Id$ +# +# This file is part of polypaudio. +# +# polypaudio 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. +# +# polypaudio 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 polypaudio; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +VERSION_STRING="@PACKAGE_NAME@ esd wrapper @PACKAGE_VERSION@" + +fail() { + echo "ERROR: $1" + exit 1 +} + +ARGS=" --log-target=syslog" + +for N in $(seq $#) ; do + + case "$1" in + "") + ;; + + -v|--version) + echo "$VERSION_STRING" + exit 0 + ;; + + -h|--help) + cat < Date: Fri, 2 Jun 2006 22:56:20 +0000 Subject: actually build cpulimit support if SIGXCPU is available git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1005 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cpulimit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 2cc37be6..d537b9db 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -26,6 +26,7 @@ #include #include +#include #include #include "cpulimit.h" @@ -62,8 +63,8 @@ /* Check every 10s */ #define CPUTIME_INTERVAL_SOFT (10) -/* Recheck after 2s */ -#define CPUTIME_INTERVAL_HARD (2) +/* Recheck after 5s */ +#define CPUTIME_INTERVAL_HARD (5) /* Time of the last CPU load check */ static time_t last_time = 0; @@ -155,7 +156,7 @@ static void signal_handler(int sig) { } /* Callback for IO events on the FIFO */ -static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags f, void *userdata) { +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]); read(the_pipe[0], &c, sizeof(c)); -- cgit From bd432f0590bdda2c42887f1d6da07ff0bb571013 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 18 Jun 2006 11:10:45 +0000 Subject: * add new argument 'exit_on_eof' to module-cli and make use of it if "-C" is passed to the daemon git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1026 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index 21fd5a25..b71be2e6 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -186,7 +186,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d break; case 'C': - pa_strbuf_puts(buf, "load-module module-cli\n"); + pa_strbuf_puts(buf, "load-module module-cli exit_on_eof=1\n"); break; case ARG_DAEMONIZE: -- cgit From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/Makefile | 2 +- src/daemon/caps.c | 12 ++++++------ src/daemon/caps.h | 8 ++++---- src/daemon/cmdline.c | 14 +++++++------- src/daemon/cmdline.h | 8 ++++---- src/daemon/cpulimit.c | 16 ++++++++-------- src/daemon/cpulimit.h | 12 ++++++------ src/daemon/daemon-conf.c | 26 +++++++++++++------------- src/daemon/daemon-conf.h | 10 +++++----- src/daemon/daemon.conf.in | 16 ++++++++-------- src/daemon/default.pa.in | 8 ++++---- src/daemon/default.pa.win32 | 8 ++++---- src/daemon/dumpmodules.c | 12 ++++++------ src/daemon/dumpmodules.h | 8 ++++---- src/daemon/esdcompat.in | 8 ++++---- src/daemon/main.c | 42 +++++++++++++++++++++--------------------- 16 files changed, 105 insertions(+), 105 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/Makefile b/src/daemon/Makefile index cd2a5c9a..c110232d 120000 --- a/src/daemon/Makefile +++ b/src/daemon/Makefile @@ -1 +1 @@ -../polyp/Makefile \ No newline at end of file +../pulse/Makefile \ No newline at end of file diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 5e24da82..dc74bc7d 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -32,9 +32,9 @@ #include #endif -#include +#include -#include +#include #include "caps.h" diff --git a/src/daemon/caps.h b/src/daemon/caps.h index 3bb861d1..8a618286 100644 --- a/src/daemon/caps.h +++ b/src/daemon/caps.h @@ -4,20 +4,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index b71be2e6..a106dc09 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -30,10 +30,10 @@ #include #include -#include +#include -#include -#include +#include +#include #include "cmdline.h" diff --git a/src/daemon/cmdline.h b/src/daemon/cmdline.h index e2eaf0d2..25453e55 100644 --- a/src/daemon/cmdline.h +++ b/src/daemon/cmdline.h @@ -4,20 +4,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index d537b9db..a8c9d3f5 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -23,11 +23,11 @@ #include #endif -#include +#include -#include -#include -#include +#include +#include +#include #include "cpulimit.h" diff --git a/src/daemon/cpulimit.h b/src/daemon/cpulimit.h index f3c5534d..21bdd17b 100644 --- a/src/daemon/cpulimit.h +++ b/src/daemon/cpulimit.h @@ -4,27 +4,27 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ -#include +#include -/* This kills the polypaudio process if it eats more than 70% of the +/* This kills the pulseaudio process if it eats more than 70% of the * CPU time. This is build around setrlimit() and SIGXCPU. It is handy * in case of using SCHED_FIFO which may freeze the whole machine */ diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 2d8d9558..fd83f28f 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -29,19 +29,19 @@ #include #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "daemon-conf.h" #ifndef DEFAULT_CONFIG_DIR # ifndef OS_IS_WIN32 -# define DEFAULT_CONFIG_DIR "/etc/polypaudio" +# define DEFAULT_CONFIG_DIR "/etc/pulseaudio" # else # define DEFAULT_CONFIG_DIR "%POLYP_ROOT%" # endif @@ -54,9 +54,9 @@ #endif #define DEFAULT_SCRIPT_FILE DEFAULT_CONFIG_DIR PATH_SEP "default.pa" -#define DEFAULT_SCRIPT_FILE_USER ".polypaudio" PATH_SEP "default.pa" +#define DEFAULT_SCRIPT_FILE_USER ".pulseaudio" PATH_SEP "default.pa" #define DEFAULT_CONFIG_FILE DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf" -#define DEFAULT_CONFIG_FILE_USER ".polypaudio" PATH_SEP "daemon.conf" +#define DEFAULT_CONFIG_FILE_USER ".pulseaudio" PATH_SEP "daemon.conf" #define ENV_SCRIPT_FILE "POLYP_SCRIPT" #define ENV_CONFIG_FILE "POLYP_CONFIG" diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index d5131419..dd5d7fb8 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -4,25 +4,25 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ -#include +#include /* The actual command to execute */ typedef enum pa_daemon_conf_cmd { diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index d5373018..30bf3ca1 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -1,23 +1,23 @@ # $Id$ # -# This file is part of polypaudio. +# This file is part of PulseAudio. # -# polypaudio is free software; you can redistribute it and/or modify +# 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. # -# polypaudio is distributed in the hope that it will be useful, but +# 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 polypaudio; if not, write to the Free Software +# along with PulseAudio; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. -## Configuration file for the polypaudio daemon. Default values are +## Configuration file for the pulseaudio daemon. Default values are ## commented out. Use either ; or # for commenting # Extra verbositiy @@ -69,9 +69,9 @@ ## hand it has the worst quality of all. ; resample-method = sinc-fastest -## Create a PID file in /tmp/polypaudio-$USER/pid. Of this is enabled -## you may use commands like "polypaudio --kill" or "polypaudio -## --check". If you are planning to start more than one polypaudio +## 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 diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index cba0172f..623cd114 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -1,20 +1,20 @@ #!@POLYPAUDIO_BINARY@ -nF # -# This file is part of polypaudio. +# This file is part of PulseAudio. # -# polypaudio is free software; you can redistribute it and/or modify it +# 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. # -# polypaudio is distributed in the hope that it will be useful, but +# 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 polypaudio; if not, write to the Free Software Foundation, +# along with PulseAudio; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. diff --git a/src/daemon/default.pa.win32 b/src/daemon/default.pa.win32 index 3478adab..d5a1e183 100644 --- a/src/daemon/default.pa.win32 +++ b/src/daemon/default.pa.win32 @@ -1,18 +1,18 @@ # -# This file is part of polypaudio. +# This file is part of PulseAudio. # -# polypaudio is free software; you can redistribute it and/or modify it +# 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. # -# polypaudio is distributed in the hope that it will be useful, but +# 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 polypaudio; if not, write to the Free Software Foundation, +# along with PulseAudio; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index d56bb798..06734ea6 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -29,9 +29,9 @@ #include #include -#include +#include -#include +#include #include "dumpmodules.h" diff --git a/src/daemon/dumpmodules.h b/src/daemon/dumpmodules.h index 968d2de9..05cd86e0 100644 --- a/src/daemon/dumpmodules.h +++ b/src/daemon/dumpmodules.h @@ -4,20 +4,20 @@ /* $Id*/ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ diff --git a/src/daemon/esdcompat.in b/src/daemon/esdcompat.in index 76023f52..673f8c8a 100755 --- a/src/daemon/esdcompat.in +++ b/src/daemon/esdcompat.in @@ -2,20 +2,20 @@ # $Id$ # -# This file is part of polypaudio. +# This file is part of PulseAudio. # -# polypaudio is free software; you can redistribute it and/or modify +# 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. # -# polypaudio is distributed in the hope that it will be useful, but +# 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 polypaudio; if not, write to the Free Software +# along with PulseAudio; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. diff --git a/src/daemon/main.c b/src/daemon/main.c index 16cc0f5e..5e7330a5 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -48,24 +48,24 @@ #include #endif -#include "../polypcore/winsock.h" +#include "../pulsecore/winsock.h" -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "cmdline.h" #include "cpulimit.h" @@ -199,7 +199,7 @@ int main(int argc, char *argv[]) { pa_random_seed(); - pa_log_set_ident("polypaudio"); + pa_log_set_ident("pulseaudio"); conf = pa_daemon_conf_new(); -- cgit From 10b5e997d7a8a4e955ce49cc816fdcd36225ff6e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 22:11:49 +0000 Subject: replace a few remaining uppercase "Polypaudio" occurences with "PulseAudio" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1036 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index dd5d7fb8..c325495c 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -35,7 +35,7 @@ typedef enum pa_daemon_conf_cmd { PA_CMD_CHECK } pa_daemon_conf_cmd_t; -/* A structure containing configuration data for the Polypaudio server . */ +/* A structure containing configuration data for the PulseAudio server . */ typedef struct pa_daemon_conf { pa_daemon_conf_cmd_t cmd; int daemonize, -- cgit From 3cf16214334b4a1c51e56b0536abd8223d6813dd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 23:51:58 +0000 Subject: * more s/pulseaudio/PulseAudio/ replacements * name the per-user dir ~/.pulse (instead of .pulseaudio), just like /etc/pulse/ git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1039 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index fd83f28f..4d458a5c 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -41,7 +41,7 @@ #ifndef DEFAULT_CONFIG_DIR # ifndef OS_IS_WIN32 -# define DEFAULT_CONFIG_DIR "/etc/pulseaudio" +# define DEFAULT_CONFIG_DIR "/etc/pulse" # else # define DEFAULT_CONFIG_DIR "%POLYP_ROOT%" # endif @@ -54,9 +54,9 @@ #endif #define DEFAULT_SCRIPT_FILE DEFAULT_CONFIG_DIR PATH_SEP "default.pa" -#define DEFAULT_SCRIPT_FILE_USER ".pulseaudio" PATH_SEP "default.pa" +#define DEFAULT_SCRIPT_FILE_USER ".pulse" PATH_SEP "default.pa" #define DEFAULT_CONFIG_FILE DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf" -#define DEFAULT_CONFIG_FILE_USER ".pulseaudio" PATH_SEP "daemon.conf" +#define DEFAULT_CONFIG_FILE_USER ".pulse" PATH_SEP "daemon.conf" #define ENV_SCRIPT_FILE "POLYP_SCRIPT" #define ENV_CONFIG_FILE "POLYP_CONFIG" -- cgit From 230f97a4a4dc22510a19add8b2df0533a359846c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 23:56:54 +0000 Subject: s/POLYP/PULSE/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1041 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 4d458a5c..64e8d235 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -43,7 +43,7 @@ # ifndef OS_IS_WIN32 # define DEFAULT_CONFIG_DIR "/etc/pulse" # else -# define DEFAULT_CONFIG_DIR "%POLYP_ROOT%" +# define DEFAULT_CONFIG_DIR "%PULSE_ROOT%" # endif #endif @@ -58,9 +58,9 @@ #define DEFAULT_CONFIG_FILE DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf" #define DEFAULT_CONFIG_FILE_USER ".pulse" PATH_SEP "daemon.conf" -#define ENV_SCRIPT_FILE "POLYP_SCRIPT" -#define ENV_CONFIG_FILE "POLYP_CONFIG" -#define ENV_DL_SEARCH_PATH "POLYP_DLPATH" +#define ENV_SCRIPT_FILE "PULSE_SCRIPT" +#define ENV_CONFIG_FILE "PULSE_CONFIG" +#define ENV_DL_SEARCH_PATH "PULSE_DLPATH" static const pa_daemon_conf default_conf = { .cmd = PA_CMD_DAEMON, -- cgit From 3ff68bd7a57186c6c6def975be3fc7e826c8bbcd Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 20 Jun 2006 13:02:34 +0000 Subject: Fix the final few occurences of polyp. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1042 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 2 +- src/daemon/esdcompat.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index 623cd114..6beeb90f 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -1,4 +1,4 @@ -#!@POLYPAUDIO_BINARY@ -nF +#!@PULSEAUDIO_BINARY@ -nF # # This file is part of PulseAudio. diff --git a/src/daemon/esdcompat.in b/src/daemon/esdcompat.in index 673f8c8a..edae8615 100755 --- a/src/daemon/esdcompat.in +++ b/src/daemon/esdcompat.in @@ -95,4 +95,4 @@ EOF shift done -eval "exec '@POLYPAUDIO_BINARY@'$ARGS" +eval "exec '@PULSEAUDIO_BINARY@'$ARGS" -- cgit From 8b0d1346022d0eb3f3b4bf3eb956f9757ff57156 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 30 Jun 2006 08:16:14 +0000 Subject: Make sure we print the file name we actually use. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1054 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 64e8d235..d1afed7b 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -238,7 +238,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file, "r"); if (!f && errno != ENOENT) { - pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", filename, pa_cstrerror(errno)); + pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", c->config_file, pa_cstrerror(errno)); goto finish; } -- cgit From 860be2e70b33ff5eeb9130f80c4b1c096a2a8f27 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Jul 2006 22:42:01 +0000 Subject: try to use send(,,MSG_NOSIGNAL) instead of write() wherever possible (which will allow us to drop the SIGPIPE check). Cache the results of the last write()/send() to make sure that we do not issue more than necessary system calls. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1083 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cpulimit.c | 4 ++-- src/daemon/main.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index a8c9d3f5..b8740ea0 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -111,7 +111,7 @@ static void reset_cpu_time(int t) { /* A simple, thread-safe puts() work-alike */ static void write_err(const char *p) { - pa_loop_write(2, p, strlen(p)); + pa_loop_write(2, p, strlen(p), NULL); } /* The signal handler, called on every SIGXCPU */ @@ -159,7 +159,7 @@ static void signal_handler(int sig) { 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]); - read(the_pipe[0], &c, sizeof(c)); + pa_read(the_pipe[0], &c, sizeof(c), NULL); m->quit(m, 1); /* Quit the main loop */ } diff --git a/src/daemon/main.c b/src/daemon/main.c index 5e7330a5..c41c69df 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -304,7 +304,7 @@ int main(int argc, char *argv[]) { close(daemon_pipe[1]); daemon_pipe[1] = -1; - if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval)) != sizeof(retval)) { + if (pa_loop_read(daemon_pipe[0], &retval, sizeof(retval), NULL) != sizeof(retval)) { pa_log(__FILE__": read() failed: %s", pa_cstrerror(errno)); retval = 1; } @@ -368,7 +368,7 @@ int main(int argc, char *argv[]) { pa_log(__FILE__": pa_pid_file_create() failed."); #ifdef HAVE_FORK if (conf->daemonize) - pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL); #endif goto finish; } @@ -428,20 +428,20 @@ int main(int argc, char *argv[]) { pa_log(__FILE__": failed to initialize daemon."); #ifdef HAVE_FORK if (conf->daemonize) - pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); + 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)); + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL); #endif } else { retval = 0; #ifdef HAVE_FORK if (conf->daemonize) - pa_loop_write(daemon_pipe[1], &retval, sizeof(retval)); + pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL); #endif c->disallow_module_loading = conf->disallow_module_loading; -- cgit From 9c87a65ce91c38b60c19ae108a51a2e8ce46a85c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jul 2006 17:44:19 +0000 Subject: * add new --system command line parameter to the daemon for running PulseAudio as system-wide instance * add PA_ prefixes to all global #defines * modify auth-by-creds: define a new group "pulse-access" which is used for authentication * add proper privilige dropping when running in --system mode * create runtime directory once on startup and not by each module seperately git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1105 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 12 ++++- src/daemon/daemon-conf.c | 22 +++----- src/daemon/daemon-conf.h | 3 +- src/daemon/daemon.conf.in | 6 +++ src/daemon/main.c | 129 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 151 insertions(+), 21 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index a106dc09..ab876edf 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -58,7 +58,8 @@ enum { ARG_RESAMPLE_METHOD, ARG_KILL, ARG_USE_PID_FILE, - ARG_CHECK + ARG_CHECK, + ARG_SYSTEM }; /* Tabel for getopt_long() */ @@ -84,6 +85,7 @@ static struct option long_options[] = { {"kill", 0, 0, ARG_KILL}, {"use-pid-file", 2, 0, ARG_USE_PID_FILE}, {"check", 0, 0, ARG_CHECK}, + {"system", 2, 0, ARG_SYSTEM}, {NULL, 0, 0, 0} }; @@ -105,6 +107,7 @@ void pa_cmdline_help(const char *argv0) { " --check Check for a running daemon\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" @@ -276,6 +279,13 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d goto fail; } break; + + case ARG_SYSTEM: + if ((conf->system_instance = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + pa_log(__FILE__": --system expects boolean argument"); + goto fail; + } + break; default: goto fail; diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index d1afed7b..a5a62567 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -39,23 +39,15 @@ #include "daemon-conf.h" -#ifndef DEFAULT_CONFIG_DIR -# ifndef OS_IS_WIN32 -# define DEFAULT_CONFIG_DIR "/etc/pulse" -# else -# define DEFAULT_CONFIG_DIR "%PULSE_ROOT%" -# endif -#endif - #ifndef OS_IS_WIN32 # define PATH_SEP "/" #else # define PATH_SEP "\\" #endif -#define DEFAULT_SCRIPT_FILE DEFAULT_CONFIG_DIR PATH_SEP "default.pa" +#define DEFAULT_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PATH_SEP "default.pa" #define DEFAULT_SCRIPT_FILE_USER ".pulse" PATH_SEP "default.pa" -#define DEFAULT_CONFIG_FILE DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf" +#define DEFAULT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf" #define DEFAULT_CONFIG_FILE_USER ".pulse" PATH_SEP "daemon.conf" #define ENV_SCRIPT_FILE "PULSE_SCRIPT" @@ -79,7 +71,8 @@ static const pa_daemon_conf default_conf = { .log_level = PA_LOG_NOTICE, .resample_method = PA_RESAMPLER_SRC_SINC_FASTEST, .config_file = NULL, - .use_pid_file = 1 + .use_pid_file = 1, + .system_instance = 0 }; pa_daemon_conf* pa_daemon_conf_new(void) { @@ -89,9 +82,7 @@ pa_daemon_conf* pa_daemon_conf_new(void) { if ((f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file, "r"))) fclose(f); -#ifdef DLSEARCHPATH - c->dl_search_path = pa_xstrdup(DLSEARCHPATH); -#endif + c->dl_search_path = pa_xstrdup(PA_DLSEARCHPATH); return c; } @@ -212,6 +203,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "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 }, { NULL, NULL, NULL }, }; @@ -229,6 +221,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { table[11].data = c; table[12].data = c; table[13].data = &c->use_pid_file; + table[14].data = &c->system_instance; pa_xfree(c->config_file); c->config_file = NULL; @@ -295,6 +288,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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); return pa_strbuf_tostring_free(s); } diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index c325495c..bfea7358 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -46,7 +46,8 @@ typedef struct pa_daemon_conf { module_idle_time, scache_idle_time, auto_log_target, - use_pid_file; + use_pid_file, + system_instance; char *script_commands, *dl_search_path, *default_script_file; pa_log_target_t log_target; pa_log_level_t log_level; diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 30bf3ca1..6e55c0ee 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -46,6 +46,9 @@ ## Unload autoloaded modules after being idle for this time ; module-idle-time = 20 +## Unload autoloaded sample cache entries after being idle for this time +; 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. @@ -75,3 +78,6 @@ ## process per user, you better disable this option since it ## effectively disables multiple instances. ; use-pid-file = 1 + +## Run the daemon as system-wide instance, requires root priviliges +; system-instance = 0 diff --git a/src/daemon/main.c b/src/daemon/main.c index c41c69df..4961f0ca 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -37,6 +37,9 @@ #include #include #include +#include +#include + #include #ifdef HAVE_SYS_IOCTL_H @@ -149,6 +152,104 @@ static void close_pipe(int p[2]) { p[0] = p[1] = -1; } +#define set_env(key, value) putenv(pa_sprintf_malloc("%s=%s", (key), (value))) + +static int change_user(void) { + struct passwd *pw; + struct group * gr; + int r; + + if (!(pw = getpwnam(PA_SYSTEM_USER))) { + pa_log(__FILE__": 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); + return -1; + } + + pa_log_info(__FILE__": 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); + 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); + + 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)); + return -1; + } + + if (initgroups(PA_SYSTEM_USER, gr->gr_gid) != 0) { + pa_log(__FILE__": Failed to change group list: %s", pa_cstrerror(errno)); + return -1; + } + +#if defined(HAVE_SETRESGID) + r = setresgid(gr->gr_gid, gr->gr_gid, gr->gr_gid); +#elif defined(HAVE_SETEGID) + if ((r = setgid(gr->gr_gid)) >= 0) + r = setegid(gr->gr_gid); +#elif defined(HAVE_SETREGID) + r = setregid(gr->gr_gid, gr->gr_gid); +#else +#error "No API to drop priviliges" +#endif + + if (r < 0) { + pa_log(__FILE__": Failed to change GID: %s", pa_cstrerror(errno)); + return -1; + } + +#if defined(HAVE_SETRESUID) + r = setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid); +#elif defined(HAVE_SETEUID) + if ((r = setuid(pw->pw_uid)) >= 0) + r = seteuid(pw->pw_uid); +#elif defined(HAVE_SETREUID) + r = setreuid(pw->pw_uid, pw->pw_uid); +#else +#error "No API to drop priviliges" +#endif + + if (r < 0) { + pa_log(__FILE__": 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); + + /* Relevant for pa_runtime_path() */ + set_env("PULSE_RUNTIME_PATH", PA_SYSTEM_RUNTIME_PATH); + + pa_log_info(__FILE__": Successfully dropped root privileges."); + + return 0; +} + +static int create_runtime_dir(void) { + char fn[PATH_MAX]; + + pa_runtime_path(NULL, fn, sizeof(fn)); + + if (pa_make_secure_dir(fn, 0700, getuid(), getgid()) < 0) { + pa_log(__FILE__": Failed to create '%s': %s", fn, pa_cstrerror(errno)); + return -1; + } + + /* Relevant for pa_runtime_path() later on */ + set_env("PULSE_RUNTIME_PATH", fn); + return 0; +} + int main(int argc, char *argv[]) { pa_core *c; pa_strbuf *buf = NULL; @@ -172,13 +273,14 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); - pa_limit_caps(); + if (getuid() != 0) + pa_limit_caps(); #ifdef HAVE_GETUID suid_root = getuid() != 0 && geteuid() == 0; - if (suid_root && (pa_own_uid_in_group("realtime", &gid) <= 0 || gid >= 1000)) { - pa_log_warn(__FILE__": WARNING: called SUID root, but not in group 'realtime'."); + 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(); } #else @@ -220,7 +322,8 @@ int main(int argc, char *argv[]) { if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) pa_raise_priority(); - pa_drop_caps(); + if (getuid() != 0) + pa_drop_caps(); if (suid_root) pa_drop_root(); @@ -278,6 +381,14 @@ int main(int argc, char *argv[]) { assert(conf->cmd == PA_CMD_DAEMON); } + if (getuid() == 0 && !conf->system_instance) { + pa_log(__FILE__": This program is not intended to be run as root (unless --system is specified)."); + goto finish; + } else if (getuid() != 0 && conf->system_instance) { + pa_log(__FILE__": Root priviliges required."); + goto finish; + } + if (conf->daemonize) { pid_t child; int tty_fd; @@ -362,6 +473,13 @@ int main(int argc, char *argv[]) { } chdir("/"); + umask(0022); + + if (conf->system_instance) { + if (change_user() < 0) + goto finish; + } else if (create_runtime_dir() < 0) + goto finish; if (conf->use_pid_file) { if (pa_pid_file_create() < 0) { @@ -379,12 +497,13 @@ int main(int argc, char *argv[]) { #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif - + mainloop = pa_mainloop_new(); assert(mainloop); c = pa_core_new(pa_mainloop_get_api(mainloop)); assert(c); + c->is_system_instance = !!conf->system_instance; r = pa_signal_init(pa_mainloop_get_api(mainloop)); assert(r == 0); -- cgit From 2b31a900d67506592aecd9c0d59ad997d7977deb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jul 2006 18:11:12 +0000 Subject: update @@ tokens according to recent Makefile.am change git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1107 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon.conf.in | 4 ++-- src/daemon/esdcompat.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 6e55c0ee..30628969 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -52,11 +52,11 @@ ## 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 = @DLSEARCHPATH@ +; dl-search-path = @PA_DLSEARCHPATH@ ## The default script file to load. Specify an empty string for not ## loading a default script file. The -; default-script-file = @DEFAULT_CONFIG_FILE@ +; default-script-file = @PA_DEFAULT_CONFIG_FILE@ ## The default log target. Use either "stderr", "syslog" or ## "auto". The latter is equivalent to "sylog" in case daemonize is diff --git a/src/daemon/esdcompat.in b/src/daemon/esdcompat.in index edae8615..ece1f4f9 100755 --- a/src/daemon/esdcompat.in +++ b/src/daemon/esdcompat.in @@ -95,4 +95,4 @@ EOF shift done -eval "exec '@PULSEAUDIO_BINARY@'$ARGS" +eval "exec '@PA_BINARY@'$ARGS" -- cgit From 340803b30c154ead29795454416592ff9d0e0df2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jul 2006 18:14:14 +0000 Subject: use access group dedclared in ~/.pulse/client.conf instead of PA_ACCESS_GROUP git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1108 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index 6beeb90f..ac10c0ca 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -1,4 +1,4 @@ -#!@PULSEAUDIO_BINARY@ -nF +#!@PA_BINARY@ -nF # # This file is part of PulseAudio. -- cgit From a382492204ad3588c0c837e120e5bc31578df72a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jul 2006 21:48:35 +0000 Subject: * add new function pa_check_in_group() * abstract credential APis a little bit by introducing HAVE_CREDS and a structure pa_creds * rework credential authentication * fix module-volume-restore and friends for usage in system-wide instance * remove loopback= argument from moulde-*-protocol-tcp since it is a superset of listen= and usually a bad idea anyway since the user shouldn't load the TCP module at all if he doesn't want remote access * rename a few variables in the jack modules to make sure they don't conflict with symbols defined in the system headers * add server address for system-wide daemons to the default server list for the the client libs * update todo git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1109 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 4 ++-- src/daemon/main.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index a5a62567..2577578c 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -46,9 +46,9 @@ #endif #define DEFAULT_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PATH_SEP "default.pa" -#define DEFAULT_SCRIPT_FILE_USER ".pulse" 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 ".pulse" PATH_SEP "daemon.conf" +#define DEFAULT_CONFIG_FILE_USER PATH_SEP "daemon.conf" #define ENV_SCRIPT_FILE "PULSE_SCRIPT" #define ENV_CONFIG_FILE "PULSE_CONFIG" diff --git a/src/daemon/main.c b/src/daemon/main.c index 4961f0ca..0449cb94 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -229,6 +229,7 @@ static int change_user(void) { /* Relevant for pa_runtime_path() */ set_env("PULSE_RUNTIME_PATH", PA_SYSTEM_RUNTIME_PATH); + set_env("PULSE_CONFIG_PATH", PA_SYSTEM_RUNTIME_PATH); pa_log_info(__FILE__": Successfully dropped root privileges."); @@ -245,8 +246,6 @@ static int create_runtime_dir(void) { return -1; } - /* Relevant for pa_runtime_path() later on */ - set_env("PULSE_RUNTIME_PATH", fn); return 0; } -- cgit From 703bb49c91a53d03ec55a704d895f59bfbafd8b0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jul 2006 23:16:02 +0000 Subject: add a few comments git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1110 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 0449cb94..cf655ee0 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -158,6 +158,10 @@ static int change_user(void) { struct passwd *pw; struct group * gr; int r; + + /* 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); @@ -238,8 +242,12 @@ static int change_user(void) { 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, getuid(), getgid()) < 0) { pa_log(__FILE__": Failed to create '%s': %s", fn, pa_cstrerror(errno)); -- cgit From a3e7595ac179ca32bc5c876b25a4e80171c3d917 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 00:21:50 +0000 Subject: Make -1 mean "current group/user" so that some platform dependent calls can be centralised. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1113 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index cf655ee0..948b2055 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -249,7 +249,7 @@ static int create_runtime_dir(void) { * per-user mode. We create the runtime directory somewhere in * /tmp/ with the current UID/GID */ - if (pa_make_secure_dir(fn, 0700, getuid(), getgid()) < 0) { + 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; } -- cgit From 246e30aec74c76fd7db53f4c537a4c90b87d5ea4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 00:28:18 +0000 Subject: Add missing header. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1114 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 948b2055..63452f6f 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -55,6 +55,7 @@ #include #include +#include #include #include -- cgit From 2409f1a80b708ead6c48ebbb568bd2b7d6d3af31 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 20 Jul 2006 01:25:37 +0000 Subject: add support to set resource limits for the daemon and set some of them to some sane values git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1116 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++ src/daemon/daemon-conf.h | 22 +++++++++++++ src/daemon/daemon.conf.in | 10 ++++++ src/daemon/main.c | 37 ++++++++++++++++++++- 4 files changed, 152 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 2577578c..12ee0800 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -73,6 +73,20 @@ static const pa_daemon_conf default_conf = { .config_file = NULL, .use_pid_file = 1, .system_instance = 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 } +#ifdef RLIMIT_NPROC + , .rlimit_nproc = { .value = 0, .is_set = 0 } +#endif +#ifdef RLIMIT_MEMLOCK + , .rlimit_memlock = { .value = 0, .is_set = 1 } +#endif +#endif }; pa_daemon_conf* pa_daemon_conf_new(void) { @@ -184,6 +198,30 @@ static int parse_resample_method(const char *filename, unsigned line, const char return 0; } +static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) { + pa_rlimit *r = data; + assert(filename); + assert(lvalue); + assert(rvalue); + assert(r); + + if (rvalue[strspn(rvalue, "\t ")] == 0) { + /* Empty string */ + r->is_set = 0; + r->value = 0; + } else { + int32_t k; + if (pa_atoi(rvalue, &k) < 0) { + pa_log(__FILE__": [%s:%u] Inavalid rlimit '%s'.", filename, line, rvalue); + return -1; + } + r->is_set = k >= 0; + r->value = k >= 0 ? (rlim_t) k : 0; + } + + return 0; +} + int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { int r = -1; FILE *f = NULL; @@ -204,6 +242,20 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "resample-method", parse_resample_method, NULL }, { "use-pid-file", pa_config_parse_bool, NULL }, { "system-instance", pa_config_parse_bool, 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 }, +#endif +#ifdef RLIMIT_MEMLOCK + { "rlimit-memlock", parse_rlimit, NULL }, +#endif +#endif { NULL, NULL, NULL }, }; @@ -222,6 +274,24 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { 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; +#endif +#ifdef RLIMIT_MEMLOCK +#ifndef RLIMIT_NPROC +#error "Houston, we have a numbering problem!" +#endif + table[22].data = &c->rlimit_memlock; +#endif +#endif + pa_xfree(c->config_file); c->config_file = NULL; @@ -289,6 +359,20 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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); +#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-stack = %li\n", c->rlimit_stack.is_set ? (long int) c->rlimit_stack.value : -1); +#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_MEMLOCK + pa_strbuf_printf(s, "rlimit-memlock = %li\n", c->rlimit_memlock.is_set ? (long int) c->rlimit_memlock.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 bfea7358..a09773f1 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -24,6 +24,10 @@ #include +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + /* The actual command to execute */ typedef enum pa_daemon_conf_cmd { PA_CMD_DAEMON, /* the default */ @@ -35,6 +39,13 @@ typedef enum pa_daemon_conf_cmd { PA_CMD_CHECK } pa_daemon_conf_cmd_t; +#ifdef HAVE_SYS_RESOURCE_H +typedef struct pa_rlimit { + rlim_t value; + int 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; @@ -53,6 +64,17 @@ typedef struct pa_daemon_conf { pa_log_level_t log_level; int resample_method; char *config_file; + +#ifdef HAVE_SYS_RESOURCE_H + pa_rlimit rlimit_as, rlimit_core, rlimit_data, rlimit_fsize, rlimit_nofile, rlimit_stack; +#ifdef RLIMIT_NPROC + pa_rlimit rlimit_nproc; +#endif +#ifdef RLIMIT_MEMLOCK + pa_rlimit rlimit_memlock; +#endif +#endif + } pa_daemon_conf; /* Allocate a new structure and fill it with sane defaults */ diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 30628969..787405f8 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -81,3 +81,13 @@ ## Run the daemon as system-wide instance, requires root priviliges ; system-instance = 0 + +## Resource limits, see getrlimit(2) for more information +; rlimit-as = -1 +; rlimit-core = -1 +; rlimit-data = -1 +; rlimit-fsize = -1 +; rlimit-nofile = 25 +; rlimit-stack = -1 +; rlimit-nproc = -1 +; rlimit-memlock = 25 diff --git a/src/daemon/main.c b/src/daemon/main.c index 63452f6f..517d9984 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -258,6 +258,37 @@ static int create_runtime_dir(void) { return 0; } +#ifdef HAVE_SYS_RESOURCE_H + +static void set_one_rlimit(const pa_rlimit *r, int resource, const char *name) { + struct rlimit rl; + assert(r); + + if (!r->is_set) + return; + + 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)); +} + +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_stack, RLIMIT_STACK, "RLIMIT_STACK"); +#ifdef RLIMIT_NPROC + set_one_rlimit(&conf->rlimit_nproc, RLIMIT_NPROC, "RLIMIT_NPROC"); +#endif +#ifdef RLIMIT_MEMLOCK + set_one_rlimit(&conf->rlimit_memlock, RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK"); +#endif +} +#endif + int main(int argc, char *argv[]) { pa_core *c; pa_strbuf *buf = NULL; @@ -335,7 +366,7 @@ int main(int argc, char *argv[]) { if (suid_root) pa_drop_root(); - + if (conf->dl_search_path) lt_dlsetsearchpath(conf->dl_search_path); @@ -502,6 +533,10 @@ int main(int argc, char *argv[]) { valid_pid_file = 1; } +#ifdef HAVE_SYS_RESOURCE_H + set_all_rlimits(conf); +#endif + #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif -- cgit From b12f29d04ba9fcaa6930d52b13880086693c0faa Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 13:07:01 +0000 Subject: Make sure parse_rlimit is only used when rlimits are supported. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1117 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 12ee0800..7184b2e6 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -199,7 +199,8 @@ static int parse_resample_method(const char *filename, unsigned line, const char } static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) { - pa_rlimit *r = data; +#ifdef HAVE_SYS_RESOURCE_H + struct pa_rlimit *r = data; assert(filename); assert(lvalue); assert(rvalue); @@ -218,6 +219,9 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, r->is_set = k >= 0; r->value = k >= 0 ? (rlim_t) k : 0; } +#else + pa_log_warning(__FILE__": [%s:%u] rlimit not supported on this platform.", filename, line); +#endif return 0; } -- cgit From 8d2dc9c4d14fd879aac3e4137b1dfc2c32a338cb Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 13:16:23 +0000 Subject: Handle user switch in a more platform independent manner. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1118 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 517d9984..8b905b31 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -37,8 +37,6 @@ #include #include #include -#include -#include #include @@ -46,6 +44,13 @@ #include #endif +#ifdef HAVE_PWD_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif + #ifdef HAVE_LIBWRAP #include #include @@ -155,6 +160,8 @@ static void close_pipe(int p[2]) { #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) { struct passwd *pw; struct group * gr; @@ -241,6 +248,15 @@ static int change_user(void) { return 0; } +#else /* HAVE_PWD_H && HAVE_GRP_H */ + +static int change_user(void) { + pa_log(__FILE__": 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]; -- cgit From 57d8a315ea3c3e4e19e19fe1d293ca941d6229d5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 13:19:16 +0000 Subject: Move check for SUID into the caps functions. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1119 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 9 +++++++++ src/daemon/main.c | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index dc74bc7d..957824d9 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef HAVE_SYS_CAPABILITY_H #include @@ -80,6 +81,10 @@ int pa_limit_caps(void) { 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); @@ -106,6 +111,10 @@ 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); diff --git a/src/daemon/main.c b/src/daemon/main.c index 8b905b31..3f489981 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -328,8 +328,7 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); - if (getuid() != 0) - pa_limit_caps(); + pa_limit_caps(); #ifdef HAVE_GETUID suid_root = getuid() != 0 && geteuid() == 0; @@ -377,8 +376,7 @@ int main(int argc, char *argv[]) { if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) pa_raise_priority(); - if (getuid() != 0) - pa_drop_caps(); + pa_drop_caps(); if (suid_root) pa_drop_root(); -- cgit From f3d49244731498c009b5c1991cb7242a8e9914ae Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 13:24:04 +0000 Subject: Centralise check if we're running as root. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1120 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 3f489981..14c16ab2 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -314,7 +314,7 @@ int main(int argc, char *argv[]) { char *s; int r, retval = 1, d = 0; int daemon_pipe[2] = { -1, -1 }; - int suid_root; + int suid_root, real_root; int valid_pid_file = 0; #ifdef HAVE_GETUID @@ -331,13 +331,15 @@ int main(int argc, char *argv[]) { pa_limit_caps(); #ifdef HAVE_GETUID - suid_root = getuid() != 0 && geteuid() == 0; + 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(); } #else + real_root = 0; suid_root = 0; #endif @@ -434,10 +436,10 @@ int main(int argc, char *argv[]) { assert(conf->cmd == PA_CMD_DAEMON); } - if (getuid() == 0 && !conf->system_instance) { + if (real_root && !conf->system_instance) { pa_log(__FILE__": This program is not intended to be run as root (unless --system is specified)."); goto finish; - } else if (getuid() != 0 && conf->system_instance) { + } else if (!real_root && conf->system_instance) { pa_log(__FILE__": Root priviliges required."); goto finish; } -- cgit From 0762af2aeed6f590bf5833128185adf902eac0cf Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 13:24:57 +0000 Subject: Only warn when running as root and not --system. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1121 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 14c16ab2..d578f508 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -437,8 +437,7 @@ int main(int argc, char *argv[]) { } if (real_root && !conf->system_instance) { - pa_log(__FILE__": This program is not intended to be run as root (unless --system is specified)."); - goto finish; + pa_log_warning(__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."); goto finish; -- cgit From 4a59581a4c95c94d97abc7844a097a356c937f0e Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 13:28:50 +0000 Subject: Fix incorrect call to nonexistant pa_log_warning(). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1122 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 2 +- src/daemon/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 7184b2e6..894c0434 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -220,7 +220,7 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, r->value = k >= 0 ? (rlim_t) k : 0; } #else - pa_log_warning(__FILE__": [%s:%u] rlimit not supported on this platform.", filename, line); + pa_log_warn(__FILE__": [%s:%u] rlimit not supported on this platform.", filename, line); #endif return 0; diff --git a/src/daemon/main.c b/src/daemon/main.c index d578f508..3ced3bf6 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -437,7 +437,7 @@ int main(int argc, char *argv[]) { } if (real_root && !conf->system_instance) { - pa_log_warning(__FILE__": This program is not intended to be run as root (unless --system is specified)."); + 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."); goto finish; -- cgit From a84a2f91384060720dc1e1a97963faadc526c299 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 21 Jul 2006 19:59:52 +0000 Subject: raise the default value for RLIMIT_NOFILE to 200 since 25 is apparently too small if every single GNOME apps thinks it needs to create its own server connection! git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1136 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 2 +- src/daemon/daemon.conf.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 894c0434..0426989c 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -78,7 +78,7 @@ static const pa_daemon_conf default_conf = { .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_nofile = { .value = 200, .is_set = 1 }, .rlimit_stack = { .value = 0, .is_set = 0 } #ifdef RLIMIT_NPROC , .rlimit_nproc = { .value = 0, .is_set = 0 } diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 787405f8..696b25a9 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -87,7 +87,7 @@ ; rlimit-core = -1 ; rlimit-data = -1 ; rlimit-fsize = -1 -; rlimit-nofile = 25 +; rlimit-nofile = 200 ; rlimit-stack = -1 ; rlimit-nproc = -1 ; rlimit-memlock = 25 -- cgit From 61ce8bb0024764fa059aa5f5f1f5c2a0189c40bc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 25 Jul 2006 20:51:15 +0000 Subject: add new command line option --no-cpu-limit. This is useful when running PulseAudio in valgrind's massif or callgrind tools git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1149 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 14 +++++++++++++- src/daemon/daemon-conf.c | 22 +++++++++++++--------- src/daemon/daemon-conf.h | 3 ++- src/daemon/daemon.conf.in | 5 +++++ src/daemon/main.c | 14 +++++++++----- 5 files changed, 42 insertions(+), 16 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index ab876edf..e00f290e 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -59,6 +59,7 @@ enum { ARG_KILL, ARG_USE_PID_FILE, ARG_CHECK, + ARG_NO_CPU_LIMIT, ARG_SYSTEM }; @@ -86,6 +87,7 @@ static struct option long_options[] = { {"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}, {NULL, 0, 0, 0} }; @@ -128,7 +130,9 @@ void pa_cmdline_help(const char *argv0) { " (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" + " --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\n" "STARTUP SCRIPT:\n" " -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with\n" @@ -286,6 +290,14 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d goto fail; } break; + + case ARG_NO_CPU_LIMIT: + if ((conf->no_cpu_limit = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + pa_log(__FILE__": --no-cpu-limit expects boolean argument"); + goto fail; + } + break; + default: goto fail; diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 0426989c..3e585d90 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -72,7 +72,8 @@ static const pa_daemon_conf default_conf = { .resample_method = PA_RESAMPLER_SRC_SINC_FASTEST, .config_file = NULL, .use_pid_file = 1, - .system_instance = 0 + .system_instance = 0, + .no_cpu_limit = 0 #ifdef HAVE_SYS_RESOURCE_H , .rlimit_as = { .value = 0, .is_set = 0 }, .rlimit_core = { .value = 0, .is_set = 0 }, @@ -246,6 +247,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "resample-method", parse_resample_method, NULL }, { "use-pid-file", pa_config_parse_bool, NULL }, { "system-instance", pa_config_parse_bool, NULL }, + { "no-cpu-limit", pa_config_parse_bool, NULL }, #ifdef HAVE_SYS_RESOURCE_H { "rlimit-as", parse_rlimit, NULL }, { "rlimit-core", parse_rlimit, NULL }, @@ -278,21 +280,22 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { table[12].data = c; table[13].data = &c->use_pid_file; table[14].data = &c->system_instance; + table[15].data = &c->no_cpu_limit; #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; + table[16].data = &c->rlimit_as; + table[17].data = &c->rlimit_core; + table[18].data = &c->rlimit_data; + table[19].data = &c->rlimit_fsize; + table[20].data = &c->rlimit_nofile; + table[21].data = &c->rlimit_stack; #ifdef RLIMIT_NPROC - table[21].data = &c->rlimit_nproc; + table[22].data = &c->rlimit_nproc; #endif #ifdef RLIMIT_MEMLOCK #ifndef RLIMIT_NPROC #error "Houston, we have a numbering problem!" #endif - table[22].data = &c->rlimit_memlock; + table[23].data = &c->rlimit_memlock; #endif #endif @@ -363,6 +366,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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, "no-cpu-limit = %i\n", !!c->no_cpu_limit); #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); diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index a09773f1..84208336 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -58,7 +58,8 @@ typedef struct pa_daemon_conf { scache_idle_time, auto_log_target, use_pid_file, - system_instance; + system_instance, + no_cpu_limit; char *script_commands, *dl_search_path, *default_script_file; pa_log_target_t log_target; pa_log_level_t log_level; diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 696b25a9..0204b9e3 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -79,6 +79,11 @@ ## effectively disables multiple instances. ; use-pid-file = 1 +## Do not install the CPU load limit, even on platforms where it is +## supported. This option is useful when debugging/profiling +## PulseAudio to disable disturbing SIGXCPU signals. +; no-cpu-limit = 0 + ## Run the daemon as system-wide instance, requires root priviliges ; system-instance = 0 diff --git a/src/daemon/main.c b/src/daemon/main.c index 3ced3bf6..38d465f8 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -588,10 +588,12 @@ int main(int argc, char *argv[]) { c->running_as_daemon = 1; oil_init(); - - r = pa_cpu_limit_init(pa_mainloop_get_api(mainloop)); - assert(r == 0); - + + if (!conf->no_cpu_limit) { + 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); @@ -645,7 +647,9 @@ int main(int argc, char *argv[]) { pa_core_free(c); - pa_cpu_limit_done(); + if (!conf->no_cpu_limit) + pa_cpu_limit_done(); + pa_signal_done(); pa_mainloop_free(mainloop); -- cgit From c21f88cb9020caca5a45a6c899d9d0a66b0d3200 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 27 Jul 2006 18:35:17 +0000 Subject: load module-gconf in default install git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1159 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index ac10c0ca..ef6048d6 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -39,9 +39,11 @@ load-module module-detect ### Load several protocols load-module module-esound-protocol-unix -#load-module module-esound-protocol-tcp load-module module-native-protocol-unix + +#load-module module-esound-protocol-tcp #load-module module-native-protocol-tcp +#load-module module-zeroconf-publish ### Load the RTP reciever module #load-module module-rtp-recv @@ -69,3 +71,7 @@ load-module module-x11-bell sample=x11-bell ### Publish connection data in the X11 root window load-module module-x11-publish +### 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. +load-module module-gconf -- cgit From a7cf5e0f2de5474b4a1131a4254a56229436b7f7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 29 Jul 2006 15:34:36 +0000 Subject: fix two typos (pierre, have you been sleeping? next time please the comments wrong but the code right, not the other way round! ;-)) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1170 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 957824d9..8ae43fb2 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -82,7 +82,7 @@ int pa_limit_caps(void) { cap_value_t nice_cap = CAP_SYS_NICE; /* Only drop caps when called SUID */ - if (getuid() != 0) + if (getuid() == 0) return 0; caps = cap_init(); @@ -112,7 +112,7 @@ int pa_drop_caps(void) { int r = -1; /* Only drop caps when called SUID */ - if (getuid() != 0) + if (getuid() == 0) return 0; caps = cap_init(); -- cgit From a7b9a7d599d461b36d225849bdbf2d5c6ad73008 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 13 Aug 2006 17:35:46 +0000 Subject: Load module-rescue-streams by default git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1245 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index ef6048d6..74148cd1 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -55,6 +55,9 @@ load-module module-native-protocol-unix ### Automatically restore the volume of playback streams load-module module-volume-restore +### Automatically move streams to the default sink if the sink they are connected to dies +load-module module-rescue-streams + ### Make some devices default #set-default-sink output #set-default-source input -- cgit From 0e436a6926af56f37a74a03bb5e143e078ca0d55 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 19:55:18 +0000 Subject: Rework memory management to allow shared memory data transfer. The central idea is to allocate all audio memory blocks from a per-process memory pool which is available as read-only SHM segment to other local processes. Then, instead of writing the actual audio data to the socket just write references to this shared memory pool. To work optimally all memory blocks should now be of type PA_MEMBLOCK_POOL or PA_MEMBLOCK_POOL_EXTERNAL. The function pa_memblock_new() now generates memory blocks of this type by default. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1266 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 38d465f8..aada0ad7 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -559,7 +559,7 @@ int main(int argc, char *argv[]) { mainloop = pa_mainloop_new(); assert(mainloop); - c = pa_core_new(pa_mainloop_get_api(mainloop)); + c = pa_core_new(pa_mainloop_get_api(mainloop), 1); assert(c); c->is_system_instance = !!conf->system_instance; -- cgit From e385d93e5aad6a6fce754c00c804ff1d6a6746d4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 21:38:40 +0000 Subject: remove all occurences of pa_logXXX(__FILE__": and replace them by pa_logXXX(" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1272 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 6 ++--- src/daemon/cmdline.c | 20 +++++++------- src/daemon/cpulimit.c | 2 +- src/daemon/daemon-conf.c | 12 ++++----- src/daemon/main.c | 68 ++++++++++++++++++++++++------------------------ 5 files changed, 54 insertions(+), 54 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 8ae43fb2..cebdaebc 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -54,7 +54,7 @@ void pa_drop_root(void) { if (uid == 0 || geteuid() != 0) return; - pa_log_info(__FILE__": dropping root rights."); + pa_log_info("dropping root rights."); #if defined(HAVE_SETRESUID) setresuid(uid, uid, uid); @@ -96,7 +96,7 @@ int pa_limit_caps(void) { if (cap_set_proc(caps) < 0) goto fail; - pa_log_info(__FILE__": dropped capabilities successfully."); + pa_log_info("dropped capabilities successfully."); r = 0; @@ -121,7 +121,7 @@ int pa_drop_caps(void) { cap_clear(caps); if (cap_set_proc(caps) < 0) { - pa_log(__FILE__": failed to drop capabilities: %s", pa_cstrerror(errno)); + pa_log("failed to drop capabilities: %s", pa_cstrerror(errno)); goto fail; } diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index e00f290e..d3fe8e65 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -199,14 +199,14 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d case ARG_DAEMONIZE: case 'D': if ((conf->daemonize = optarg ? pa_parse_boolean(optarg) : 1) < 0) { - pa_log(__FILE__": --daemonize expects boolean argument"); + 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"); + pa_log("--fail expects boolean argument"); goto fail; } break; @@ -216,7 +216,7 @@ 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 { @@ -228,21 +228,21 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d case ARG_HIGH_PRIORITY: if ((conf->high_priority = optarg ? pa_parse_boolean(optarg) : 1) < 0) { - pa_log(__FILE__": --high-priority expects boolean argument"); + pa_log("--high-priority 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"); + pa_log("--disallow-module-loading 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"); + pa_log("--use-pid-file expects boolean argument"); goto fail; } break; @@ -260,7 +260,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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'."); goto fail; } break; @@ -279,21 +279,21 @@ 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"); + pa_log("--system expects boolean argument"); goto fail; } break; case ARG_NO_CPU_LIMIT: if ((conf->no_cpu_limit = optarg ? pa_parse_boolean(optarg) : 1) < 0) { - pa_log(__FILE__": --no-cpu-limit expects boolean argument"); + pa_log("--no-cpu-limit expects boolean argument"); goto fail; } break; diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index b8740ea0..d7466b06 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -172,7 +172,7 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { /* Prepare the main loop pipe */ if (pipe(the_pipe) < 0) { - pa_log(__FILE__": pipe() failed: %s", pa_cstrerror(errno)); + pa_log("pipe() failed: %s", pa_cstrerror(errno)); return -1; } diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 3e585d90..2cb06697 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -168,7 +168,7 @@ static int parse_log_target(const char *filename, unsigned line, const char *lva assert(filename && lvalue && rvalue && 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; } @@ -180,7 +180,7 @@ static int parse_log_level(const char *filename, unsigned line, const char *lval assert(filename && lvalue && rvalue && 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; } @@ -192,7 +192,7 @@ static int parse_resample_method(const char *filename, unsigned line, const char assert(filename && lvalue && rvalue && 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] Inavalid resample method '%s'.", filename, line, rvalue); return -1; } @@ -214,14 +214,14 @@ 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] Inavalid 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); + pa_log_warn("[%s:%u] rlimit not supported on this platform.", filename, line); #endif return 0; @@ -308,7 +308,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file, "r"); if (!f && errno != ENOENT) { - pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", c->config_file, pa_cstrerror(errno)); + pa_log("WARNING: failed to open configuration file '%s': %s", c->config_file, pa_cstrerror(errno)); goto finish; } diff --git a/src/daemon/main.c b/src/daemon/main.c index aada0ad7..95ba6dd5 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -117,7 +117,7 @@ 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)); + pa_log_info("Got signal %s.", pa_strsignal(sig)); switch (sig) { #ifdef SIGUSR1 @@ -144,7 +144,7 @@ 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; } @@ -172,34 +172,34 @@ static int change_user(void) { * 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("Warning: 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 (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; } @@ -215,7 +215,7 @@ static int change_user(void) { #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; } @@ -231,7 +231,7 @@ static int change_user(void) { #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; } @@ -243,7 +243,7 @@ static int change_user(void) { set_env("PULSE_RUNTIME_PATH", PA_SYSTEM_RUNTIME_PATH); set_env("PULSE_CONFIG_PATH", PA_SYSTEM_RUNTIME_PATH); - pa_log_info(__FILE__": Successfully dropped root privileges."); + pa_log_info("Successfully dropped root privileges."); return 0; } @@ -251,7 +251,7 @@ 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; } @@ -267,7 +267,7 @@ static int create_runtime_dir(void) { * /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)); + pa_log("Failed to create '%s': %s", fn, pa_cstrerror(errno)); return -1; } @@ -286,7 +286,7 @@ static void set_one_rlimit(const pa_rlimit *r, int resource, const char *name) { 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)); + pa_log_warn("setrlimit(%s, (%u, %u)) failed: %s", name, (unsigned) r->value, (unsigned) r->value, pa_cstrerror(errno)); } static void set_all_rlimits(const pa_daemon_conf *conf) { @@ -335,7 +335,7 @@ int main(int argc, char *argv[]) { 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_log_warn("WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'."); pa_drop_root(); } #else @@ -368,7 +368,7 @@ 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; } @@ -414,9 +414,9 @@ int main(int argc, char *argv[]) { pid_t pid; if (pa_pid_file_check_running(&pid) < 0) { - pa_log_info(__FILE__": daemon not running"); + pa_log_info("daemon not running"); } else { - pa_log_info(__FILE__": daemon running as PID %u", pid); + pa_log_info("daemon running as PID %u", pid); retval = 0; } @@ -426,7 +426,7 @@ 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."); + pa_log("failed to kill daemon."); else retval = 0; @@ -437,9 +437,9 @@ int main(int argc, char *argv[]) { } if (real_root && !conf->system_instance) { - pa_log_warn(__FILE__": This program is not intended to be run as root (unless --system is specified)."); + pa_log_warn("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."); + pa_log("Root priviliges required."); goto finish; } @@ -448,18 +448,18 @@ int main(int argc, char *argv[]) { int tty_fd; 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("failed to create pipe."); goto finish; } if ((child = fork()) < 0) { - pa_log(__FILE__": fork() failed: %s", pa_cstrerror(errno)); + pa_log("fork() failed: %s", pa_cstrerror(errno)); goto finish; } @@ -470,14 +470,14 @@ int main(int argc, char *argv[]) { 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)); + 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; } @@ -537,7 +537,7 @@ int main(int argc, char *argv[]) { if (conf->use_pid_file) { if (pa_pid_file_create() < 0) { - pa_log(__FILE__": pa_pid_file_create() failed."); + pa_log("pa_pid_file_create() failed."); #ifdef HAVE_FORK if (conf->daemonize) pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL); @@ -604,13 +604,13 @@ int main(int argc, char *argv[]) { pa_xfree(s); if (r < 0 && conf->fail) { - pa_log(__FILE__": failed to initialize daemon."); + pa_log("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."); + pa_log("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); @@ -634,10 +634,10 @@ int main(int argc, char *argv[]) { 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."); + pa_log_info("Daemon startup complete."); if (pa_mainloop_run(mainloop, &retval) < 0) retval = 1; - pa_log_info(__FILE__": Daemon shutdown initiated."); + pa_log_info("Daemon shutdown initiated."); } } @@ -653,7 +653,7 @@ int main(int argc, char *argv[]) { pa_signal_done(); pa_mainloop_free(mainloop); - pa_log_info(__FILE__": Daemon terminated."); + pa_log_info("Daemon terminated."); finish: -- cgit From dbc658df4129eec260619f3fd31680ad7977f46c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 19 Aug 2006 01:20:13 +0000 Subject: add new "disable-shm" server config option git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1286 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 22 +++++++++++++--------- src/daemon/daemon-conf.h | 3 ++- src/daemon/main.c | 15 +++++++++------ 3 files changed, 24 insertions(+), 16 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 2cb06697..dd478126 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -73,7 +73,8 @@ static const pa_daemon_conf default_conf = { .config_file = NULL, .use_pid_file = 1, .system_instance = 0, - .no_cpu_limit = 0 + .no_cpu_limit = 0, + .disable_shm = 0 #ifdef HAVE_SYS_RESOURCE_H , .rlimit_as = { .value = 0, .is_set = 0 }, .rlimit_core = { .value = 0, .is_set = 0 }, @@ -248,6 +249,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "use-pid-file", pa_config_parse_bool, NULL }, { "system-instance", pa_config_parse_bool, NULL }, { "no-cpu-limit", pa_config_parse_bool, NULL }, + { "disable-shm", pa_config_parse_bool, NULL }, #ifdef HAVE_SYS_RESOURCE_H { "rlimit-as", parse_rlimit, NULL }, { "rlimit-core", parse_rlimit, NULL }, @@ -281,21 +283,22 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { table[13].data = &c->use_pid_file; table[14].data = &c->system_instance; table[15].data = &c->no_cpu_limit; + table[16].data = &c->disable_shm; #ifdef HAVE_SYS_RESOURCE_H - table[16].data = &c->rlimit_as; - table[17].data = &c->rlimit_core; - table[18].data = &c->rlimit_data; - table[19].data = &c->rlimit_fsize; - table[20].data = &c->rlimit_nofile; - table[21].data = &c->rlimit_stack; + table[17].data = &c->rlimit_as; + table[18].data = &c->rlimit_core; + table[19].data = &c->rlimit_data; + table[20].data = &c->rlimit_fsize; + table[21].data = &c->rlimit_nofile; + table[22].data = &c->rlimit_stack; #ifdef RLIMIT_NPROC - table[22].data = &c->rlimit_nproc; + table[23].data = &c->rlimit_nproc; #endif #ifdef RLIMIT_MEMLOCK #ifndef RLIMIT_NPROC #error "Houston, we have a numbering problem!" #endif - table[23].data = &c->rlimit_memlock; + table[24].data = &c->rlimit_memlock; #endif #endif @@ -367,6 +370,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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, "no-cpu-limit = %i\n", !!c->no_cpu_limit); + pa_strbuf_printf(s, "disable_shm = %i\n", !!c->disable_shm); #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); diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index 84208336..b4b833ad 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -59,7 +59,8 @@ typedef struct pa_daemon_conf { auto_log_target, use_pid_file, system_instance, - no_cpu_limit; + no_cpu_limit, + disable_shm; char *script_commands, *dl_search_path, *default_script_file; pa_log_target_t log_target; pa_log_level_t log_level; diff --git a/src/daemon/main.c b/src/daemon/main.c index 95ba6dd5..8b816b9a 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -306,10 +306,10 @@ static void set_all_rlimits(const pa_daemon_conf *conf) { #endif int main(int argc, char *argv[]) { - pa_core *c; + pa_core *c = NULL; pa_strbuf *buf = NULL; - pa_daemon_conf *conf; - pa_mainloop *mainloop; + pa_daemon_conf *conf = NULL; + pa_mainloop *mainloop = NULL; char *s; int r, retval = 1, d = 0; @@ -559,8 +559,9 @@ int main(int argc, char *argv[]) { mainloop = pa_mainloop_new(); assert(mainloop); - c = pa_core_new(pa_mainloop_get_api(mainloop), 1); - assert(c); + if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm))) + goto finish; + c->is_system_instance = !!conf->system_instance; r = pa_signal_init(pa_mainloop_get_api(mainloop)); @@ -651,12 +652,14 @@ int main(int argc, char *argv[]) { pa_cpu_limit_done(); pa_signal_done(); - pa_mainloop_free(mainloop); pa_log_info("Daemon terminated."); finish: + if (mainloop) + pa_mainloop_free(mainloop); + if (conf) pa_daemon_conf_free(conf); -- cgit From a8519d56677f79e9ef6ee65439531a8d6b955d43 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 19 Aug 2006 01:20:40 +0000 Subject: add "disable-shm=" to default daemon configuration file git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1287 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon.conf.in | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 0204b9e3..29b22a42 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -96,3 +96,6 @@ ; rlimit-stack = -1 ; rlimit-nproc = -1 ; rlimit-memlock = 25 + +## Disable shared memory data transfer +; disable-shm = 0 -- cgit From 47c7a14b828a35ade80b49ec6bed75b2801af7bb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 19 Aug 2006 01:21:22 +0000 Subject: add --disable-shm command line option to the daemon git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1288 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index d3fe8e65..d368b644 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -60,6 +60,7 @@ enum { ARG_USE_PID_FILE, ARG_CHECK, ARG_NO_CPU_LIMIT, + ARG_DISABLE_SHM, ARG_SYSTEM }; @@ -88,6 +89,7 @@ static struct option long_options[] = { {"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}, {NULL, 0, 0, 0} }; @@ -132,7 +134,8 @@ void pa_cmdline_help(const char *argv0) { " src-zero-order-hold,src-linear,trivial)\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\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" @@ -297,7 +300,13 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d goto fail; } break; - + + case ARG_DISABLE_SHM: + if ((conf->disable_shm = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + pa_log("--disable-shm expects boolean argument"); + goto fail; + } + break; default: goto fail; -- cgit From 26bfce6281f475d04f122dee6a711c7c00496614 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 22 Aug 2006 12:46:05 +0000 Subject: Improve error messages a bit. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1320 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 8b816b9a..5d77282c 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -559,8 +559,10 @@ int main(int argc, char *argv[]) { mainloop = pa_mainloop_new(); assert(mainloop); - if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm))) + if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm))) { + pa_log("pa_core_new() failed."); goto finish; + } c->is_system_instance = !!conf->system_instance; -- cgit From 8ead68fcb3fb7da981a42f4b502bdeabf96a62fb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 25 Aug 2006 12:12:13 +0000 Subject: activate HAL in the default config git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1331 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index 74148cd1..03122669 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -27,7 +27,11 @@ #load-module module-pipe-sink ### Automatically load driver modules depending on the hardware available -load-module module-detect +load-module module-hal-detect + +### Alternatively use the static hardware detection module (for systems that +### lack HAL support +#load-module module-detect ### Load audio drivers automatically on access #add-autoload-sink output module-oss device="/dev/dsp" sink_name=output source_name=input @@ -41,21 +45,24 @@ load-module module-detect load-module module-esound-protocol-unix load-module module-native-protocol-unix +### 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 #load-module module-zeroconf-publish -### Load the RTP reciever module +### Load the RTP reciever 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 -### Automatically move streams to the default sink if the sink they are connected to dies +### Automatically move streams to the default sink if the sink they are +### connected to dies, similar for sources load-module module-rescue-streams ### Make some devices default -- cgit From 11b6c451b88099d2094183de5f4237ec578f4cfe Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 2 Sep 2006 12:28:40 +0000 Subject: fix esdcompat for non-gnu systems git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1361 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/esdcompat.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/esdcompat.in b/src/daemon/esdcompat.in index ece1f4f9..942389d2 100755 --- a/src/daemon/esdcompat.in +++ b/src/daemon/esdcompat.in @@ -28,7 +28,7 @@ fail() { ARGS=" --log-target=syslog" -for N in $(seq $#) ; do +while [ "$#" -gt "0" ]; do case "$1" in "") -- cgit From 40f18d97f6e84e56e8792212f6078519609dec47 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Sep 2006 13:29:59 +0000 Subject: fix alsa-sink example git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1377 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index 03122669..a495f890 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -20,7 +20,7 @@ ### Load audio drivers statically #load-module module-alsa-sink -#load-module module-alsa-source device=plughw:1,0 +#load-module module-alsa-source device=hw:1,0 #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 #load-module module-null-sink -- cgit From f1021b9e0ba9727ff08009295dea28cc247b9d4f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 20 Sep 2006 19:02:45 +0000 Subject: enable module-hal-detect in the default configuration file only if HAL support is enabled (closes #30) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1401 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/default.pa.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index a495f890..af2a6789 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -27,11 +27,11 @@ #load-module module-pipe-sink ### Automatically load driver modules depending on the hardware available -load-module module-hal-detect +@HAVE_HAL_TRUE@load-module module-hal-detect ### Alternatively use the static hardware detection module (for systems that ### lack HAL support -#load-module module-detect +@HAVE_HAL_FALSE@load-module module-detect ### Load audio drivers automatically on access #add-autoload-sink output module-oss device="/dev/dsp" sink_name=output source_name=input -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 18 +++++++-------- src/daemon/caps.h | 6 ++--- src/daemon/cmdline.c | 36 ++++++++++++++--------------- src/daemon/cmdline.h | 6 ++--- src/daemon/cpulimit.c | 22 +++++++++--------- src/daemon/cpulimit.h | 6 ++--- src/daemon/daemon-conf.c | 16 ++++++------- src/daemon/daemon-conf.h | 4 ++-- src/daemon/dumpmodules.c | 22 +++++++++--------- src/daemon/main.c | 60 ++++++++++++++++++++++++------------------------ 10 files changed, 98 insertions(+), 98 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index cebdaebc..db4bd919 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -2,17 +2,17 @@ /*** 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 @@ -50,7 +50,7 @@ int setresuid(uid_t r, uid_t e, uid_t s); /* Drop root rights when called SUID root */ void pa_drop_root(void) { uid_t uid = getuid(); - + if (uid == 0 || geteuid() != 0) return; @@ -96,13 +96,13 @@ int pa_limit_caps(void) { if (cap_set_proc(caps) < 0) goto fail; - pa_log_info("dropped capabilities successfully."); - + pa_log_info("dropped capabilities successfully."); + r = 0; fail: cap_free (caps); - + return r; } @@ -124,12 +124,12 @@ int pa_drop_caps(void) { pa_log("failed to drop capabilities: %s", pa_cstrerror(errno)); goto fail; } - + r = 0; fail: cap_free (caps); - + return r; } diff --git a/src/daemon/caps.h b/src/daemon/caps.h index 8a618286..34da1af6 100644 --- a/src/daemon/caps.h +++ b/src/daemon/caps.h @@ -5,17 +5,17 @@ /*** 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 diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index d368b644..c3cb9209 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -2,17 +2,17 @@ /*** 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 @@ -100,7 +100,7 @@ void pa_cmdline_help(const char *argv0) { e++; else e = argv0; - + printf("%s [options]\n\n" "COMMANDS:\n" " -h, --help Show this help\n" @@ -124,7 +124,7 @@ 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" + " -v Increase the verbosity level\n" " --log-target={auto,syslog,stderr} Specify the log target\n" " -p, --dl-search-path=PATH Set the search path for dynamic shared\n" " objects (plugins)\n" @@ -143,7 +143,7 @@ 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); } @@ -156,7 +156,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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: @@ -184,21 +184,21 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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); 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) { @@ -226,7 +226,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d if (conf->log_level < PA_LOG_LEVEL_MAX-1) conf->log_level++; } - + break; case ARG_HIGH_PRIORITY: @@ -249,13 +249,13 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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; @@ -307,7 +307,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d goto fail; } break; - + default: goto fail; } @@ -322,12 +322,12 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d } *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..fdfbc0b6 100644 --- a/src/daemon/cmdline.h +++ b/src/daemon/cmdline.h @@ -5,17 +5,17 @@ /*** 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 diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index d7466b06..808cb4d4 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -2,17 +2,17 @@ /*** 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 @@ -80,7 +80,7 @@ static pa_io_event *io_event = NULL; static struct sigaction sigaction_prev; /* Nonzero after pa_cpu_limit_init() */ -static int installed = 0; +static int installed = 0; /* The current state of operation */ static enum { @@ -131,24 +131,24 @@ static void signal_handler(int sig) { snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", (double)CPUTIME_INTERVAL_SOFT/(now-last_time)*100); write_err(t); #endif - + if (CPUTIME_INTERVAL_SOFT >= ((now-last_time)*(double)CPUTIME_PERCENT/100)) { 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)); 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 */ @@ -167,7 +167,7 @@ static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags 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); /* Prepare the main loop pipe */ @@ -191,7 +191,7 @@ 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; @@ -200,7 +200,7 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { installed = 1; reset_cpu_time(CPUTIME_INTERVAL_SOFT); - + return 0; } diff --git a/src/daemon/cpulimit.h b/src/daemon/cpulimit.h index 21bdd17b..bb11f794 100644 --- a/src/daemon/cpulimit.h +++ b/src/daemon/cpulimit.h @@ -5,17 +5,17 @@ /*** 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 diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index dd478126..319cf0c7 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -231,7 +231,7 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { int r = -1; FILE *f = NULL; - + pa_config_item table[] = { { "daemonize", pa_config_parse_bool, NULL }, { "fail", pa_config_parse_bool, NULL }, @@ -266,7 +266,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { #endif { NULL, NULL, NULL }, }; - + table[0].data = &c->daemonize; table[1].data = &c->fail; table[2].data = &c->high_priority; @@ -301,8 +301,8 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { table[24].data = &c->rlimit_memlock; #endif #endif - - + + pa_xfree(c->config_file); c->config_file = NULL; @@ -316,11 +316,11 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { } r = f ? pa_config_parse(c->config_file, f, table, NULL) : 0; - + finish: if (f) fclose(f); - + return r; } @@ -354,7 +354,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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); @@ -385,6 +385,6 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { pa_strbuf_printf(s, "rlimit-memlock = %li\n", c->rlimit_memlock.is_set ? (long int) c->rlimit_memlock.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 b4b833ad..b7fcf23b 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -66,7 +66,7 @@ typedef struct pa_daemon_conf { pa_log_level_t log_level; int resample_method; char *config_file; - + #ifdef HAVE_SYS_RESOURCE_H pa_rlimit rlimit_as, rlimit_core, rlimit_data, rlimit_fsize, rlimit_nofile, rlimit_stack; #ifdef RLIMIT_NPROC @@ -76,7 +76,7 @@ typedef struct pa_daemon_conf { pa_rlimit rlimit_memlock; #endif #endif - + } pa_daemon_conf; /* Allocate a new structure and fill it with sane defaults */ diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index 06734ea6..8509924a 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -45,14 +45,14 @@ static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modi static void long_info(const char *name, const char *path, pa_modinfo *i) { static int nl = 0; assert(name && i); - + if (nl) printf("\n"); nl = 1; printf("Name: %s\n", name); - + if (!i->description && !i->version && !i->author && !i->usage) printf("No module information available\n"); else { @@ -65,14 +65,14 @@ static void long_info(const char *name, const char *path, pa_modinfo *i) { if (i->usage) printf("Usage: %s\n", i->usage); } - + if (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; - + if ((i = pa_modinfo_get_by_name(path ? path : name))) { info(name, path, i); pa_modinfo_free(i); @@ -86,10 +86,10 @@ static int is_preloaded(const char *name) { for (l = lt_preloaded_symbols; l->name; l++) { char buf[64], *e; - + if (l->address) continue; - + snprintf(buf, sizeof(buf), "%s", l->name); if ((e = strrchr(buf, '.'))) *e = 0; @@ -112,7 +112,7 @@ 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; } @@ -127,20 +127,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); 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/main.c b/src/daemon/main.c index 5d77282c..b7266b7e 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -2,17 +2,17 @@ /*** 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 @@ -125,7 +125,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); @@ -170,7 +170,7 @@ 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("Failed to find user '%s'.", PA_SYSTEM_USER); return -1; @@ -197,7 +197,7 @@ static int change_user(void) { pa_log("Failed to create '%s': %s", PA_SYSTEM_RUNTIME_PATH, pa_cstrerror(errno)); return -1; } - + if (initgroups(PA_SYSTEM_USER, gr->gr_gid) != 0) { pa_log("Failed to change group list: %s", pa_cstrerror(errno)); return -1; @@ -265,7 +265,7 @@ static int create_runtime_dir(void) { /* 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("Failed to create '%s': %s", fn, pa_cstrerror(errno)); return -1; @@ -311,7 +311,7 @@ int main(int argc, char *argv[]) { pa_daemon_conf *conf = NULL; pa_mainloop *mainloop = NULL; - char *s; + char *s; int r, retval = 1, d = 0; int daemon_pipe[2] = { -1, -1 }; int suid_root, real_root; @@ -333,7 +333,7 @@ int main(int argc, char *argv[]) { #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("WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'."); pa_drop_root(); @@ -342,9 +342,9 @@ int main(int argc, char *argv[]) { real_root = 0; suid_root = 0; #endif - + LTDL_SET_PRELOADED_SYMBOLS(); - + r = lt_dlinit(); assert(r == 0); @@ -356,11 +356,11 @@ int main(int argc, char *argv[]) { #endif pa_random_seed(); - + pa_log_set_ident("pulseaudio"); - + conf = pa_daemon_conf_new(); - + if (pa_daemon_conf_load(conf, NULL) < 0) goto finish; @@ -429,9 +429,9 @@ int main(int argc, char *argv[]) { pa_log("failed to kill daemon."); else retval = 0; - + goto finish; - + default: assert(conf->cmd == PA_CMD_DAEMON); } @@ -457,7 +457,7 @@ int main(int argc, char *argv[]) { pa_log("failed to create pipe."); goto finish; } - + if ((child = fork()) < 0) { pa_log("fork() failed: %s", pa_cstrerror(errno)); goto finish; @@ -478,7 +478,7 @@ int main(int argc, char *argv[]) { pa_log("daemon startup failed."); else pa_log_info("daemon startup successful."); - + goto finish; } @@ -517,7 +517,7 @@ 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); @@ -528,13 +528,13 @@ int main(int argc, char *argv[]) { chdir("/"); umask(0022); - + if (conf->system_instance) { if (change_user() < 0) goto finish; } else if (create_runtime_dir() < 0) goto finish; - + if (conf->use_pid_file) { if (pa_pid_file_create() < 0) { pa_log("pa_pid_file_create() failed."); @@ -551,7 +551,7 @@ int main(int argc, char *argv[]) { #ifdef HAVE_SYS_RESOURCE_H set_all_rlimits(conf); #endif - + #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif @@ -580,7 +580,7 @@ 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); @@ -596,7 +596,7 @@ int main(int argc, char *argv[]) { 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); @@ -605,7 +605,7 @@ int main(int argc, char *argv[]) { 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."); #ifdef HAVE_FORK @@ -652,11 +652,11 @@ int main(int argc, char *argv[]) { if (!conf->no_cpu_limit) pa_cpu_limit_done(); - + pa_signal_done(); - + pa_log_info("Daemon terminated."); - + finish: if (mainloop) @@ -667,7 +667,7 @@ finish: if (valid_pid_file) pa_pid_file_remove(); - + close_pipe(daemon_pipe); #ifdef OS_IS_WIN32 @@ -675,6 +675,6 @@ finish: #endif lt_dlexit(); - + return retval; } -- cgit From 06211b7c8fd329137ae9003818543912a87d9898 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 13 Feb 2007 15:35:19 +0000 Subject: Add copyright notices to all relevant files. (based on svn log) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1426 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 3 +++ src/daemon/caps.h | 2 ++ src/daemon/cmdline.c | 2 ++ src/daemon/cmdline.h | 2 ++ src/daemon/cpulimit.c | 2 ++ src/daemon/cpulimit.h | 2 ++ src/daemon/daemon-conf.c | 3 +++ src/daemon/daemon-conf.h | 3 +++ src/daemon/dumpmodules.c | 3 +++ src/daemon/dumpmodules.h | 2 ++ src/daemon/main.c | 3 +++ 11 files changed, 27 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index db4bd919..2ea51c9f 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, diff --git a/src/daemon/caps.h b/src/daemon/caps.h index 34da1af6..4cd09578 100644 --- a/src/daemon/caps.h +++ b/src/daemon/caps.h @@ -6,6 +6,8 @@ /*** 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, diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index c3cb9209..dc757c9c 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -3,6 +3,8 @@ /*** 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, diff --git a/src/daemon/cmdline.h b/src/daemon/cmdline.h index fdfbc0b6..18418894 100644 --- a/src/daemon/cmdline.h +++ b/src/daemon/cmdline.h @@ -6,6 +6,8 @@ /*** 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, diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 808cb4d4..d4ac1d86 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -3,6 +3,8 @@ /*** 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 diff --git a/src/daemon/cpulimit.h b/src/daemon/cpulimit.h index bb11f794..271109b4 100644 --- a/src/daemon/cpulimit.h +++ b/src/daemon/cpulimit.h @@ -6,6 +6,8 @@ /*** 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, diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 319cf0c7..8cab327f 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index b7fcf23b..4843a610 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -6,6 +6,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index 8509924a..6743622a 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, diff --git a/src/daemon/dumpmodules.h b/src/daemon/dumpmodules.h index 05cd86e0..ab2ddb64 100644 --- a/src/daemon/dumpmodules.h +++ b/src/daemon/dumpmodules.h @@ -6,6 +6,8 @@ /*** 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, diff --git a/src/daemon/main.c b/src/daemon/main.c index b7266b7e..211dd30c 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, -- cgit From 4d88fcd59da84ac4f09113855c8f15384a4e05c3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 25 May 2007 20:35:30 +0000 Subject: when called with the setid bit change euid to uid sooner to make sure that we can access our own files even when we dropped most capabilities. (Closes #21) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1455 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 33 +++++++++++++++------------------ src/daemon/main.c | 29 ++++++++++++++++++----------- 2 files changed, 33 insertions(+), 29 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 2ea51c9f..8043230c 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -35,6 +35,9 @@ #ifdef HAVE_SYS_CAPABILITY_H #include #endif +#ifdef HAVE_SYS_PRCTL_H +#include +#endif #include @@ -76,35 +79,31 @@ void pa_drop_root(void) { #endif -#ifdef HAVE_SYS_CAPABILITY_H +#if defined(HAVE_SYS_CAPABILITY_H) && defined(HAVE_SYS_PRCTL_H) -/* Limit capabilities set to CAPSYS_NICE */ +/* Limit permitted 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; + if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) + goto fail; + pa_log_info("dropped capabilities successfully."); - - r = 0; + + r = 1; fail: - cap_free (caps); + cap_free(caps); return r; } @@ -114,24 +113,22 @@ 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); + prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0); + if (cap_set_proc(caps) < 0) { pa_log("failed to drop capabilities: %s", pa_cstrerror(errno)); goto fail; } - + r = 0; fail: - cap_free (caps); + cap_free(caps); return r; } diff --git a/src/daemon/main.c b/src/daemon/main.c index 211dd30c..72e47975 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -329,22 +329,29 @@ int main(int argc, char *argv[]) { struct timeval tv; #endif - setlocale(LC_ALL, ""); - - pa_limit_caps(); - #ifdef HAVE_GETUID real_root = getuid() == 0; suid_root = !real_root && geteuid() == 0; +#else + real_root = 0; + suid_root = 0; +#endif + + if (suid_root) { + if (pa_limit_caps() > 0) + /* We managed to drop capabilities except the needed + * ones. Hence we can drop the uid. */ + pa_drop_root(); + } + + setlocale(LC_ALL, ""); if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0 || gid >= 1000)) { pa_log_warn("WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'."); + pa_drop_caps(); pa_drop_root(); + suid_root = real_root = 0; } -#else - real_root = 0; - suid_root = 0; -#endif LTDL_SET_PRELOADED_SYMBOLS(); @@ -381,10 +388,10 @@ int main(int argc, char *argv[]) { if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) pa_raise_priority(); - pa_drop_caps(); - - if (suid_root) + if (suid_root) { + pa_drop_caps(); pa_drop_root(); + } if (conf->dl_search_path) lt_dlsetsearchpath(conf->dl_search_path); -- cgit From 5530d3295a3e65905346e98314f884a09a2be325 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 29 May 2007 07:47:02 +0000 Subject: We now use gid unconditionally, so make sure it's defined. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1463 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 72e47975..91cc3a2f 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -320,9 +320,7 @@ int main(int argc, char *argv[]) { int suid_root, real_root; int valid_pid_file = 0; -#ifdef HAVE_GETUID gid_t gid = (gid_t) -1; -#endif #ifdef OS_IS_WIN32 pa_time_event *timer; -- cgit From 1e12e0ee8dfdda1632b9c082aba6fc1956813a5b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 29 May 2007 17:24:48 +0000 Subject: Kill spaces on EOL git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1465 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 8043230c..f92db743 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -97,9 +97,9 @@ int pa_limit_caps(void) { if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) goto fail; - + pa_log_info("dropped capabilities successfully."); - + r = 1; fail: @@ -119,12 +119,12 @@ int pa_drop_caps(void) { cap_clear(caps); prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0); - + if (cap_set_proc(caps) < 0) { pa_log("failed to drop capabilities: %s", pa_cstrerror(errno)); goto fail; } - + r = 0; fail: -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 13 +- src/daemon/cmdline.c | 37 ++++- src/daemon/cpulimit.c | 52 +++--- src/daemon/daemon-conf.c | 257 ++++++++++++++++++++++-------- src/daemon/daemon-conf.h | 7 +- src/daemon/daemon.conf.in | 13 +- src/daemon/default.pa.in | 63 +++++--- src/daemon/dumpmodules.c | 18 ++- src/daemon/ltdl-bind-now.c | 160 +++++++++++++++++++ src/daemon/ltdl-bind-now.h | 32 ++++ src/daemon/main.c | 164 ++++++++++++------- src/daemon/pulseaudio-module-xsmp.desktop | 10 ++ 12 files changed, 631 insertions(+), 195 deletions(-) create mode 100644 src/daemon/ltdl-bind-now.c create mode 100644 src/daemon/ltdl-bind-now.h create mode 100644 src/daemon/pulseaudio-module-xsmp.desktop (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index f92db743..5b4008a5 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -26,11 +26,11 @@ #include #endif -#include #include #include #include #include +#include #ifdef HAVE_SYS_CAPABILITY_H #include @@ -60,7 +60,7 @@ void pa_drop_root(void) { if (uid == 0 || geteuid() != 0) return; - pa_log_info("dropping root rights."); + pa_log_info("Dropping root priviliges."); #if defined(HAVE_SETRESUID) setresuid(uid, uid, uid); @@ -88,8 +88,9 @@ int pa_limit_caps(void) { cap_value_t nice_cap = CAP_SYS_NICE; caps = cap_init(); - assert(caps); + pa_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) @@ -98,7 +99,7 @@ int pa_limit_caps(void) { if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) goto fail; - pa_log_info("dropped capabilities successfully."); + pa_log_info("Dropped capabilities successfully."); r = 1; @@ -114,14 +115,14 @@ int pa_drop_caps(void) { int r = -1; caps = cap_init(); - assert(caps); + pa_assert(caps); cap_clear(caps); prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0); if (cap_set_proc(caps) < 0) { - pa_log("failed to drop capabilities: %s", pa_cstrerror(errno)); + pa_log("Failed to drop capabilities: %s", pa_cstrerror(errno)); goto fail; } diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index dc757c9c..6b7b2671 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -26,7 +26,6 @@ #endif #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include +#include #include "cmdline.h" @@ -63,7 +63,9 @@ enum { ARG_CHECK, ARG_NO_CPU_LIMIT, ARG_DISABLE_SHM, - ARG_SYSTEM + ARG_DUMP_RESAMPLE_METHODS, + ARG_SYSTEM, + ARG_CLEANUP_SHM }; /* Tabel for getopt_long() */ @@ -92,12 +94,16 @@ static struct option long_options[] = { {"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; + pa_assert(argv0); + if ((e = strrchr(argv0, '/'))) e++; else @@ -109,6 +115,8 @@ void pa_cmdline_help(const char *argv0) { " --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" " -k --kill Kill a running daemon\n" " --check Check for a running daemon\n\n" @@ -131,9 +139,8 @@ void pa_cmdline_help(const char *argv0) { " -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" + " (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" @@ -152,7 +159,10 @@ void pa_cmdline_help(const char *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(); @@ -178,6 +188,14 @@ 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; @@ -193,9 +211,12 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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"); diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index d4ac1d86..ab212129 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "cpulimit.h" @@ -38,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -92,23 +92,18 @@ static enum { /* 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; - - r = getrlimit(RLIMIT_CPU, &rl); - assert(r >= 0); + pa_assert_se(getrlimit(RLIMIT_CPU, &rl) >= 0); rl.rlim_cur = n; - r = setrlimit(RLIMIT_CPU, &rl); - assert(r >= 0); + pa_assert_se(setrlimit(RLIMIT_CPU, &rl) >= 0); } /* A simple, thread-safe puts() work-alike */ @@ -118,7 +113,7 @@ static void write_err(const char *p) { /* The signal handler, called on every SIGXCPU */ static void signal_handler(int sig) { - assert(sig == SIGXCPU); + pa_assert(sig == SIGXCPU); if (phase == PHASE_IDLE) { time_t now; @@ -130,7 +125,7 @@ static void signal_handler(int sig) { time(&now); #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/(now-last_time)*100); write_err(t); #endif @@ -160,7 +155,12 @@ static void signal_handler(int sig) { /* 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_read(the_pipe[0], &c, sizeof(c), NULL); m->quit(m, 1); /* Quit the main loop */ } @@ -168,7 +168,13 @@ 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); + + 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); time(&last_time); @@ -178,10 +184,10 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { 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]); + pa_make_fd_cloexec(the_pipe[0]); + pa_make_fd_cloexec(the_pipe[1]); api = m; io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL); @@ -208,24 +214,18 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { /* 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); + pa_assert_se(sigaction(SIGXCPU, &sigaction_prev, NULL) >= 0); installed = 0; } } diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 8cab327f..920e3717 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -39,19 +38,14 @@ #include #include #include +#include #include "daemon-conf.h" -#ifndef OS_IS_WIN32 -# define PATH_SEP "/" -#else -# define PATH_SEP "\\" -#endif - -#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_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "default.pa" +#define DEFAULT_SCRIPT_FILE_USER PA_PATH_SEP "default.pa" +#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" @@ -72,31 +66,34 @@ static const pa_daemon_conf default_conf = { .default_script_file = NULL, .log_target = PA_LOG_SYSLOG, .log_level = PA_LOG_NOTICE, - .resample_method = PA_RESAMPLER_SRC_SINC_FASTEST, + .resample_method = PA_RESAMPLER_AUTO, .config_file = NULL, .use_pid_file = 1, .system_instance = 0, .no_cpu_limit = 0, - .disable_shm = 0 + .disable_shm = 0, + .default_n_fragments = 4, + .default_fragment_size_msec = 25, + .default_sample_spec = { .format = PA_SAMPLE_S16NE, .rate = 44100, .channels = 2 } #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 = 200, .is_set = 1 }, + .rlimit_nofile = { .value = 256, .is_set = 1 }, .rlimit_stack = { .value = 0, .is_set = 0 } #ifdef RLIMIT_NPROC , .rlimit_nproc = { .value = 0, .is_set = 0 } #endif #ifdef RLIMIT_MEMLOCK - , .rlimit_memlock = { .value = 0, .is_set = 1 } + , .rlimit_memlock = { .value = 16384, .is_set = 1 } #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 *c = pa_xnewdup(pa_daemon_conf, &default_conf, 1); if ((f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file, "r"))) fclose(f); @@ -106,7 +103,7 @@ pa_daemon_conf* pa_daemon_conf_new(void) { } void pa_daemon_conf_free(pa_daemon_conf *c) { - assert(c); + pa_assert(c); pa_xfree(c->script_commands); pa_xfree(c->dl_search_path); pa_xfree(c->default_script_file); @@ -115,7 +112,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; @@ -133,7 +131,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) @@ -158,7 +157,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; @@ -169,7 +169,11 @@ int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string) { static int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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("[%s:%u] Invalid log target '%s'.", filename, line, rvalue); @@ -181,7 +185,11 @@ static int parse_log_target(const char *filename, unsigned line, const char *lva static int parse_log_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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("[%s:%u] Invalid log level '%s'.", filename, line, rvalue); @@ -193,10 +201,14 @@ static int parse_log_level(const char *filename, unsigned line, const char *lval static int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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("[%s:%u] Inavalid resample method '%s'.", filename, line, rvalue); + pa_log("[%s:%u] Invalid resample method '%s'.", filename, line, rvalue); return -1; } @@ -206,10 +218,11 @@ static int parse_resample_method(const char *filename, unsigned line, const char 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 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 */ @@ -218,7 +231,7 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, } else { int32_t k; if (pa_atoi(rvalue, &k) < 0) { - pa_log("[%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; @@ -231,43 +244,138 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, return 0; } +static int parse_sample_format(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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 *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) { + pa_daemon_conf *c = data; + int32_t r; + + pa_assert(filename); + pa_assert(lvalue); + pa_assert(rvalue); + pa_assert(data); + + if (pa_atoi(rvalue, &r) < 0 || r > 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; +} + +static int parse_sample_channels(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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 > PA_CHANNELS_MAX || n <= 0) { + pa_log("[%s:%u] Invalid sample channels '%s'.", filename, line, rvalue); + return -1; + } + + c->default_sample_spec.channels = (uint8_t) n; + return 0; +} + +static int parse_fragments(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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 *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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; +} + int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { int r = -1; FILE *f = NULL; 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 }, - { "no-cpu-limit", pa_config_parse_bool, NULL }, - { "disable-shm", pa_config_parse_bool, NULL }, + { "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 }, + { "no-cpu-limit", pa_config_parse_bool, NULL }, + { "disable-shm", pa_config_parse_bool, NULL }, + { "default-sample-format", parse_sample_format, NULL }, + { "default-sample-rate", parse_sample_rate, NULL }, + { "default-sample-channels", parse_sample_channels, NULL }, + { "default-fragments", parse_fragments, NULL }, + { "default-fragment-size-msec", parse_fragment_size_msec, 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 }, + { "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-nproc", parse_rlimit, NULL }, #endif #ifdef RLIMIT_MEMLOCK - { "rlimit-memlock", parse_rlimit, NULL }, + { "rlimit-memlock", parse_rlimit, NULL }, #endif #endif - { NULL, NULL, NULL }, + { NULL, NULL, NULL }, }; table[0].data = &c->daemonize; @@ -287,25 +395,29 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { table[14].data = &c->system_instance; table[15].data = &c->no_cpu_limit; table[16].data = &c->disable_shm; + table[17].data = c; + table[18].data = c; + table[19].data = c; + table[20].data = c; + table[21].data = c; #ifdef HAVE_SYS_RESOURCE_H - table[17].data = &c->rlimit_as; - table[18].data = &c->rlimit_core; - table[19].data = &c->rlimit_data; - table[20].data = &c->rlimit_fsize; - table[21].data = &c->rlimit_nofile; - table[22].data = &c->rlimit_stack; + table[22].data = &c->rlimit_as; + table[23].data = &c->rlimit_core; + table[24].data = &c->rlimit_data; + table[25].data = &c->rlimit_fsize; + table[26].data = &c->rlimit_nofile; + table[27].data = &c->rlimit_stack; #ifdef RLIMIT_NPROC - table[23].data = &c->rlimit_nproc; + table[28].data = &c->rlimit_nproc; #endif #ifdef RLIMIT_MEMLOCK #ifndef RLIMIT_NPROC #error "Houston, we have a numbering problem!" #endif - table[24].data = &c->rlimit_memlock; + table[29].data = &c->rlimit_memlock; #endif #endif - pa_xfree(c->config_file); c->config_file = NULL; @@ -314,7 +426,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file, "r"); if (!f && errno != ENOENT) { - pa_log("WARNING: failed to open configuration file '%s': %s", c->config_file, pa_cstrerror(errno)); + pa_log_warn("Failed to open configuration file '%s': %s", c->config_file, pa_cstrerror(errno)); goto finish; } @@ -351,12 +463,16 @@ static const char* const log_level_to_string[] = { }; char *pa_daemon_conf_dump(pa_daemon_conf *c) { - pa_strbuf *s = pa_strbuf_new(); + pa_strbuf *s; + + 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_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); @@ -373,7 +489,12 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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, "no-cpu-limit = %i\n", !!c->no_cpu_limit); - pa_strbuf_printf(s, "disable_shm = %i\n", !!c->disable_shm); + pa_strbuf_printf(s, "disable-shm = %i\n", !!c->disable_shm); + 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-fragments = %u\n", c->default_n_fragments); + pa_strbuf_printf(s, "default-fragment-size-msec = %u\n", c->default_fragment_size_msec); #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); diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index 4843a610..4d37861d 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -26,6 +26,7 @@ ***/ #include +#include #ifdef HAVE_SYS_RESOURCE_H #include @@ -39,7 +40,9 @@ typedef enum pa_daemon_conf_cmd { 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 @@ -80,6 +83,8 @@ typedef struct pa_daemon_conf { #endif #endif + unsigned default_n_fragments, default_fragment_size_msec; + pa_sample_spec default_sample_spec; } pa_daemon_conf; /* Allocate a new structure and fill it with sane defaults */ diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 29b22a42..2132bf3d 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -92,10 +92,19 @@ ; rlimit-core = -1 ; rlimit-data = -1 ; rlimit-fsize = -1 -; rlimit-nofile = 200 +; rlimit-nofile = 256 ; rlimit-stack = -1 ; rlimit-nproc = -1 -; rlimit-memlock = 25 +; rlimit-memlock = 16384 ## Disable shared memory data transfer ; disable-shm = 0 + +## Default sample format +; default-sample-format = s16le +; default-sample-rate = 44100 +; default-sample-channels = 2 + +## Default fragment settings, for device drivers that need this +; default-fragments = 4 +; default-fragment-size-msec = 25 diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index af2a6789..597993c4 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,8 +16,19 @@ # along with PulseAudio; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +.nofail + +### Load something into the sample cache +#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 -### Load audio drivers statically +.fail + +### Load audio drivers statically (it's probably better to not load +### these drivers manually, but instead use module-hal-detect -- +### see below -- for doing this automatically) #load-module module-alsa-sink #load-module module-alsa-source device=hw:1,0 #load-module module-oss device="/dev/dsp" sink_name=output source_name=input @@ -27,19 +37,13 @@ #load-module module-pipe-sink ### Automatically load driver modules depending on the hardware available -@HAVE_HAL_TRUE@load-module module-hal-detect - +.ifexists @PA_DLSEARCHPATH@/module-hal-detect@PA_SOEXT@ +load-module module-hal-detect +.else ### Alternatively use the static hardware detection module (for systems that -### lack HAL support -@HAVE_HAL_FALSE@load-module module-detect - -### 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 +### lack HAL support) +load-module module-detect +.endif ### Load several protocols load-module module-esound-protocol-unix @@ -61,27 +65,36 @@ load-module module-native-protocol-unix ### Automatically restore the volume of playback streams load-module module-volume-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 some devices default -#set-default-sink output -#set-default-source input - -.nofail - -### 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 +### Automatically suspend sinks/sources that become idle for too long +load-module module-suspend-on-idle ### Load X11 bell module -load-module module-x11-bell sample=x11-bell +#load-module module-x11-bell sample=x11-bell ### Publish connection data in the X11 root window +.ifexists @PA_DLSEARCHPATH@/module-x11-publish@PA_SOEXT@ load-module module-x11-publish +.endif + +### Register ourselves in the X11 session manager +# Deactivated by default, to avoid deadlock when PA is started as esd from gnome-session +# Instead we load this via /etc/xdg/autostart/ and "pactl load-module" now +# load-module module-x11-xsmp ### 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 @PA_DLSEARCHPATH@/module-gconf@PA_SOEXT@ load-module module-gconf +.endif + +### Make some devices default +#set-default-sink output +#set-default-source input diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index 6743622a..ad7fab20 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -28,26 +28,30 @@ #include #include -#include #include #include #include #include +#include +#include #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); + 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"); @@ -76,6 +80,8 @@ static void long_info(const char *name, const char *path, pa_modinfo *i) { 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); @@ -93,7 +99,7 @@ static int is_preloaded(const char *name) { 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; @@ -121,6 +127,8 @@ static int callback(const char *path, lt_ptr data) { } 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++) @@ -137,7 +145,7 @@ void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) { 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; diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c new file mode 100644 index 00000000..6025c6e3 --- /dev/null +++ b/src/daemon/ltdl-bind-now.c @@ -0,0 +1,160 @@ +/* $Id$ */ + +/*** + This file is part of PulseAudio. + + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, + 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 +#endif + +#if HAVE_DLFCN_H +#include +#endif + +#if HAVE_SYS_DL_H +#include +#endif + +#include + +#include +#include +#include +#include + +#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 + +static pa_mutex *libtool_mutex = NULL; + +PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls); + +static void libtool_lock(void) { + pa_mutex_lock(libtool_mutex); +} + +static void libtool_unlock(void) { + pa_mutex_unlock(libtool_mutex); +} + +static void libtool_set_error(const char *error) { + PA_STATIC_TLS_SET(libtool_tls, (char*) error); +} + +static const char *libtool_get_error(void) { + return PA_STATIC_TLS_GET(libtool_tls); +} + +#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_module m; + + pa_assert(fname); + + if (!(m = dlopen(fname, PA_BIND_NOW))) { + libtool_set_error(dlerror()); + return NULL; + } + + return m; +} + +static int bind_now_close(lt_user_data d, lt_module m) { + + pa_assert(m); + + if (dlclose(m) != 0){ + libtool_set_error(dlerror()); + 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))) { + libtool_set_error(dlerror()); + return NULL; + } + + return ptr; +} + +#endif + +void pa_ltdl_init(void) { + +#ifdef PA_BIND_NOW + lt_dlloader *place; + static const struct lt_user_dlloader loader = { + .module_open = bind_now_open, + .module_close = bind_now_close, + .find_sym = bind_now_find_sym + }; +#endif + + pa_assert_se(lt_dlinit() == 0); + pa_assert_se(libtool_mutex = pa_mutex_new(TRUE, FALSE)); + pa_assert_se(lt_dlmutex_register(libtool_lock, libtool_unlock, libtool_set_error, libtool_get_error) == 0); + +#ifdef PA_BIND_NOW + + if (!(place = lt_dlloader_find("dlopen"))) + place = lt_dlloader_next(NULL); + + /* Add our BIND_NOW loader as the default module loader. */ + if (lt_dlloader_add(place, &loader, "bind-now-loader") != 0) + pa_log_warn("Failed to add bind-now-loader."); +#endif +} + +void pa_ltdl_done(void) { + pa_assert_se(lt_dlexit() == 0); + pa_mutex_free(libtool_mutex); + libtool_mutex = NULL; +} + diff --git a/src/daemon/ltdl-bind-now.h b/src/daemon/ltdl-bind-now.h new file mode 100644 index 00000000..e19c7bc1 --- /dev/null +++ b/src/daemon/ltdl-bind-now.h @@ -0,0 +1,32 @@ +#ifndef foopulsecoreltdlbindnowhfoo +#define foopulsecoreltdlbindnowhfoo + +/* $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, + 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 91cc3a2f..6c9f6627 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -59,13 +58,16 @@ #include #endif -#include "../pulsecore/winsock.h" +#ifdef HAVE_DBUS +#include +#endif #include #include #include #include +#include #include #include #include @@ -78,12 +80,20 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include "cmdline.h" #include "cpulimit.h" #include "daemon-conf.h" #include "dumpmodules.h" #include "caps.h" +#include "ltdl-bind-now.h" #ifdef HAVE_LIBWRAP /* Only one instance of these variables */ @@ -120,7 +130,7 @@ 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("Got signal %s.", pa_strsignal(sig)); + pa_log_info("Got signal %s.", pa_sig2str(sig)); switch (sig) { #ifdef SIGUSR1 @@ -153,14 +163,6 @@ static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e, } } -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) @@ -281,7 +283,7 @@ static int create_runtime_dir(void) { static void 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; @@ -313,13 +315,11 @@ int main(int argc, char *argv[]) { pa_strbuf *buf = NULL; pa_daemon_conf *conf = NULL; pa_mainloop *mainloop = NULL; - char *s; - int r, retval = 1, d = 0; + int r = 0, retval = 1, d = 0; int daemon_pipe[2] = { -1, -1 }; int suid_root, real_root; int valid_pid_file = 0; - gid_t gid = (gid_t) -1; #ifdef OS_IS_WIN32 @@ -327,6 +327,23 @@ int main(int argc, char *argv[]) { struct timeval tv; #endif + +#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. + */ + + if (!getenv("LD_BIND_NOW")) { + putenv(pa_xstrdup("LD_BIND_NOW=1")); + + /* We have to execute ourselves, because the libc caches the + * value of $LD_BIND_NOW on initialization. */ + pa_assert_se(execv("/proc/self/exe", argv) == 0); + } +#endif + #ifdef HAVE_GETUID real_root = getuid() == 0; suid_root = !real_root && geteuid() == 0; @@ -336,16 +353,26 @@ int main(int argc, char *argv[]) { #endif if (suid_root) { - if (pa_limit_caps() > 0) - /* We managed to drop capabilities except the needed - * ones. Hence we can drop the uid. */ - pa_drop_root(); + /* Drop all capabilities except CAP_SYS_NICE */ + pa_limit_caps(); + + /* Drop priviliges, but keep CAP_SYS_NICE */ + pa_drop_root(); + + /* After dropping root, the effective set is reset, hence, + * let's raise it again */ + pa_limit_caps(); + + /* When capabilities are not supported we will not be able to + * aquire RT sched anymore. But yes, that's the way it is. It + * is just too risky tun let PA run as root all the time. */ } setlocale(LC_ALL, ""); - if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0 || gid >= 1000)) { - pa_log_warn("WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'."); + if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0)) { + pa_log_info("Warning: Called SUID root, but not in group '"PA_REALTIME_GROUP"'. " + "For enabling real-time scheduling please become a member of '"PA_REALTIME_GROUP"' , or increase the RLIMIT_RTPRIO user limit."); pa_drop_caps(); pa_drop_root(); suid_root = real_root = 0; @@ -353,8 +380,7 @@ int main(int argc, char *argv[]) { LTDL_SET_PRELOADED_SYMBOLS(); - r = lt_dlinit(); - assert(r == 0); + pa_ltdl_init(); #ifdef OS_IS_WIN32 { @@ -386,7 +412,7 @@ int main(int argc, char *argv[]) { if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) pa_raise_priority(); - if (suid_root) { + if (suid_root && (conf->cmd != PA_CMD_DAEMON || !conf->high_priority)) { pa_drop_caps(); pa_drop_root(); } @@ -408,6 +434,16 @@ int main(int argc, char *argv[]) { goto finish; } + case PA_CMD_DUMP_RESAMPLE_METHODS: { + int i; + + for (i = 0; i < PA_RESAMPLER_MAX; i++) + if (pa_resample_method_supported(i)) + printf("%s\n", pa_resample_method_to_string(i)); + + goto finish; + } + case PA_CMD_HELP : pa_cmdline_help(argv[0]); retval = 0; @@ -440,8 +476,15 @@ int main(int argc, char *argv[]) { goto finish; + case PA_CMD_CLEANUP_SHM: + + if (pa_shm_cleanup() >= 0) + retval = 0; + + goto finish; + default: - assert(conf->cmd == PA_CMD_DAEMON); + pa_assert(conf->cmd == PA_CMD_DAEMON); } if (real_root && !conf->system_instance) { @@ -474,7 +517,7 @@ int main(int argc, char *argv[]) { if (child != 0) { /* 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)) { @@ -490,7 +533,7 @@ int main(int argc, char *argv[]) { goto finish; } - close(daemon_pipe[0]); + pa_assert_se(pa_close(daemon_pipe[0]) == 0); daemon_pipe[0] = -1; #endif @@ -505,9 +548,9 @@ int main(int argc, char *argv[]) { #endif #ifndef OS_IS_WIN32 - close(0); - close(1); - close(2); + pa_close(0); + pa_close(1); + pa_close(2); open("/dev/null", O_RDONLY); open("/dev/null", O_WRONLY); @@ -529,12 +572,12 @@ int main(int argc, char *argv[]) { #ifdef TIOCNOTTY if ((tty_fd = open("/dev/tty", O_RDWR)) >= 0) { ioctl(tty_fd, TIOCNOTTY, (char*) 0); - close(tty_fd); + pa_assert_se(pa_close(tty_fd) == 0); } #endif } - chdir("/"); + pa_assert_se(chdir("/") == 0); umask(0022); if (conf->system_instance) { @@ -564,18 +607,37 @@ int main(int argc, char *argv[]) { signal(SIGPIPE, SIG_IGN); #endif - mainloop = pa_mainloop_new(); - assert(mainloop); + pa_log_info("Page size is %lu bytes", (unsigned long) PA_PAGE_SIZE); + + 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!"); + +#ifdef SIGRTMIN + /* Valgrind uses SIGRTMAX. To easy debugging we don't use it here */ + pa_rtsig_configure(SIGRTMIN, SIGRTMAX-1); +#endif + + pa_assert_se(mainloop = pa_mainloop_new()); if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm))) { - pa_log("pa_core_new() failed."); + pa_log("pa_core_new() failed."); goto finish; } c->is_system_instance = !!conf->system_instance; - - r = pa_signal_init(pa_mainloop_get_api(mainloop)); - assert(r == 0); + c->high_priority = !!conf->high_priority; + c->default_sample_spec = conf->default_sample_spec; + c->default_n_fragments = conf->default_n_fragments; + c->default_fragment_size_msec = conf->default_fragment_size_msec; + 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_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); @@ -590,9 +652,7 @@ int main(int argc, char *argv[]) { #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); + pa_assert_se(timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&tv), message_cb, NULL)); #endif if (conf->daemonize) @@ -600,10 +660,8 @@ int main(int argc, char *argv[]) { oil_init(); - if (!conf->no_cpu_limit) { - r = pa_cpu_limit_init(pa_mainloop_get_api(mainloop)); - assert(r == 0); - } + if (!conf->no_cpu_limit) + pa_assert_se(pa_cpu_limit_init(pa_mainloop_get_api(mainloop)) == 0); buf = pa_strbuf_new(); if (conf->default_script_file) @@ -634,12 +692,6 @@ int main(int argc, char *argv[]) { pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL); #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; - 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); @@ -656,7 +708,7 @@ int main(int argc, char *argv[]) { pa_mainloop_get_api(mainloop)->time_free(timer); #endif - pa_core_free(c); + pa_core_unref(c); if (!conf->no_cpu_limit) pa_cpu_limit_done(); @@ -676,13 +728,17 @@ finish: if (valid_pid_file) pa_pid_file_remove(); - close_pipe(daemon_pipe); + pa_close_pipe(daemon_pipe); #ifdef OS_IS_WIN32 WSACleanup(); #endif - lt_dlexit(); + pa_ltdl_done(); + +#ifdef HAVE_DBUS + dbus_shutdown(); +#endif return retval; } diff --git a/src/daemon/pulseaudio-module-xsmp.desktop b/src/daemon/pulseaudio-module-xsmp.desktop new file mode 100644 index 00000000..fa719a73 --- /dev/null +++ b/src/daemon/pulseaudio-module-xsmp.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=1.0 +Encoding=UTF-8 +Name=PulseAudio Session Management +Comment=Load module-x11-xsmp into PulseAudio +Exec=pactl load-module module-x11-xsmp +Terminal=false +Type=Application +Categories= +GenericName= -- cgit From a46804a8e2ba8aa0e869bcf72015e3b551a7b40d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Oct 2007 15:33:07 +0000 Subject: use real path of binary instead of /proc/self/exe to execute ourselves git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1976 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 6c9f6627..cd3cfcc8 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -336,11 +336,14 @@ int main(int argc, char *argv[]) { */ if (!getenv("LD_BIND_NOW")) { - putenv(pa_xstrdup("LD_BIND_NOW=1")); + char *rp; /* We have to execute ourselves, because the libc caches the * value of $LD_BIND_NOW on initialization. */ - pa_assert_se(execv("/proc/self/exe", argv) == 0); + + putenv(pa_xstrdup("LD_BIND_NOW=1")); + pa_assert_se(rp = pa_readlink("/proc/self/exe")); + pa_assert_se(execv(rp, argv) == 0); } #endif -- cgit From 44d7c9ad9bcfd8ab55d4ef7f6595c7ffd65da35d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Nov 2007 00:34:43 +0000 Subject: add nice and rtprio resource limit support; make rtprio and nice level to use configurable; some minor updates git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2010 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 177 +++++++++++++++++++++++++++++++++------------- src/daemon/daemon-conf.h | 24 +++++-- src/daemon/daemon.conf.in | 89 +++++++++++++++-------- src/daemon/main.c | 6 ++ 4 files changed, 210 insertions(+), 86 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 920e3717..089b12fc 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -53,10 +54,13 @@ static const pa_daemon_conf default_conf = { .cmd = PA_CMD_DAEMON, - .daemonize = 0, - .fail = 1, - .high_priority = 0, - .disallow_module_loading = 0, + .daemonize = FALSE, + .fail = TRUE, + .high_priority = TRUE, + .nice_level = -11, + .realtime_scheduling = FALSE, + .realtime_priority = 5, /* Half of JACK's default rtprio */ + .disallow_module_loading = FALSE, .exit_idle_time = -1, .module_idle_time = 20, .scache_idle_time = 20, @@ -68,25 +72,31 @@ static const pa_daemon_conf default_conf = { .log_level = PA_LOG_NOTICE, .resample_method = PA_RESAMPLER_AUTO, .config_file = NULL, - .use_pid_file = 1, - .system_instance = 0, - .no_cpu_limit = 0, - .disable_shm = 0, + .use_pid_file = TRUE, + .system_instance = FALSE, + .no_cpu_limit = FALSE, + .disable_shm = FALSE, .default_n_fragments = 4, .default_fragment_size_msec = 25, .default_sample_spec = { .format = PA_SAMPLE_S16NE, .rate = 44100, .channels = 2 } #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 = 256, .is_set = 1 }, - .rlimit_stack = { .value = 0, .is_set = 0 } + , .rlimit_as = { .value = 0, .is_set = FALSE }, + .rlimit_core = { .value = 0, .is_set = FALSE }, + .rlimit_data = { .value = 0, .is_set = FALSE }, + .rlimit_fsize = { .value = 0, .is_set = FALSE }, + .rlimit_nofile = { .value = 256, .is_set = TRUE }, + .rlimit_stack = { .value = 0, .is_set = FALSE } #ifdef RLIMIT_NPROC - , .rlimit_nproc = { .value = 0, .is_set = 0 } + , .rlimit_nproc = { .value = 0, .is_set = FALSE } #endif #ifdef RLIMIT_MEMLOCK - , .rlimit_memlock = { .value = 16384, .is_set = 1 } + , .rlimit_memlock = { .value = 16384, .is_set = TRUE } +#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 #endif }; @@ -334,6 +344,42 @@ static int parse_fragment_size_msec(const char *filename, unsigned line, const c return 0; } +static int parse_nice_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED 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 *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) { + 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; + return 0; +} + int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { int r = -1; FILE *f = NULL; @@ -342,25 +388,28 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "daemonize", pa_config_parse_bool, NULL }, { "fail", pa_config_parse_bool, NULL }, { "high-priority", pa_config_parse_bool, NULL }, + { "realtime-scheduling", pa_config_parse_bool, NULL }, { "disallow-module-loading", pa_config_parse_bool, NULL }, + { "use-pid-file", pa_config_parse_bool, NULL }, + { "system-instance", pa_config_parse_bool, NULL }, + { "no-cpu-limit", pa_config_parse_bool, NULL }, + { "disable-shm", 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 }, + { "realtime-priority", parse_rtprio, 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 }, - { "no-cpu-limit", pa_config_parse_bool, NULL }, - { "disable-shm", pa_config_parse_bool, NULL }, { "default-sample-format", parse_sample_format, NULL }, { "default-sample-rate", parse_sample_rate, NULL }, { "default-sample-channels", parse_sample_channels, NULL }, { "default-fragments", parse_fragments, NULL }, { "default-fragment-size-msec", parse_fragment_size_msec, NULL }, + { "nice-level", parse_nice_level, NULL }, #ifdef HAVE_SYS_RESOURCE_H { "rlimit-as", parse_rlimit, NULL }, { "rlimit-core", parse_rlimit, NULL }, @@ -374,6 +423,12 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { #ifdef RLIMIT_MEMLOCK { "rlimit-memlock", parse_rlimit, NULL }, #endif +#ifdef RLIMIT_NICE + { "rlimit-nice", parse_rlimit, NULL }, +#endif +#ifdef RLIMIT_RTPRIO + { "rlimit-rtprio", parse_rlimit, NULL }, +#endif #endif { NULL, NULL, NULL }, }; @@ -381,40 +436,55 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { 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[3].data = &c->realtime_scheduling; + table[4].data = &c->disallow_module_loading; + table[5].data = &c->use_pid_file; + table[6].data = &c->system_instance; + table[7].data = &c->no_cpu_limit; + table[8].data = &c->disable_shm; + table[9].data = &c->exit_idle_time; + table[10].data = &c->module_idle_time; + table[11].data = &c->scache_idle_time; table[12].data = c; - table[13].data = &c->use_pid_file; - table[14].data = &c->system_instance; - table[15].data = &c->no_cpu_limit; - table[16].data = &c->disable_shm; + table[13].data = &c->dl_search_path; + table[14].data = &c->default_script_file; + table[15].data = c; + table[16].data = c; table[17].data = c; table[18].data = c; table[19].data = c; table[20].data = c; table[21].data = c; + table[22].data = c; + table[23].data = c; + table[24].data = c; #ifdef HAVE_SYS_RESOURCE_H - table[22].data = &c->rlimit_as; - table[23].data = &c->rlimit_core; - table[24].data = &c->rlimit_data; - table[25].data = &c->rlimit_fsize; - table[26].data = &c->rlimit_nofile; - table[27].data = &c->rlimit_stack; + table[25].data = &c->rlimit_as; + table[26].data = &c->rlimit_core; + table[27].data = &c->rlimit_data; + table[28].data = &c->rlimit_fsize; + table[29].data = &c->rlimit_nofile; + table[30].data = &c->rlimit_stack; #ifdef RLIMIT_NPROC - table[28].data = &c->rlimit_nproc; + table[31].data = &c->rlimit_nproc; #endif #ifdef RLIMIT_MEMLOCK #ifndef RLIMIT_NPROC #error "Houston, we have a numbering problem!" #endif - table[29].data = &c->rlimit_memlock; + table[32].data = &c->rlimit_memlock; +#endif +#ifdef RLIMIT_NICE +#ifndef RLIMIT_MEMLOCK +#error "Houston, we have a numbering problem!" +#endif + table[33].data = &c->rlimit_nice; +#endif +#ifdef RLIMIT_RTPRIO +#ifndef RLIMIT_NICE +#error "Houston, we have a numbering problem!" +#endif + table[34].data = &c->rlimit_rtprio; #endif #endif @@ -474,10 +544,17 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { pa_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, "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, "disallow-module-loading = %s\n", pa_yes_no(c->disallow_module_loading)); + 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)); + pa_strbuf_printf(s, "no-cpu-limit = %s\n", pa_yes_no(c->no_cpu_limit)); + pa_strbuf_printf(s, "disable-shm = %s\n", pa_yes_no(c->disable_shm)); 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); @@ -486,10 +563,6 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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, "no-cpu-limit = %i\n", !!c->no_cpu_limit); - pa_strbuf_printf(s, "disable-shm = %i\n", !!c->disable_shm); 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); @@ -508,6 +581,12 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { #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_NICE + pa_strbuf_printf(s, "rlimit-nice = %li\n", c->rlimit_memlock.is_set ? (long int) c->rlimit_nice.value : -1); +#endif +#ifdef RLIMIT_RTPRIO + pa_strbuf_printf(s, "rlimit-rtprio = %li\n", c->rlimit_memlock.is_set ? (long int) c->rlimit_rtprio.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 4d37861d..b8930bd7 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -26,6 +26,7 @@ ***/ #include +#include #include #ifdef HAVE_SYS_RESOURCE_H @@ -48,29 +49,32 @@ typedef enum pa_daemon_conf_cmd { #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, - scache_idle_time, - auto_log_target, use_pid_file, system_instance, no_cpu_limit, disable_shm; + int exit_idle_time, + module_idle_time, + scache_idle_time, + auto_log_target, + 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; char *config_file; #ifdef HAVE_SYS_RESOURCE_H @@ -81,6 +85,12 @@ typedef struct pa_daemon_conf { #ifdef RLIMIT_MEMLOCK pa_rlimit rlimit_memlock; #endif +#ifdef RLIMIT_NICE + pa_rlimit rlimit_nice; +#endif +#ifdef RLIMIT_RTPRIO + pa_rlimit rlimit_rtprio; +#endif #endif unsigned default_n_fragments, default_fragment_size_msec; diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 2132bf3d..54acd8ea 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -20,42 +20,58 @@ ## 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 +; daemonize = no ## 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 +; fail = yes + +## Renice the daemon to level -15. This a good idea if you experience +## drop-outs 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 on startup, thus it is +## presumably safe. +; high-priority = yes + +## Try to acquire SCHED_FIFO scheduling for the IO threads. The same +## security concerns as mentioned above apply. However, if PA enters +## an endless loop, realtime scheduling causes a system lockup. Thus, +## realtime scheduling should only be enabled on trusted machines for +## now. Please not that only the IO threads of PulseAudio are made +## real-time. The controlling thread is left a normally scheduled +## thread. Thus the enabling the high-priority option is orthogonal. +; realtime-scheduling = no + +## The realtime priority to acquire, if realtime-scheduling is +## enabled. (Note: JACK uses 10 by default, 9 for clients -- some +## PulseAudio threads might choose a priority a little lower or higher +## than this value.) +; realtime-priority = 5 + +## The nice level to acquire for the daemon, if high-priority is +## enabled. (Note: on some distributions X11 uses -10 by default.) +; nice-level = -11 ## Disallow module loading after startup -; disallow-module-loading = 0 +; disallow-module-loading = no ## 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 +## Unload autoloaded modules after being idle for this time ; module-idle-time = 20 -## Unload autoloaded sample cache entries after being idle for this time +## Unload autoloaded sample cache entries after being idle for this time ; 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. +## colons. ; dl-search-path = @PA_DLSEARCHPATH@ ## The default script file to load. Specify an empty string for not -## loading a default script file. The +## loading a default script file. The ; default-script-file = @PA_DEFAULT_CONFIG_FILE@ ## The default log target. Use either "stderr", "syslog" or @@ -63,31 +79,42 @@ ## true, otherwise to "stderr". ; log-target = auto +# Log level, one of debug, info, notice, warning, error. Log messages +# with a lower log level than specified here are not logged, +; log-level = notice + ## 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 +## src-linear, trivial, speex-float-N, speex-fixed-N, ffmpeg. See the +## documentation of libsamplerate for an explanation for the different +## src- methods. The method 'trivial' is the most basic algorithm +## implemented. If you're tight on CPU consider using this. On the +## other hand it has the worst quality of them all. The speex +## resamplers take an integer quality setting in the range 0..9 +## (bad...good). They exist in two flavours: fixed and float. The +## former uses fixed point numbers, the latter relies on floating +## point numbers. On most desktop CPUs the float point resmapler is a +## lot faster, and it also offers slightly better quality. +; resample-method = speex-float-3 ## 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 +; use-pid-file = yes ## Do not install the CPU load limit, even on platforms where it is -## supported. This option is useful when debugging/profiling +## supported. This option is useful when debugging/profiling ## PulseAudio to disable disturbing SIGXCPU signals. -; no-cpu-limit = 0 +; no-cpu-limit = no ## Run the daemon as system-wide instance, requires root priviliges -; system-instance = 0 +; system-instance = no -## Resource limits, see getrlimit(2) for more information +## Resource limits, see getrlimit(2) for more information. Set to -1 +## if PA shouldn't touch the resource limit. Not all resource limits +## are available on all operating systems. ; rlimit-as = -1 ; rlimit-core = -1 ; rlimit-data = -1 @@ -96,9 +123,11 @@ ; rlimit-stack = -1 ; rlimit-nproc = -1 ; rlimit-memlock = 16384 +; rlimit-nice = 31 +; rlimit-rtprio = 9 -## Disable shared memory data transfer -; disable-shm = 0 +## Disable shared memory data transfer +; disable-shm = no ## Default sample format ; default-sample-format = s16le diff --git a/src/daemon/main.c b/src/daemon/main.c index cd3cfcc8..249131e0 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -307,6 +307,12 @@ static void set_all_rlimits(const pa_daemon_conf *conf) { #ifdef RLIMIT_MEMLOCK set_one_rlimit(&conf->rlimit_memlock, RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK"); #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 } #endif -- cgit From 005ed41c3f83430ce936f55378c68f1e29557aeb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Nov 2007 01:42:34 +0000 Subject: save and restore errno in sig handler git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2011 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cpulimit.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index ab212129..b77dd443 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -113,6 +113,9 @@ static void write_err(const char *p) { /* The signal handler, called on every SIGXCPU */ static void signal_handler(int sig) { + int saved_errno; + + saved_errno = errno; pa_assert(sig == SIGXCPU); if (phase == PHASE_IDLE) { @@ -150,6 +153,8 @@ static void signal_handler(int sig) { write_err("Hard CPU time limit exhausted, terminating forcibly.\n"); _exit(1); /* Forced exit */ } + + errno = saved_errno; } /* Callback for IO events on the FIFO */ -- cgit From 41ea3b2fd4fa0a0a4d884ad00e9b3b060082515b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Nov 2007 01:45:01 +0000 Subject: add new option --realtime git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2012 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index 6b7b2671..0c840449 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -49,6 +49,7 @@ enum { ARG_FAIL, ARG_LOG_LEVEL, ARG_HIGH_PRIORITY, + ARG_REALTIME, ARG_DISALLOW_MODULE_LOADING, ARG_EXIT_IDLE_TIME, ARG_MODULE_IDLE_TIME, @@ -79,6 +80,7 @@ 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}, {"exit-idle-time", 2, 0, ARG_EXIT_IDLE_TIME}, {"module-idle-time", 2, 0, ARG_MODULE_IDLE_TIME}, @@ -124,8 +126,12 @@ void pa_cmdline_help(const char *argv0) { " --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" + " --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 loading after startup\n" " --exit-idle-time=SECS Terminate the daemon when idle and this\n" " time passed\n" @@ -224,14 +230,14 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d case ARG_DAEMONIZE: case 'D': - if ((conf->daemonize = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + 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) { + if ((conf->fail = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) { pa_log("--fail expects boolean argument"); goto fail; } @@ -253,21 +259,28 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d break; case ARG_HIGH_PRIORITY: - if ((conf->high_priority = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + 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) { + 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_USE_PID_FILE: - if ((conf->use_pid_file = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + if ((conf->use_pid_file = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) { pa_log("--use-pid-file expects boolean argument"); goto fail; } @@ -311,21 +324,21 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d break; case ARG_SYSTEM: - if ((conf->system_instance = optarg ? pa_parse_boolean(optarg) : 1) < 0) { + 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) : 1) < 0) { + 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) : 1) < 0) { + if ((conf->disable_shm = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) { pa_log("--disable-shm expects boolean argument"); goto fail; } -- cgit From 7bfd1b2f01613dd14b9ca478ae530c1641aa46a1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Nov 2007 02:58:26 +0000 Subject: make rtprio and nice level actually configurable git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2014 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 249131e0..01cbba18 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -419,9 +419,9 @@ int main(int argc, char *argv[]) { pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target, NULL); if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) - pa_raise_priority(); + pa_raise_priority(conf->nice_level); - if (suid_root && (conf->cmd != PA_CMD_DAEMON || !conf->high_priority)) { + if (suid_root && (conf->cmd != PA_CMD_DAEMON || !conf->realtime_scheduling)) { pa_drop_caps(); pa_drop_root(); } @@ -636,7 +636,6 @@ int main(int argc, char *argv[]) { } c->is_system_instance = !!conf->system_instance; - c->high_priority = !!conf->high_priority; c->default_sample_spec = conf->default_sample_spec; c->default_n_fragments = conf->default_n_fragments; c->default_fragment_size_msec = conf->default_fragment_size_msec; @@ -645,6 +644,8 @@ int main(int argc, char *argv[]) { c->module_idle_time = conf->module_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; pa_assert_se(pa_signal_init(pa_mainloop_get_api(mainloop)) == 0); pa_signal_new(SIGINT, signal_callback, c); -- cgit From 81233c178113e92862ac5da77fdfdd2e82a33990 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Nov 2007 11:23:45 +0000 Subject: make disallow-module-loading config option work again (original patch from Diego Petteno) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2015 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 01cbba18..051c323e 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -639,7 +639,6 @@ int main(int argc, char *argv[]) { c->default_sample_spec = conf->default_sample_spec; c->default_n_fragments = conf->default_n_fragments; c->default_fragment_size_msec = conf->default_fragment_size_msec; - 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; @@ -666,7 +665,7 @@ int main(int argc, char *argv[]) { #endif if (conf->daemonize) - c->running_as_daemon = 1; + c->running_as_daemon = TRUE; oil_init(); @@ -682,6 +681,10 @@ int main(int argc, char *argv[]) { pa_log_error("%s", s = pa_strbuf_tostring_free(buf)); pa_xfree(s); + /* We completed the initial module loading, so let's disable it + * from now on, if requested */ + c->disallow_module_loading = !!conf->disallow_module_loading; + if (r < 0 && conf->fail) { pa_log("failed to initialize daemon."); #ifdef HAVE_FORK -- cgit From bff4ca431b0146cb0cbb3935905f50714072a0d9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 5 Nov 2007 15:10:13 +0000 Subject: add a man page for the pulseaudio binary. More will follow. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2023 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index 0c840449..cfd2c841 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -144,7 +144,7 @@ void pa_cmdline_help(const char *argv0) { " --log-target={auto,syslog,stderr} Specify the log target\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" + " --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" -- cgit From a2121d5e6f33b31481a014012b7eef43b8e500db Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 8 Nov 2007 22:31:30 +0000 Subject: strip most comments from the default configuration files, since the man page is now more elaborate and we don't want to maintain those docs redundantly at two places git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2030 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon.conf.in | 87 +++++------------------------------------------ 1 file changed, 8 insertions(+), 79 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 54acd8ea..f15d93e8 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -17,104 +17,38 @@ # 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 +## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for +## more information. Default values a commented out. Use either ; or # for +## commenting. -## Daemonize after startup ; daemonize = no - -## Quit if startup fails ; fail = yes +; disallow-module-loading = no +; use-pid-file = yes +; system-instance = no +; disable-shm = no -## Renice the daemon to level -15. This a good idea if you experience -## drop-outs 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 on startup, thus it is -## presumably safe. ; high-priority = yes +; nice-level = -11 -## Try to acquire SCHED_FIFO scheduling for the IO threads. The same -## security concerns as mentioned above apply. However, if PA enters -## an endless loop, realtime scheduling causes a system lockup. Thus, -## realtime scheduling should only be enabled on trusted machines for -## now. Please not that only the IO threads of PulseAudio are made -## real-time. The controlling thread is left a normally scheduled -## thread. Thus the enabling the high-priority option is orthogonal. ; realtime-scheduling = no - -## The realtime priority to acquire, if realtime-scheduling is -## enabled. (Note: JACK uses 10 by default, 9 for clients -- some -## PulseAudio threads might choose a priority a little lower or higher -## than this value.) ; realtime-priority = 5 -## The nice level to acquire for the daemon, if high-priority is -## enabled. (Note: on some distributions X11 uses -10 by default.) -; nice-level = -11 - -## Disallow module loading after startup -; disallow-module-loading = no - -## 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 ; 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@ -## 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@ -## 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, one of debug, info, notice, warning, error. Log messages -# with a lower log level than specified here are not logged, ; log-level = notice -## 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, speex-float-N, speex-fixed-N, ffmpeg. See the -## documentation of libsamplerate for an explanation for the different -## src- methods. The method 'trivial' is the most basic algorithm -## implemented. If you're tight on CPU consider using this. On the -## other hand it has the worst quality of them all. The speex -## resamplers take an integer quality setting in the range 0..9 -## (bad...good). They exist in two flavours: fixed and float. The -## former uses fixed point numbers, the latter relies on floating -## point numbers. On most desktop CPUs the float point resmapler is a -## lot faster, and it also offers slightly better quality. ; resample-method = speex-float-3 -## 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 = yes - -## Do not install the CPU load limit, even on platforms where it is -## supported. This option is useful when debugging/profiling -## PulseAudio to disable disturbing SIGXCPU signals. ; no-cpu-limit = no -## Run the daemon as system-wide instance, requires root priviliges -; system-instance = no - -## Resource limits, see getrlimit(2) for more information. Set to -1 -## if PA shouldn't touch the resource limit. Not all resource limits -## are available on all operating systems. ; rlimit-as = -1 ; rlimit-core = -1 ; rlimit-data = -1 @@ -126,14 +60,9 @@ ; rlimit-nice = 31 ; rlimit-rtprio = 9 -## Disable shared memory data transfer -; disable-shm = no - -## Default sample format ; default-sample-format = s16le ; default-sample-rate = 44100 ; default-sample-channels = 2 -## Default fragment settings, for device drivers that need this ; default-fragments = 4 ; default-fragment-size-msec = 25 -- cgit From e313fe1b3d0d9f9945c41c151d72edbe9cf1ec54 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 18:25:40 +0000 Subject: tag modules that may only be loaded once at most especially, and enforce that in the module loader git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/dumpmodules.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/daemon') diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c index ad7fab20..68236c70 100644 --- a/src/daemon/dumpmodules.c +++ b/src/daemon/dumpmodules.c @@ -71,6 +71,7 @@ static void long_info(const char *name, const char *path, pa_modinfo *i) { printf("Author: %s\n", i->author); if (i->usage) printf("Usage: %s\n", i->usage); + printf("Load Once: %s\n", pa_yes_no(i->load_once)); } if (path) -- cgit From 15f56de8f2a10e092e11dfa3fc48ee28d2dd7e25 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 13 Nov 2007 19:39:23 +0000 Subject: don't touch RLIMIT:MEMBLOCK by default. This should improve out-of-the-box comaptibility with JACK git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2052 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 2 +- src/daemon/daemon.conf.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 089b12fc..3d63891c 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -90,7 +90,7 @@ static const pa_daemon_conf default_conf = { , .rlimit_nproc = { .value = 0, .is_set = FALSE } #endif #ifdef RLIMIT_MEMLOCK - , .rlimit_memlock = { .value = 16384, .is_set = TRUE } + , .rlimit_memlock = { .value = 0, .is_set = FALSE } #endif #ifdef RLIMIT_NICE , .rlimit_nice = { .value = 31, .is_set = TRUE } /* nice level of -11 */ diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index f15d93e8..8d224e82 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -56,7 +56,7 @@ ; rlimit-nofile = 256 ; rlimit-stack = -1 ; rlimit-nproc = -1 -; rlimit-memlock = 16384 +; rlimit-memlock = -1 ; rlimit-nice = 31 ; rlimit-rtprio = 9 -- cgit From 8bdad297e3aaeb7443a92aecd3cd26dbd47a421e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 16 Nov 2007 23:46:22 +0000 Subject: add interface to PolicyKit git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2060 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/PulseAudio.policy | 49 ++++++++++ src/daemon/polkit.c | 223 +++++++++++++++++++++++++++++++++++++++++++ src/daemon/polkit.h | 29 ++++++ 3 files changed, 301 insertions(+) create mode 100644 src/daemon/PulseAudio.policy create mode 100644 src/daemon/polkit.c create mode 100644 src/daemon/polkit.h (limited to 'src/daemon') diff --git a/src/daemon/PulseAudio.policy b/src/daemon/PulseAudio.policy new file mode 100644 index 00000000..55ebbf9c --- /dev/null +++ b/src/daemon/PulseAudio.policy @@ -0,0 +1,49 @@ + + + + + + + + + + + Real-time scheduling for the PulseAudio daemon + System policy prevents PulseAudio from acquiring real-time scheduling. + + no + no + auth_admin_keep_always + + + + + High-priority scheduling (negative Unix nice level) for the PulseAudio daemon + System policy prevents PulseAudio from acquiring high-priority scheduling. + + no + no + auth_admin_keep_always + + + + diff --git a/src/daemon/polkit.c b/src/daemon/polkit.c new file mode 100644 index 00000000..362c5194 --- /dev/null +++ b/src/daemon/polkit.c @@ -0,0 +1,223 @@ +/* $Id$ */ + +/*** + This file is part of PulseAudio. + + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, + 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 +#endif + +#include +#include +#include + +#include +#include + +#include +#include + +#include "polkit.h" + +static pa_bool_t show_grant_dialog(const char *action_id) { + DBusError dbus_error; + DBusConnection *bus = NULL; + DBusMessage *m = NULL, *reply = NULL; + pa_bool_t r = FALSE; + uint32_t xid = 0; + int verdict; + + dbus_error_init(&dbus_error); + + if (!(bus = dbus_bus_get(DBUS_BUS_SESSION, &dbus_error))) { + pa_log_error("Cannot connect to session bus: %s", dbus_error.message); + goto finish; + } + + if (!(m = dbus_message_new_method_call("org.gnome.PolicyKit", "/org/gnome/PolicyKit/Manager", "org.gnome.PolicyKit.Manager", "ShowDialog"))) { + pa_log_error("Failed to allocate D-Bus message."); + goto finish; + } + + if (!(dbus_message_append_args(m, DBUS_TYPE_STRING, &action_id, DBUS_TYPE_UINT32, &xid, DBUS_TYPE_INVALID))) { + pa_log_error("Failed to append arguments to D-Bus message."); + goto finish; + } + + if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &dbus_error))) { + pa_log_warn("Failed to show grant dialog: %s", dbus_error.message); + goto finish; + } + + if (!(dbus_message_get_args(reply, &dbus_error, DBUS_TYPE_BOOLEAN, &verdict, DBUS_TYPE_INVALID))) { + pa_log_warn("Malformed response from grant manager: %s", dbus_error.message); + goto finish; + } + + r = !!verdict; + +finish: + + if (bus) + dbus_connection_unref(bus); + + dbus_error_free(&dbus_error); + + if (m) + dbus_message_unref(m); + + if (reply) + dbus_message_unref(reply); + + return r; +} + +int pa_polkit_check(const char *action_id) { + int ret = -1; + DBusError dbus_error; + DBusConnection *bus = NULL; + PolKitCaller *caller = NULL; + PolKitAction *action = NULL; + PolKitContext *context = NULL; + PolKitError *polkit_error = NULL; + PolKitSession *session = NULL; + PolKitResult polkit_result; + + dbus_error_init(&dbus_error); + + if (!(bus = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error))) { + pa_log_error("Cannot connect to system bus: %s", dbus_error.message); + goto finish; + } + + if (!(caller = polkit_caller_new_from_pid(bus, getpid(), &dbus_error))) { + pa_log_error("Cannot get caller from PID: %s", dbus_error.message); + goto finish; + } + + /* This function is called when PulseAudio is called SUID root. We + * want to authenticate the real user that called us and not the + * effective user we gained through being SUID root. Hence we + * overwrite the UID caller data here explicitly, just for + * paranoia. In fact PolicyKit should fill in the UID here anyway + * -- an not the EUID or any other user id. */ + + if (!(polkit_caller_set_uid(caller, getuid()))) { + pa_log_error("Cannot set UID on caller object."); + goto finish; + } + + if (!(polkit_caller_get_ck_session(caller, &session))) { + pa_log_error("Failed to get CK session."); + goto finish; + } + + /* We need to overwrite the UID in both the caller and the session + * object */ + + if (!(polkit_session_set_uid(session, getuid()))) { + pa_log_error("Cannot set UID on session object."); + goto finish; + } + + if (!(action = polkit_action_new())) { + pa_log_error("Cannot allocate PolKitAction."); + goto finish; + } + + if (!polkit_action_set_action_id(action, action_id)) { + pa_log_error("Cannot set action_id"); + goto finish; + } + + if (!(context = polkit_context_new())) { + pa_log_error("Cannot allocate PolKitContext."); + goto finish; + } + + if (!polkit_context_init(context, &polkit_error)) { + pa_log_error("Cannot initialize PolKitContext: %s", polkit_error_get_error_message(polkit_error)); + goto finish; + } + + for (;;) { + +#ifdef HAVE_POLKIT_CONTEXT_IS_CALLER_AUTHORIZED + polkit_result = polkit_context_is_caller_authorized(context, action, caller, TRUE, &polkit_error); + + if (polkit_error_is_set(polkit_error)) { + pa_log_error("Could not determine whether caller is authorized: %s", polkit_error_get_error_message(polkit_error)); + goto finish; + } +#else + + polkit_result = polkit_context_can_caller_do_action(context, action, caller); + +#endif + + if (polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH || + polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_SESSION || + polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_ALWAYS || +#ifdef POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT + polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT || +#endif + polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH || + polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION || + polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS +#ifdef POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT + || polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT +#endif + ) { + + if (show_grant_dialog(action_id)) + continue; + } + + break; + } + + if (polkit_result != POLKIT_RESULT_YES && polkit_result != POLKIT_RESULT_NO) + pa_log_warn("PolicyKit responded with '%s'", polkit_result_to_string_representation(polkit_result)); + + ret = polkit_result == POLKIT_RESULT_YES; + +finish: + + if (caller) + polkit_caller_unref(caller); + + if (action) + polkit_action_unref(action); + + if (context) + polkit_context_unref(context); + + if (bus) + dbus_connection_unref(bus); + + dbus_error_free(&dbus_error); + + if (polkit_error) + polkit_error_free(polkit_error); + + return ret; +} diff --git a/src/daemon/polkit.h b/src/daemon/polkit.h new file mode 100644 index 00000000..cbcf6a6a --- /dev/null +++ b/src/daemon/polkit.h @@ -0,0 +1,29 @@ +#ifndef foopolkithfoo +#define foopolkithfoo + +/* $Id$ */ + +/*** + This file is part of PulseAudio. + + Copyright 2007 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, + 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. +***/ + +int pa_polkit_check(const char *action); + +#endif -- cgit From 14a9b80afbb0bddc216462b72156f14e032e1b5e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 21 Nov 2007 01:30:40 +0000 Subject: - Check process name when dealing with PID files - Add new PA_STREAM_FIX_CHANNELS, FIX_RATE, FIX_FORMAT, DONT_MOVE, VARIABLE_RATES to pa_sream_flags_t adn implement it - Expose those flags in pacat - Add notifications about device suspend/resume to the protocol and expose them in libpulse - Allow changing of buffer_attr during playback - allow disabling for remixing globally - hookup polkit support git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2067 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/daemon-conf.c | 24 ++++--- src/daemon/daemon-conf.h | 3 +- src/daemon/daemon.conf.in | 1 + src/daemon/main.c | 169 +++++++++++++++++++++++++++++++++++----------- 4 files changed, 146 insertions(+), 51 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 3d63891c..c98c0218 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -71,6 +71,7 @@ static const pa_daemon_conf default_conf = { .log_target = PA_LOG_SYSLOG, .log_level = PA_LOG_NOTICE, .resample_method = PA_RESAMPLER_AUTO, + .disable_remixing = FALSE, .config_file = NULL, .use_pid_file = TRUE, .system_instance = FALSE, @@ -410,6 +411,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "default-fragments", parse_fragments, NULL }, { "default-fragment-size-msec", parse_fragment_size_msec, NULL }, { "nice-level", parse_nice_level, NULL }, + { "disable-remixing", pa_config_parse_bool, NULL }, #ifdef HAVE_SYS_RESOURCE_H { "rlimit-as", parse_rlimit, NULL }, { "rlimit-core", parse_rlimit, NULL }, @@ -458,33 +460,34 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { table[22].data = c; table[23].data = c; table[24].data = c; + table[25].data = &c->disable_remixing; #ifdef HAVE_SYS_RESOURCE_H - table[25].data = &c->rlimit_as; - table[26].data = &c->rlimit_core; - table[27].data = &c->rlimit_data; - table[28].data = &c->rlimit_fsize; - table[29].data = &c->rlimit_nofile; - table[30].data = &c->rlimit_stack; + table[26].data = &c->rlimit_as; + table[27].data = &c->rlimit_core; + table[28].data = &c->rlimit_data; + table[29].data = &c->rlimit_fsize; + table[30].data = &c->rlimit_nofile; + table[31].data = &c->rlimit_stack; #ifdef RLIMIT_NPROC - table[31].data = &c->rlimit_nproc; + table[32].data = &c->rlimit_nproc; #endif #ifdef RLIMIT_MEMLOCK #ifndef RLIMIT_NPROC #error "Houston, we have a numbering problem!" #endif - table[32].data = &c->rlimit_memlock; + table[33].data = &c->rlimit_memlock; #endif #ifdef RLIMIT_NICE #ifndef RLIMIT_MEMLOCK #error "Houston, we have a numbering problem!" #endif - table[33].data = &c->rlimit_nice; + table[34].data = &c->rlimit_nice; #endif #ifdef RLIMIT_RTPRIO #ifndef RLIMIT_NICE #error "Houston, we have a numbering problem!" #endif - table[34].data = &c->rlimit_rtprio; + table[35].data = &c->rlimit_rtprio; #endif #endif @@ -563,6 +566,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { 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, "disable-remixing = %s\n", pa_yes_no(c->disable_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); diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index b8930bd7..3dcafbfe 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -64,7 +64,8 @@ typedef struct pa_daemon_conf { use_pid_file, system_instance, no_cpu_limit, - disable_shm; + disable_shm, + disable_remixing; int exit_idle_time, module_idle_time, scache_idle_time, diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index 8d224e82..d664962e 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -46,6 +46,7 @@ ; log-level = notice ; resample-method = speex-float-3 +; disable-remixing = no ; no-cpu-limit = no diff --git a/src/daemon/main.c b/src/daemon/main.c index 051c323e..236819e1 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -94,6 +94,7 @@ #include "dumpmodules.h" #include "caps.h" #include "ltdl-bind-now.h" +#include "polkit.h" #ifdef HAVE_LIBWRAP /* Only one instance of these variables */ @@ -281,17 +282,21 @@ static int create_runtime_dir(void) { #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; pa_assert(r); if (!r->is_set) - return; + return 0; rl.rlim_cur = rl.rlim_max = r->value; - if (setrlimit(resource, &rl) < 0) + if (setrlimit(resource, &rl) < 0) { pa_log_warn("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) { @@ -324,9 +329,10 @@ int main(int argc, char *argv[]) { char *s; int r = 0, retval = 1, d = 0; int daemon_pipe[2] = { -1, -1 }; - int suid_root, real_root; + pa_bool_t suid_root, real_root; int valid_pid_file = 0; gid_t gid = (gid_t) -1; + pa_bool_t allow_realtime, allow_high_priority; #ifdef OS_IS_WIN32 pa_time_event *timer; @@ -357,8 +363,8 @@ int main(int argc, char *argv[]) { real_root = getuid() == 0; suid_root = !real_root && geteuid() == 0; #else - real_root = 0; - suid_root = 0; + real_root = FALSE; + suid_root = FALSE; #endif if (suid_root) { @@ -377,29 +383,12 @@ int main(int argc, char *argv[]) { * is just too risky tun let PA run as root all the time. */ } - setlocale(LC_ALL, ""); - - if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0)) { - pa_log_info("Warning: Called SUID root, but not in group '"PA_REALTIME_GROUP"'. " - "For enabling real-time scheduling please become a member of '"PA_REALTIME_GROUP"' , or increase the RLIMIT_RTPRIO user limit."); - pa_drop_caps(); - pa_drop_root(); - suid_root = real_root = 0; - } - - LTDL_SET_PRELOADED_SYMBOLS(); - - pa_ltdl_init(); - -#ifdef OS_IS_WIN32 - { - WSADATA data; - WSAStartup(MAKEWORD(2, 0), &data); - } -#endif - - pa_random_seed(); + /* At this point, we are a normal user, possibly with CAP_NICE if + * we were started SUID. If we are started as normal root, than we + * still are normal root. */ + setlocale(LC_ALL, ""); + pa_log_set_maximal_level(PA_LOG_INFO); pa_log_set_ident("pulseaudio"); conf = pa_daemon_conf_new(); @@ -411,24 +400,123 @@ int main(int argc, char *argv[]) { goto finish; if (pa_cmdline_parse(conf, argc, argv, &d) < 0) { - pa_log("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); + if (suid_root) { + /* Ok, we're suid root, so let's better not enable high prio + * or RT by default */ + + allow_high_priority = allow_realtime = FALSE; + +#ifdef HAVE_POLKIT + if (conf->high_priority) { + if (pa_polkit_check("org.pulseaudio.acquire-high-priority") > 0) { + pa_log_info("PolicyKit grants us acquire-high-priority privilige."); + allow_high_priority = TRUE; + } else + pa_log_info("PolicyKit refuses acquire-high-priority privilige."); + } + + if (conf->realtime_scheduling) { + if (pa_polkit_check("org.pulseaudio.acquire-real-time") > 0) { + pa_log_info("PolicyKit grants us acquire-real-time privilige."); + allow_realtime = TRUE; + } else + pa_log_info("PolicyKit refuses acquire-real-time privilige."); + } +#endif + + if ((conf->high_priority || conf->realtime_scheduling) && pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) > 0) { + pa_log_info("We're in the group '"PA_REALTIME_GROUP"', allowing real-time and high-priority scheduling."); + allow_realtime = conf->realtime_scheduling; + allow_high_priority = conf->high_priority; + } + + if (!allow_high_priority && !allow_realtime) { + + /* OK, there's no further need to keep CAP_NICE. Hence + * let's give it up early */ + + pa_drop_caps(); + pa_drop_root(); + suid_root = real_root = FALSE; + + if (conf->high_priority || conf->realtime_scheduling) + pa_log_notice("Called SUID root and real-time/high-priority scheduling was requested in the configuration. However, we lack the necessary priviliges:\n" + "We are not in group '"PA_REALTIME_GROUP"' and PolicyKit refuse to grant us priviliges. Dropping SUID again.\n" + "For enabling real-time scheduling please acquire the appropriate PolicyKit priviliges, or become a member of '"PA_REALTIME_GROUP"', or increase the RLIMIT_NICE/RLIMIT_RTPRIO resource limits for this user."); + } + + } else { + + /* OK, we're a normal user, so let's allow the user evrything + * he asks for, it's now the kernel's job to enforce limits, + * not ours anymore */ + allow_high_priority = allow_realtime = TRUE; + } + + if (conf->high_priority && !allow_high_priority) { + pa_log_info("High-priority scheduling enabled in configuration but now allowed by policy. Disabling forcibly."); + conf->high_priority = FALSE; + } + + if (conf->realtime_scheduling && !allow_realtime) { + pa_log_info("Real-time scheduling enabled in configuration but now allowed by policy. Disabling forcibly."); + conf->realtime_scheduling = FALSE; + } + if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) pa_raise_priority(conf->nice_level); - if (suid_root && (conf->cmd != PA_CMD_DAEMON || !conf->realtime_scheduling)) { - pa_drop_caps(); - pa_drop_root(); + if (suid_root) { + pa_bool_t drop; + + drop = conf->cmd != PA_CMD_DAEMON || !conf->realtime_scheduling; + +#ifdef RLIMIT_RTPRIO + if (!drop) { + + /* At this point we still have CAP_NICE if we were loaded + * SUID root. If possible let's acquire RLIMIT_RTPRIO + * instead and give CAP_NICE up. */ + + const pa_rlimit rl = { 9, TRUE }; + + if (set_one_rlimit(&rl, RLIMIT_RTPRIO, "RLIMIT_RTPRIO") >= 0) { + pa_log_info("Successfully increased RLIMIT_RTPRIO, giving up CAP_NICE."); + drop = TRUE; + } else + pa_log_warn("RLIMIT_RTPRIO failed: %s", pa_cstrerror(errno)); + } +#endif + + if (drop) { + pa_drop_caps(); + pa_drop_root(); + suid_root = real_root = FALSE; + } } + LTDL_SET_PRELOADED_SYMBOLS(); + pa_ltdl_init(); + 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); @@ -466,10 +554,10 @@ int main(int argc, char *argv[]) { case PA_CMD_CHECK: { pid_t pid; - if (pa_pid_file_check_running(&pid) < 0) { - pa_log_info("daemon not running"); - } else { - pa_log_info("daemon running as PID %u", pid); + 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; } @@ -478,8 +566,8 @@ int main(int argc, char *argv[]) { } case PA_CMD_KILL: - if (pa_pid_file_kill(SIGINT, NULL) < 0) - pa_log("failed to kill daemon."); + if (pa_pid_file_kill(SIGINT, NULL, "pulseaudio") < 0) + pa_log("Failed to kill daemon."); else retval = 0; @@ -496,9 +584,9 @@ int main(int argc, char *argv[]) { pa_assert(conf->cmd == PA_CMD_DAEMON); } - if (real_root && !conf->system_instance) { + if (real_root && !conf->system_instance) pa_log_warn("This program is not intended to be run as root (unless --system is specified)."); - } else if (!real_root && conf->system_instance) { + else if (!real_root && conf->system_instance) { pa_log("Root priviliges required."); goto finish; } @@ -645,6 +733,7 @@ int main(int argc, char *argv[]) { c->resample_method = conf->resample_method; c->realtime_priority = conf->realtime_priority; c->realtime_scheduling = !!conf->realtime_scheduling; + c->disable_remixing = !!conf->disable_remixing; pa_assert_se(pa_signal_init(pa_mainloop_get_api(mainloop)) == 0); pa_signal_new(SIGINT, signal_callback, c); -- cgit From be4c0f296cecb6cfdcf38ff6151bedfa3206a5bb Mon Sep 17 00:00:00 2001 From: Diego Petteno Date: Thu, 24 Jan 2008 09:35:50 +0000 Subject: Apply the fix for CVE-2008-0008 from 0.9.9 release on trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2102 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/caps.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/caps.c b/src/daemon/caps.c index 5b4008a5..44ee355e 100644 --- a/src/daemon/caps.c +++ b/src/daemon/caps.c @@ -63,13 +63,16 @@ void pa_drop_root(void) { pa_log_info("Dropping root priviliges."); #if defined(HAVE_SETRESUID) - setresuid(uid, uid, uid); + pa_assert_se(setresuid(uid, uid, uid) >= 0); #elif defined(HAVE_SETREUID) - setreuid(uid, uid); + pa_assert_se(setreuid(uid, uid) >= 0); #else - setuid(uid); - seteuid(uid); + pa_assert_se(setuid(uid) >= 0); + pa_assert_se(seteuid(uid) >= 0); #endif + + pa_assert_se(getuid() == uid); + pa_assert_se(geteuid() == uid); } #else @@ -147,4 +150,3 @@ int pa_drop_caps(void) { } #endif - -- cgit From a3e820fca7e264037adf525a8af8894190f25ec7 Mon Sep 17 00:00:00 2001 From: Diego Petteno Date: Thu, 24 Jan 2008 11:12:29 +0000 Subject: Mark long_options constant. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2104 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/cmdline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index cfd2c841..f1e1282c 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -70,7 +70,7 @@ enum { }; /* 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}, -- cgit From 0a807b3c4b6f5cd3fa253e0d39a5da5f7e2e4414 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Feb 2008 13:13:12 +0000 Subject: print pa version id each time we start up, so that it is easier to identify the version people are reporting bugs again git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2107 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index 236819e1..acc2f028 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -596,13 +596,13 @@ int main(int argc, char *argv[]) { int tty_fd; if (pa_stdio_acquire() < 0) { - pa_log("failed to acquire stdio."); + pa_log("Failed to acquire stdio."); goto finish; } #ifdef HAVE_FORK if (pipe(daemon_pipe) < 0) { - pa_log("failed to create pipe."); + pa_log("Failed to create pipe."); goto finish; } @@ -704,6 +704,7 @@ int main(int argc, char *argv[]) { signal(SIGPIPE, SIG_IGN); #endif + pa_log_info("This is PulseAudio " PACKAGE_VERSION); pa_log_info("Page size is %lu bytes", (unsigned long) PA_PAGE_SIZE); if (pa_rtclock_hrtimer()) -- cgit From dc3682d3f7861cabf3f58f96575d5893cdda3e0a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Feb 2008 18:03:11 +0000 Subject: only call pa_ltdl_done() if we called pa_ltdl_init() before git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2111 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/main.c b/src/daemon/main.c index acc2f028..7823180a 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -333,6 +333,7 @@ int main(int argc, char *argv[]) { int valid_pid_file = 0; gid_t gid = (gid_t) -1; pa_bool_t allow_realtime, allow_high_priority; + pa_bool_t ltdl_init = FALSE; #ifdef OS_IS_WIN32 pa_time_event *timer; @@ -504,6 +505,7 @@ int main(int argc, char *argv[]) { LTDL_SET_PRELOADED_SYMBOLS(); pa_ltdl_init(); + ltdl_init = TRUE; if (conf->dl_search_path) lt_dlsetsearchpath(conf->dl_search_path); @@ -837,7 +839,8 @@ finish: WSACleanup(); #endif - pa_ltdl_done(); + if (ltdl_init) + pa_ltdl_done(); #ifdef HAVE_DBUS dbus_shutdown(); -- cgit From 9ad7bb6188a6e3f01ae105473ad822ab81246627 Mon Sep 17 00:00:00 2001 From: Diego Petteno Date: Sat, 8 Mar 2008 23:30:08 +0000 Subject: Build and run using libltdl from libtool 2.2. The user module loader support has changed drastically. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2113 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/ltdl-bind-now.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c index 6025c6e3..d569fea8 100644 --- a/src/daemon/ltdl-bind-now.c +++ b/src/daemon/ltdl-bind-now.c @@ -34,6 +34,11 @@ #include #endif +#ifndef HAVE_LT_USER_DLLOADER +/* Only used with ltdl 2.2 */ +#include +#endif + #include #include @@ -85,7 +90,11 @@ static const char *libtool_get_error(void) { to set $LT_BIND_NOW before starting the pulsaudio binary. */ +#ifndef HAVE_LT_DLADVISE static lt_module bind_now_open(lt_user_data d, const char *fname) { +#else + static lt_module bind_now_open(lt_user_data d, const char *fname, lt_dladvise advise) { +#endif lt_module m; pa_assert(fname); @@ -129,19 +138,27 @@ static lt_ptr bind_now_find_sym(lt_user_data d, lt_module m, const char *symbol) void pa_ltdl_init(void) { #ifdef PA_BIND_NOW +# ifdef HAVE_LT_USER_DLLOADER lt_dlloader *place; static const struct lt_user_dlloader loader = { .module_open = bind_now_open, .module_close = bind_now_close, .find_sym = bind_now_find_sym }; +# else + static const lt_dlvtable *dlopen_loader; + static lt_dlvtable bindnow_loader; +# endif #endif pa_assert_se(lt_dlinit() == 0); pa_assert_se(libtool_mutex = pa_mutex_new(TRUE, FALSE)); +#ifdef HAVE_LT_DLMUTEX_REGISTER pa_assert_se(lt_dlmutex_register(libtool_lock, libtool_unlock, libtool_set_error, libtool_get_error) == 0); +#endif #ifdef PA_BIND_NOW +# ifdef HAVE_LT_USER_DLLOADER if (!(place = lt_dlloader_find("dlopen"))) place = lt_dlloader_next(NULL); @@ -149,6 +166,26 @@ void pa_ltdl_init(void) { /* Add our BIND_NOW loader as the default module loader. */ if (lt_dlloader_add(place, &loader, "bind-now-loader") != 0) pa_log_warn("Failed to add bind-now-loader."); +# else + /* Already initialised */ + if ( dlopen_loader != NULL ) return; + + if (!(dlopen_loader = lt_dlloader_find("dlopen"))) { + pa_log_warn("Failed to find original dlopen 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."); +# endif #endif } -- cgit From 30e2a773d4e92ebe93ac1a21f481de9631fcc2a1 Mon Sep 17 00:00:00 2001 From: Diego Petteno Date: Sun, 9 Mar 2008 12:54:45 +0000 Subject: Test for _struct_ lt_user_dlloader, otherwise it won't be found. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2114 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/ltdl-bind-now.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c index d569fea8..ea46593d 100644 --- a/src/daemon/ltdl-bind-now.c +++ b/src/daemon/ltdl-bind-now.c @@ -138,7 +138,7 @@ static lt_ptr bind_now_find_sym(lt_user_data d, lt_module m, const char *symbol) void pa_ltdl_init(void) { #ifdef PA_BIND_NOW -# ifdef HAVE_LT_USER_DLLOADER +# ifdef HAVE_STRUCT_LT_USER_DLLOADER lt_dlloader *place; static const struct lt_user_dlloader loader = { .module_open = bind_now_open, @@ -158,7 +158,7 @@ void pa_ltdl_init(void) { #endif #ifdef PA_BIND_NOW -# ifdef HAVE_LT_USER_DLLOADER +# ifdef HAVE_STRUCT_LT_USER_DLLOADER if (!(place = lt_dlloader_find("dlopen"))) place = lt_dlloader_next(NULL); -- cgit From 666b952218847a086504f2c8b5fbc0b147d44896 Mon Sep 17 00:00:00 2001 From: Diego Petteno Date: Sun, 9 Mar 2008 12:55:21 +0000 Subject: And one more. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2115 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/ltdl-bind-now.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon') diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c index ea46593d..6915fe0c 100644 --- a/src/daemon/ltdl-bind-now.c +++ b/src/daemon/ltdl-bind-now.c @@ -34,7 +34,7 @@ #include #endif -#ifndef HAVE_LT_USER_DLLOADER +#ifndef HAVE_STRUCT_LT_USER_DLLOADER /* Only used with ltdl 2.2 */ #include #endif -- cgit From 70d00833f1492e4333546083ce91990d3109434a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Mar 2008 13:28:46 +0000 Subject: change policy file to not show polkit auth dlg by default git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2116 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/daemon/PulseAudio.policy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/PulseAudio.policy b/src/daemon/PulseAudio.policy index 55ebbf9c..cf9499ee 100644 --- a/src/daemon/PulseAudio.policy +++ b/src/daemon/PulseAudio.policy @@ -32,7 +32,7 @@ USA. no no - auth_admin_keep_always + no @@ -42,7 +42,7 @@ USA. no no - auth_admin_keep_always + no -- cgit