]> code.delx.au - pulseaudio/blob - src/daemon/daemon-conf.c
add i18n support
[pulseaudio] / src / daemon / daemon-conf.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <errno.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <sched.h>
32
33 #include <pulse/xmalloc.h>
34 #include <pulse/timeval.h>
35 #include <pulse/i18n.h>
36
37 #include <pulsecore/core-error.h>
38 #include <pulsecore/core-util.h>
39 #include <pulsecore/strbuf.h>
40 #include <pulsecore/conf-parser.h>
41 #include <pulsecore/resampler.h>
42 #include <pulsecore/macro.h>
43
44 #include "daemon-conf.h"
45
46 #define DEFAULT_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "default.pa"
47 #define DEFAULT_SCRIPT_FILE_USER PA_PATH_SEP "default.pa"
48 #define DEFAULT_SYSTEM_SCRIPT_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "system.pa"
49
50 #define DEFAULT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "daemon.conf"
51 #define DEFAULT_CONFIG_FILE_USER PA_PATH_SEP "daemon.conf"
52
53 #define ENV_SCRIPT_FILE "PULSE_SCRIPT"
54 #define ENV_CONFIG_FILE "PULSE_CONFIG"
55 #define ENV_DL_SEARCH_PATH "PULSE_DLPATH"
56
57 static const pa_daemon_conf default_conf = {
58 .cmd = PA_CMD_DAEMON,
59 .daemonize = FALSE,
60 .fail = TRUE,
61 .high_priority = TRUE,
62 .nice_level = -11,
63 .realtime_scheduling = FALSE,
64 .realtime_priority = 5, /* Half of JACK's default rtprio */
65 .disallow_module_loading = FALSE,
66 .exit_idle_time = 20,
67 .module_idle_time = 20,
68 .scache_idle_time = 20,
69 .auto_log_target = 1,
70 .script_commands = NULL,
71 .dl_search_path = NULL,
72 .load_default_script_file = TRUE,
73 .default_script_file = NULL,
74 .log_target = PA_LOG_SYSLOG,
75 .log_level = PA_LOG_NOTICE,
76 .resample_method = PA_RESAMPLER_AUTO,
77 .disable_remixing = FALSE,
78 .config_file = NULL,
79 .use_pid_file = TRUE,
80 .system_instance = FALSE,
81 .no_cpu_limit = FALSE,
82 .disable_shm = FALSE,
83 .default_n_fragments = 4,
84 .default_fragment_size_msec = 25,
85 .default_sample_spec = { .format = PA_SAMPLE_S16NE, .rate = 44100, .channels = 2 }
86 #ifdef HAVE_SYS_RESOURCE_H
87 ,.rlimit_fsize = { .value = 0, .is_set = FALSE },
88 .rlimit_data = { .value = 0, .is_set = FALSE },
89 .rlimit_stack = { .value = 0, .is_set = FALSE },
90 .rlimit_core = { .value = 0, .is_set = FALSE },
91 .rlimit_rss = { .value = 0, .is_set = FALSE }
92 #ifdef RLIMIT_NPROC
93 ,.rlimit_nproc = { .value = 0, .is_set = FALSE }
94 #endif
95 ,.rlimit_nofile = { .value = 256, .is_set = TRUE }
96 #ifdef RLIMIT_MEMLOCK
97 ,.rlimit_memlock = { .value = 0, .is_set = FALSE }
98 #endif
99 ,.rlimit_as = { .value = 0, .is_set = FALSE }
100 #ifdef RLIMIT_LOCKS
101 ,.rlimit_locks = { .value = 0, .is_set = FALSE }
102 #endif
103 #ifdef RLIMIT_SIGPENDING
104 ,.rlimit_sigpending = { .value = 0, .is_set = FALSE }
105 #endif
106 #ifdef RLIMIT_MSGQUEUE
107 ,.rlimit_msgqueue = { .value = 0, .is_set = FALSE }
108 #endif
109 #ifdef RLIMIT_NICE
110 ,.rlimit_nice = { .value = 31, .is_set = TRUE } /* nice level of -11 */
111 #endif
112 #ifdef RLIMIT_RTPRIO
113 ,.rlimit_rtprio = { .value = 9, .is_set = TRUE } /* One below JACK's default for the server */
114 #endif
115 #ifdef RLIMIT_RTTIME
116 ,.rlimit_rttime = { .value = PA_USEC_PER_SEC, .is_set = TRUE }
117 #endif
118 #endif
119 };
120
121 pa_daemon_conf* pa_daemon_conf_new(void) {
122 pa_daemon_conf *c = pa_xnewdup(pa_daemon_conf, &default_conf, 1);
123
124 c->dl_search_path = pa_xstrdup(PA_DLSEARCHPATH);
125 return c;
126 }
127
128 void pa_daemon_conf_free(pa_daemon_conf *c) {
129 pa_assert(c);
130 pa_xfree(c->script_commands);
131 pa_xfree(c->dl_search_path);
132 pa_xfree(c->default_script_file);
133 pa_xfree(c->config_file);
134 pa_xfree(c);
135 }
136
137 int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) {
138 pa_assert(c);
139 pa_assert(string);
140
141 if (!strcmp(string, "auto"))
142 c->auto_log_target = 1;
143 else if (!strcmp(string, "syslog")) {
144 c->auto_log_target = 0;
145 c->log_target = PA_LOG_SYSLOG;
146 } else if (!strcmp(string, "stderr")) {
147 c->auto_log_target = 0;
148 c->log_target = PA_LOG_STDERR;
149 } else
150 return -1;
151
152 return 0;
153 }
154
155 int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) {
156 uint32_t u;
157 pa_assert(c);
158 pa_assert(string);
159
160 if (pa_atou(string, &u) >= 0) {
161 if (u >= PA_LOG_LEVEL_MAX)
162 return -1;
163
164 c->log_level = (pa_log_level_t) u;
165 } else if (pa_startswith(string, "debug"))
166 c->log_level = PA_LOG_DEBUG;
167 else if (pa_startswith(string, "info"))
168 c->log_level = PA_LOG_INFO;
169 else if (pa_startswith(string, "notice"))
170 c->log_level = PA_LOG_NOTICE;
171 else if (pa_startswith(string, "warn"))
172 c->log_level = PA_LOG_WARN;
173 else if (pa_startswith(string, "err"))
174 c->log_level = PA_LOG_ERROR;
175 else
176 return -1;
177
178 return 0;
179 }
180
181 int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string) {
182 int m;
183 pa_assert(c);
184 pa_assert(string);
185
186 if ((m = pa_parse_resample_method(string)) < 0)
187 return -1;
188
189 c->resample_method = m;
190 return 0;
191 }
192
193 static int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
194 pa_daemon_conf *c = data;
195
196 pa_assert(filename);
197 pa_assert(lvalue);
198 pa_assert(rvalue);
199 pa_assert(data);
200
201 if (pa_daemon_conf_set_log_target(c, rvalue) < 0) {
202 pa_log(_("[%s:%u] Invalid log target '%s'."), filename, line, rvalue);
203 return -1;
204 }
205
206 return 0;
207 }
208
209 static int parse_log_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
210 pa_daemon_conf *c = data;
211
212 pa_assert(filename);
213 pa_assert(lvalue);
214 pa_assert(rvalue);
215 pa_assert(data);
216
217 if (pa_daemon_conf_set_log_level(c, rvalue) < 0) {
218 pa_log(_("[%s:%u] Invalid log level '%s'."), filename, line, rvalue);
219 return -1;
220 }
221
222 return 0;
223 }
224
225 static int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
226 pa_daemon_conf *c = data;
227
228 pa_assert(filename);
229 pa_assert(lvalue);
230 pa_assert(rvalue);
231 pa_assert(data);
232
233 if (pa_daemon_conf_set_resample_method(c, rvalue) < 0) {
234 pa_log(_("[%s:%u] Invalid resample method '%s'."), filename, line, rvalue);
235 return -1;
236 }
237
238 return 0;
239 }
240
241 static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
242 #ifdef HAVE_SYS_RESOURCE_H
243 struct pa_rlimit *r = data;
244
245 pa_assert(filename);
246 pa_assert(lvalue);
247 pa_assert(rvalue);
248 pa_assert(r);
249
250 if (rvalue[strspn(rvalue, "\t ")] == 0) {
251 /* Empty string */
252 r->is_set = 0;
253 r->value = 0;
254 } else {
255 int32_t k;
256 if (pa_atoi(rvalue, &k) < 0) {
257 pa_log(_("[%s:%u] Invalid rlimit '%s'."), filename, line, rvalue);
258 return -1;
259 }
260 r->is_set = k >= 0;
261 r->value = k >= 0 ? (rlim_t) k : 0;
262 }
263 #else
264 pa_log_warn(_("[%s:%u] rlimit not supported on this platform."), filename, line);
265 #endif
266
267 return 0;
268 }
269
270 static int parse_sample_format(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
271 pa_daemon_conf *c = data;
272 pa_sample_format_t f;
273
274 pa_assert(filename);
275 pa_assert(lvalue);
276 pa_assert(rvalue);
277 pa_assert(data);
278
279 if ((f = pa_parse_sample_format(rvalue)) < 0) {
280 pa_log(_("[%s:%u] Invalid sample format '%s'."), filename, line, rvalue);
281 return -1;
282 }
283
284 c->default_sample_spec.format = f;
285 return 0;
286 }
287
288 static int parse_sample_rate(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
289 pa_daemon_conf *c = data;
290 int32_t r;
291
292 pa_assert(filename);
293 pa_assert(lvalue);
294 pa_assert(rvalue);
295 pa_assert(data);
296
297 if (pa_atoi(rvalue, &r) < 0 || r > (int32_t) PA_RATE_MAX || r <= 0) {
298 pa_log(_("[%s:%u] Invalid sample rate '%s'."), filename, line, rvalue);
299 return -1;
300 }
301
302 c->default_sample_spec.rate = r;
303 return 0;
304 }
305
306 static int parse_sample_channels(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
307 pa_daemon_conf *c = data;
308 int32_t n;
309
310 pa_assert(filename);
311 pa_assert(lvalue);
312 pa_assert(rvalue);
313 pa_assert(data);
314
315 if (pa_atoi(rvalue, &n) < 0 || n > (int32_t) PA_CHANNELS_MAX || n <= 0) {
316 pa_log(_("[%s:%u] Invalid sample channels '%s'."), filename, line, rvalue);
317 return -1;
318 }
319
320 c->default_sample_spec.channels = (uint8_t) n;
321 return 0;
322 }
323
324 static int parse_fragments(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
325 pa_daemon_conf *c = data;
326 int32_t n;
327
328 pa_assert(filename);
329 pa_assert(lvalue);
330 pa_assert(rvalue);
331 pa_assert(data);
332
333 if (pa_atoi(rvalue, &n) < 0 || n < 2) {
334 pa_log(_("[%s:%u] Invalid number of fragments '%s'."), filename, line, rvalue);
335 return -1;
336 }
337
338 c->default_n_fragments = (unsigned) n;
339 return 0;
340 }
341
342 static int parse_fragment_size_msec(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
343 pa_daemon_conf *c = data;
344 int32_t n;
345
346 pa_assert(filename);
347 pa_assert(lvalue);
348 pa_assert(rvalue);
349 pa_assert(data);
350
351 if (pa_atoi(rvalue, &n) < 0 || n < 1) {
352 pa_log(_("[%s:%u] Invalid fragment size '%s'."), filename, line, rvalue);
353 return -1;
354 }
355
356 c->default_fragment_size_msec = (unsigned) n;
357 return 0;
358 }
359
360 static int parse_nice_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
361 pa_daemon_conf *c = data;
362 int32_t level;
363
364 pa_assert(filename);
365 pa_assert(lvalue);
366 pa_assert(rvalue);
367 pa_assert(data);
368
369 if (pa_atoi(rvalue, &level) < 0 || level < -20 || level > 19) {
370 pa_log(_("[%s:%u] Invalid nice level '%s'."), filename, line, rvalue);
371 return -1;
372 }
373
374 c->nice_level = (int) level;
375 return 0;
376 }
377
378 static int parse_rtprio(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
379 pa_daemon_conf *c = data;
380 int32_t rtprio;
381
382 pa_assert(filename);
383 pa_assert(lvalue);
384 pa_assert(rvalue);
385 pa_assert(data);
386
387 if (pa_atoi(rvalue, &rtprio) < 0 || rtprio < sched_get_priority_min(SCHED_FIFO) || rtprio > sched_get_priority_max(SCHED_FIFO)) {
388 pa_log("[%s:%u] Invalid realtime priority '%s'.", filename, line, rvalue);
389 return -1;
390 }
391
392 c->realtime_priority = (int) rtprio;
393 return 0;
394 }
395
396 int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
397 int r = -1;
398 FILE *f = NULL;
399
400 pa_config_item table[] = {
401 { "daemonize", pa_config_parse_bool, NULL },
402 { "fail", pa_config_parse_bool, NULL },
403 { "high-priority", pa_config_parse_bool, NULL },
404 { "realtime-scheduling", pa_config_parse_bool, NULL },
405 { "disallow-module-loading", pa_config_parse_bool, NULL },
406 { "use-pid-file", pa_config_parse_bool, NULL },
407 { "system-instance", pa_config_parse_bool, NULL },
408 { "no-cpu-limit", pa_config_parse_bool, NULL },
409 { "disable-shm", pa_config_parse_bool, NULL },
410 { "exit-idle-time", pa_config_parse_int, NULL },
411 { "module-idle-time", pa_config_parse_int, NULL },
412 { "scache-idle-time", pa_config_parse_int, NULL },
413 { "realtime-priority", parse_rtprio, NULL },
414 { "dl-search-path", pa_config_parse_string, NULL },
415 { "default-script-file", pa_config_parse_string, NULL },
416 { "log-target", parse_log_target, NULL },
417 { "log-level", parse_log_level, NULL },
418 { "verbose", parse_log_level, NULL },
419 { "resample-method", parse_resample_method, NULL },
420 { "default-sample-format", parse_sample_format, NULL },
421 { "default-sample-rate", parse_sample_rate, NULL },
422 { "default-sample-channels", parse_sample_channels, NULL },
423 { "default-fragments", parse_fragments, NULL },
424 { "default-fragment-size-msec", parse_fragment_size_msec, NULL },
425 { "nice-level", parse_nice_level, NULL },
426 { "disable-remixing", pa_config_parse_bool, NULL },
427 { "load-default-script-file", pa_config_parse_bool, NULL },
428 #ifdef HAVE_SYS_RESOURCE_H
429 { "rlimit-fsize", parse_rlimit, NULL },
430 { "rlimit-data", parse_rlimit, NULL },
431 { "rlimit-stack", parse_rlimit, NULL },
432 { "rlimit-core", parse_rlimit, NULL },
433 { "rlimit-rss", parse_rlimit, NULL },
434 { "rlimit-nofile", parse_rlimit, NULL },
435 { "rlimit-as", parse_rlimit, NULL },
436 #ifdef RLIMIT_NPROC
437 { "rlimit-nproc", parse_rlimit, NULL },
438 #endif
439 #ifdef RLIMIT_MEMLOCK
440 { "rlimit-memlock", parse_rlimit, NULL },
441 #endif
442 #ifdef RLIMIT_LOCKS
443 { "rlimit-locks", parse_rlimit, NULL },
444 #endif
445 #ifdef RLIMIT_SIGPENDING
446 { "rlimit-sigpending", parse_rlimit, NULL },
447 #endif
448 #ifdef RLIMIT_MSGQUEUE
449 { "rlimit-msgqueue", parse_rlimit, NULL },
450 #endif
451 #ifdef RLIMIT_NICE
452 { "rlimit-nice", parse_rlimit, NULL },
453 #endif
454 #ifdef RLIMIT_RTPRIO
455 { "rlimit-rtprio", parse_rlimit, NULL },
456 #endif
457 #ifdef RLIMIT_RTTIME
458 { "rlimit-rttime", parse_rlimit, NULL },
459 #endif
460 #endif
461 { NULL, NULL, NULL },
462 };
463
464 table[0].data = &c->daemonize;
465 table[1].data = &c->fail;
466 table[2].data = &c->high_priority;
467 table[3].data = &c->realtime_scheduling;
468 table[4].data = &c->disallow_module_loading;
469 table[5].data = &c->use_pid_file;
470 table[6].data = &c->system_instance;
471 table[7].data = &c->no_cpu_limit;
472 table[8].data = &c->disable_shm;
473 table[9].data = &c->exit_idle_time;
474 table[10].data = &c->module_idle_time;
475 table[11].data = &c->scache_idle_time;
476 table[12].data = c;
477 table[13].data = &c->dl_search_path;
478 table[14].data = &c->default_script_file;
479 table[15].data = c;
480 table[16].data = c;
481 table[17].data = c;
482 table[18].data = c;
483 table[19].data = c;
484 table[20].data = c;
485 table[21].data = c;
486 table[22].data = c;
487 table[23].data = c;
488 table[24].data = c;
489 table[25].data = &c->disable_remixing;
490 table[26].data = &c->load_default_script_file;
491 #ifdef HAVE_SYS_RESOURCE_H
492 table[27].data = &c->rlimit_fsize;
493 table[28].data = &c->rlimit_data;
494 table[29].data = &c->rlimit_stack;
495 table[30].data = &c->rlimit_as;
496 table[31].data = &c->rlimit_core;
497 table[32].data = &c->rlimit_nofile;
498 table[33].data = &c->rlimit_as;
499 #ifdef RLIMIT_NPROC
500 table[34].data = &c->rlimit_nproc;
501 #endif
502
503 #ifdef RLIMIT_MEMLOCK
504 #ifndef RLIMIT_NPROC
505 #error "Houston, we have a numbering problem!"
506 #endif
507 table[35].data = &c->rlimit_memlock;
508 #endif
509
510 #ifdef RLIMIT_LOCKS
511 #ifndef RLIMIT_MEMLOCK
512 #error "Houston, we have a numbering problem!"
513 #endif
514 table[36].data = &c->rlimit_locks;
515 #endif
516
517 #ifdef RLIMIT_SIGPENDING
518 #ifndef RLIMIT_LOCKS
519 #error "Houston, we have a numbering problem!"
520 #endif
521 table[37].data = &c->rlimit_sigpending;
522 #endif
523
524 #ifdef RLIMIT_MSGQUEUE
525 #ifndef RLIMIT_SIGPENDING
526 #error "Houston, we have a numbering problem!"
527 #endif
528 table[38].data = &c->rlimit_msgqueue;
529 #endif
530
531 #ifdef RLIMIT_NICE
532 #ifndef RLIMIT_MSGQUEUE
533 #error "Houston, we have a numbering problem!"
534 #endif
535 table[39].data = &c->rlimit_nice;
536 #endif
537
538 #ifdef RLIMIT_RTPRIO
539 #ifndef RLIMIT_NICE
540 #error "Houston, we have a numbering problem!"
541 #endif
542 table[40].data = &c->rlimit_rtprio;
543 #endif
544
545 #ifdef RLIMIT_RTTIME
546 #ifndef RLIMIT_RTTIME
547 #error "Houston, we have a numbering problem!"
548 #endif
549 table[41].data = &c->rlimit_rttime;
550 #endif
551 #endif
552
553 pa_xfree(c->config_file);
554 c->config_file = NULL;
555
556 f = filename ?
557 fopen(c->config_file = pa_xstrdup(filename), "r") :
558 pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file);
559
560 if (!f && errno != ENOENT) {
561 pa_log_warn(_("Failed to open configuration file: %s"), pa_cstrerror(errno));
562 goto finish;
563 }
564
565 r = f ? pa_config_parse(c->config_file, f, table, NULL) : 0;
566
567 finish:
568 if (f)
569 fclose(f);
570
571 return r;
572 }
573
574 int pa_daemon_conf_env(pa_daemon_conf *c) {
575 char *e;
576 pa_assert(c);
577
578 if ((e = getenv(ENV_DL_SEARCH_PATH))) {
579 pa_xfree(c->dl_search_path);
580 c->dl_search_path = pa_xstrdup(e);
581 }
582 if ((e = getenv(ENV_SCRIPT_FILE))) {
583 pa_xfree(c->default_script_file);
584 c->default_script_file = pa_xstrdup(e);
585 }
586
587 return 0;
588 }
589
590 const char *pa_daemon_conf_get_default_script_file(pa_daemon_conf *c) {
591 pa_assert(c);
592
593 if (!c->default_script_file) {
594 if (c->system_instance)
595 c->default_script_file = pa_find_config_file(DEFAULT_SYSTEM_SCRIPT_FILE, NULL, ENV_SCRIPT_FILE);
596 else
597 c->default_script_file = pa_find_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE);
598 }
599
600 return c->default_script_file;
601 }
602
603 FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) {
604 FILE *f;
605 pa_assert(c);
606
607 if (!c->default_script_file) {
608 if (c->system_instance)
609 f = pa_open_config_file(DEFAULT_SYSTEM_SCRIPT_FILE, NULL, ENV_SCRIPT_FILE, &c->default_script_file);
610 else
611 f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file);
612 } else
613 f = fopen(c->default_script_file, "r");
614
615 return f;
616 }
617
618
619 static const char* const log_level_to_string[] = {
620 [PA_LOG_DEBUG] = "debug",
621 [PA_LOG_INFO] = "info",
622 [PA_LOG_NOTICE] = "notice",
623 [PA_LOG_WARN] = "warning",
624 [PA_LOG_ERROR] = "error"
625 };
626
627 char *pa_daemon_conf_dump(pa_daemon_conf *c) {
628 pa_strbuf *s;
629
630 pa_assert(c);
631
632 s = pa_strbuf_new();
633
634 if (c->config_file)
635 pa_strbuf_printf(s, _("### Read from configuration file: %s ###\n"), c->config_file);
636
637 pa_assert(c->log_level <= PA_LOG_LEVEL_MAX);
638
639 pa_strbuf_printf(s, "daemonize = %s\n", pa_yes_no(c->daemonize));
640 pa_strbuf_printf(s, "fail = %s\n", pa_yes_no(c->fail));
641 pa_strbuf_printf(s, "high-priority = %s\n", pa_yes_no(c->high_priority));
642 pa_strbuf_printf(s, "nice-level = %i\n", c->nice_level);
643 pa_strbuf_printf(s, "realtime-scheduling = %s\n", pa_yes_no(c->realtime_scheduling));
644 pa_strbuf_printf(s, "realtime-priority = %i\n", c->realtime_priority);
645 pa_strbuf_printf(s, "disallow-module-loading = %s\n", pa_yes_no(c->disallow_module_loading));
646 pa_strbuf_printf(s, "use-pid-file = %s\n", pa_yes_no(c->use_pid_file));
647 pa_strbuf_printf(s, "system-instance = %s\n", pa_yes_no(c->system_instance));
648 pa_strbuf_printf(s, "no-cpu-limit = %s\n", pa_yes_no(c->no_cpu_limit));
649 pa_strbuf_printf(s, "disable-shm = %s\n", pa_yes_no(c->disable_shm));
650 pa_strbuf_printf(s, "exit-idle-time = %i\n", c->exit_idle_time);
651 pa_strbuf_printf(s, "module-idle-time = %i\n", c->module_idle_time);
652 pa_strbuf_printf(s, "scache-idle-time = %i\n", c->scache_idle_time);
653 pa_strbuf_printf(s, "dl-search-path = %s\n", pa_strempty(c->dl_search_path));
654 pa_strbuf_printf(s, "default-script-file = %s\n", pa_strempty(pa_daemon_conf_get_default_script_file(c)));
655 pa_strbuf_printf(s, "load-default-script-file = %s\n", pa_yes_no(c->load_default_script_file));
656 pa_strbuf_printf(s, "log-target = %s\n", c->auto_log_target ? "auto" : (c->log_target == PA_LOG_SYSLOG ? "syslog" : "stderr"));
657 pa_strbuf_printf(s, "log-level = %s\n", log_level_to_string[c->log_level]);
658 pa_strbuf_printf(s, "resample-method = %s\n", pa_resample_method_to_string(c->resample_method));
659 pa_strbuf_printf(s, "disable-remixing = %s\n", pa_yes_no(c->disable_remixing));
660 pa_strbuf_printf(s, "default-sample-format = %s\n", pa_sample_format_to_string(c->default_sample_spec.format));
661 pa_strbuf_printf(s, "default-sample-rate = %u\n", c->default_sample_spec.rate);
662 pa_strbuf_printf(s, "default-sample-channels = %u\n", c->default_sample_spec.channels);
663 pa_strbuf_printf(s, "default-fragments = %u\n", c->default_n_fragments);
664 pa_strbuf_printf(s, "default-fragment-size-msec = %u\n", c->default_fragment_size_msec);
665 #ifdef HAVE_SYS_RESOURCE_H
666 pa_strbuf_printf(s, "rlimit-fsize = %li\n", c->rlimit_fsize.is_set ? (long int) c->rlimit_fsize.value : -1);
667 pa_strbuf_printf(s, "rlimit-data = %li\n", c->rlimit_data.is_set ? (long int) c->rlimit_data.value : -1);
668 pa_strbuf_printf(s, "rlimit-stack = %li\n", c->rlimit_stack.is_set ? (long int) c->rlimit_stack.value : -1);
669 pa_strbuf_printf(s, "rlimit-core = %li\n", c->rlimit_core.is_set ? (long int) c->rlimit_core.value : -1);
670 pa_strbuf_printf(s, "rlimit-as = %li\n", c->rlimit_as.is_set ? (long int) c->rlimit_as.value : -1);
671 pa_strbuf_printf(s, "rlimit-rss = %li\n", c->rlimit_rss.is_set ? (long int) c->rlimit_rss.value : -1);
672 #ifdef RLIMIT_NPROC
673 pa_strbuf_printf(s, "rlimit-nproc = %li\n", c->rlimit_nproc.is_set ? (long int) c->rlimit_nproc.value : -1);
674 #endif
675 pa_strbuf_printf(s, "rlimit-nofile = %li\n", c->rlimit_nofile.is_set ? (long int) c->rlimit_nofile.value : -1);
676 #ifdef RLIMIT_MEMLOCK
677 pa_strbuf_printf(s, "rlimit-memlock = %li\n", c->rlimit_memlock.is_set ? (long int) c->rlimit_memlock.value : -1);
678 #endif
679 #ifdef RLIMIT_LOCKS
680 pa_strbuf_printf(s, "rlimit-locks = %li\n", c->rlimit_locks.is_set ? (long int) c->rlimit_locks.value : -1);
681 #endif
682 #ifdef RLIMIT_SIGPENDING
683 pa_strbuf_printf(s, "rlimit-sigpending = %li\n", c->rlimit_sigpending.is_set ? (long int) c->rlimit_sigpending.value : -1);
684 #endif
685 #ifdef RLIMIT_MSGQUEUE
686 pa_strbuf_printf(s, "rlimit-msgqueue = %li\n", c->rlimit_msgqueue.is_set ? (long int) c->rlimit_msgqueue.value : -1);
687 #endif
688 #ifdef RLIMIT_NICE
689 pa_strbuf_printf(s, "rlimit-nice = %li\n", c->rlimit_nice.is_set ? (long int) c->rlimit_nice.value : -1);
690 #endif
691 #ifdef RLIMIT_RTPRIO
692 pa_strbuf_printf(s, "rlimit-rtprio = %li\n", c->rlimit_rtprio.is_set ? (long int) c->rlimit_rtprio.value : -1);
693 #endif
694 #ifdef RLIMIT_RTTIME
695 pa_strbuf_printf(s, "rlimit-rttime = %li\n", c->rlimit_rttime.is_set ? (long int) c->rlimit_rttime.value : -1);
696 #endif
697 #endif
698
699 return pa_strbuf_tostring_free(s);
700 }