]> code.delx.au - pulseaudio/blobdiff - src/daemon/daemon-conf.c
Make sure parse_rlimit is only used when rlimits are supported.
[pulseaudio] / src / daemon / daemon-conf.c
index d1afed7b1ad5bb7f043cc4e9dc08ee4a4eddb7c4..7184b2e60c0db6b944a02036855b81ba5b4e4989 100644 (file)
 
 #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_USER ".pulse" PATH_SEP "default.pa"
-#define DEFAULT_CONFIG_FILE DEFAULT_CONFIG_DIR PATH_SEP "daemon.conf"
-#define DEFAULT_CONFIG_FILE_USER ".pulse" PATH_SEP "daemon.conf"
+#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 ENV_SCRIPT_FILE "PULSE_SCRIPT"
 #define ENV_CONFIG_FILE "PULSE_CONFIG"
@@ -79,7 +71,22 @@ 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
+#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) {
@@ -89,9 +96,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;
 }
 
@@ -193,6 +198,34 @@ 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) {
+#ifdef HAVE_SYS_RESOURCE_H
+    struct 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;
+    }
+#else
+    pa_log_warning(__FILE__": [%s:%u] rlimit not supported on this platform.", filename, line);
+#endif
+
+    return 0;
+}
+
 int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
     int r = -1;
     FILE *f = NULL;
@@ -212,6 +245,21 @@ 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 },
+#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 },
     };
     
@@ -229,6 +277,25 @@ 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;
+#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;
@@ -295,6 +362,21 @@ 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);
+#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);
 }