summaryrefslogtreecommitdiffstats
path: root/polyp/daemon-conf.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-12-11 00:10:41 +0000
committerLennart Poettering <lennart@poettering.net>2004-12-11 00:10:41 +0000
commit73eabece3365c1bb47bf6b009682219c4492fda5 (patch)
tree907b66e2fe29705a512e5f3a240210590b8fe9ba /polyp/daemon-conf.c
parent5be9641ffe18c482294c99345306c382ba4cf750 (diff)
* add first part of zeroconf publisher
* bump version to 0.7.1. * improve logging subsystem (introducing log levels) * remove verbose flag on cli * add new API pa_sample_format_to_string() * replace strtol() by usages of pa_atou() and pa_atoi() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@317 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/daemon-conf.c')
-rw-r--r--polyp/daemon-conf.c77
1 files changed, 63 insertions, 14 deletions
diff --git a/polyp/daemon-conf.c b/polyp/daemon-conf.c
index 7753da6a..a6afd05a 100644
--- a/polyp/daemon-conf.c
+++ b/polyp/daemon-conf.c
@@ -53,7 +53,6 @@ static const struct pa_daemon_conf default_conf = {
.cmd = PA_CMD_DAEMON,
.daemonize = 0,
.fail = 1,
- .verbose = 0,
.high_priority = 0,
.disallow_module_loading = 0,
.exit_idle_time = -1,
@@ -64,6 +63,7 @@ static const struct pa_daemon_conf default_conf = {
.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
@@ -108,6 +108,31 @@ int pa_daemon_conf_set_log_target(struct pa_daemon_conf *c, const char *string)
return 0;
}
+int pa_daemon_conf_set_log_level(struct 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 = (enum pa_log_level) 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(struct pa_daemon_conf *c, const char *string) {
int m;
assert(c && string);
@@ -131,6 +156,18 @@ static int parse_log_target(const char *filename, unsigned line, const char *lva
return 0;
}
+static int parse_log_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+ struct 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, void *userdata) {
struct pa_daemon_conf *c = data;
assert(filename && lvalue && rvalue && data);
@@ -148,7 +185,6 @@ int pa_daemon_conf_load(struct pa_daemon_conf *c, const char *filename) {
FILE *f = NULL;
struct pa_config_item table[] = {
- { "verbose", pa_config_parse_bool, NULL },
{ "daemonize", pa_config_parse_bool, NULL },
{ "fail", pa_config_parse_bool, NULL },
{ "high-priority", pa_config_parse_bool, NULL },
@@ -159,24 +195,27 @@ int pa_daemon_conf_load(struct pa_daemon_conf *c, const char *filename) {
{ "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->verbose;
- table[1].data = &c->daemonize;
- table[2].data = &c->fail;
- table[3].data = &c->high_priority;
- table[4].data = &c->disallow_module_loading;
- table[5].data = &c->exit_idle_time;
- table[6].data = &c->module_idle_time;
- table[7].data = &c->scache_idle_time;
- table[8].data = &c->dl_search_path;
- table[9].data = &c->default_script_file;
+ 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->use_pid_file;
+ table[12].data = c;
+ table[13].data = &c->use_pid_file;
pa_xfree(c->config_file);
c->config_file = NULL;
@@ -214,13 +253,22 @@ int pa_daemon_conf_env(struct pa_daemon_conf *c) {
return 0;
}
+static const char* const log_level_to_string[] = {
+ [PA_LOG_DEBUG] = "debug",
+ [PA_LOG_INFO] = "info",
+ [PA_LOG_NOTICE] = "notice",
+ [PA_LOG_WARN] = "warning",
+ [PA_LOG_ERROR] = "error"
+};
+
char *pa_daemon_conf_dump(struct pa_daemon_conf *c) {
struct 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, "verbose = %i\n", !!c->verbose);
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);
@@ -231,6 +279,7 @@ char *pa_daemon_conf_dump(struct pa_daemon_conf *c) {
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);