summaryrefslogtreecommitdiffstats
path: root/polyp/client-conf.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-11-04 21:27:12 +0000
committerLennart Poettering <lennart@poettering.net>2004-11-04 21:27:12 +0000
commit5844a33f0be1af942ee33feae38b9d46169fd61c (patch)
tree7a2feaab269107da3131a6baa2932aad3dc4377a /polyp/client-conf.c
parent2aad9e3ae2aa53d13458faf148946cf7e7d87627 (diff)
some commenting
change alogrithm for checking for configuration files git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@273 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/client-conf.c')
-rw-r--r--polyp/client-conf.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/polyp/client-conf.c b/polyp/client-conf.c
index b8a4c778..47c5b49c 100644
--- a/polyp/client-conf.c
+++ b/polyp/client-conf.c
@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
+#include <errno.h>
+#include <string.h>
#include "client-conf.h"
#include "xmalloc.h"
@@ -29,13 +31,12 @@
#include "conf-parser.h"
#include "util.h"
-#ifndef DEFAULT_CLIENT_CONFIG_FILE
-#define DEFAULT_CLIENT_CONFIG_FILE "/etc/polypaudio/client.conf"
+#ifndef DEFAULT_CONFIG_DIR
+#define DEFAULT_CONFIG_DIR "/etc/polypaudio"
#endif
-#ifndef DEFAULT_CLIENT_CONFIG_FILE_USER
+#define DEFAULT_CLIENT_CONFIG_FILE DEFAULT_CONFIG_DIR"/client.conf"
#define DEFAULT_CLIENT_CONFIG_FILE_USER ".polypaudio/client.conf"
-#endif
#define ENV_CLIENT_CONFIG_FILE "POLYP_CLIENTCONFIG"
#define ENV_DEFAULT_SINK "POLYP_SINK"
@@ -71,8 +72,9 @@ void pa_client_conf_free(struct pa_client_conf *c) {
pa_xfree(c);
}
int pa_client_conf_load(struct pa_client_conf *c, const char *filename) {
- char *def = NULL;
- int r;
+ FILE *f = NULL;
+ char *fn = NULL;
+ int r = -1;
struct pa_config_item table[] = {
{ "daemon-binary", pa_config_parse_string, NULL },
@@ -91,29 +93,23 @@ int pa_client_conf_load(struct pa_client_conf *c, const char *filename) {
table[4].data = &c->default_server;
table[5].data = &c->autospawn;
- if (!filename)
- filename = getenv(ENV_CLIENT_CONFIG_FILE);
-
- if (!filename) {
- char *h;
-
- if ((h = getenv("HOME"))) {
- def = pa_sprintf_malloc("%s/%s", h, DEFAULT_CLIENT_CONFIG_FILE_USER);
-
- if (!access(def, F_OK))
- filename = def;
- else {
- pa_xfree(def);
- def = NULL;
- }
- }
+ f = filename ?
+ fopen((fn = pa_xstrdup(filename)), "r") :
+ pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn);
+
+ if (!f && errno != EINTR) {
+ pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s\n", filename, strerror(errno));
+ goto finish;
}
+
+ r = pa_config_parse(fn, f, table, NULL);
+
+finish:
+ pa_xfree(fn);
- if (!filename)
- filename = DEFAULT_CLIENT_CONFIG_FILE;
+ if (f)
+ fclose(f);
- r = pa_config_parse(filename, table, NULL);
- pa_xfree(def);
return r;
}