aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-config.c
diff options
context:
space:
mode:
authorGravatar Alec Berryman <alec@thened.net>2009-11-21 23:18:26 -0600
committerGravatar Carl Worth <cworth@cworth.org>2009-11-23 03:01:57 +0100
commit91d1d3f043b82d5f3f8c04f2db71a829a7406131 (patch)
treecdd4783ec2a35528e7f142c260fd934b75c98c92 /notmuch-config.c
parent8c09ca1e21a9f33cf216cde3bebc05d245ff6b78 (diff)
Support multiple configuration files via $NOTMUCH_CONFIG
If present, $NOTMUCH_CONFIG will be used as the configuration file location.
Diffstat (limited to 'notmuch-config.c')
-rw-r--r--notmuch-config.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index aaa0372c..fc65d6b0 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -132,9 +132,10 @@ get_username_from_passwd_file (void *ctx)
return name;
}
-/* Open the named notmuch configuration file. A filename of NULL will
- * be interpreted as the default configuration file
- * ($HOME/.notmuch-config).
+/* Open the named notmuch configuration file. If the filename is NULL,
+ * the value of the environment variable $NOTMUCH_CONFIG will be used.
+ * If $NOTMUCH_CONFIG is unset, the default configuration file
+ * ($HOME/.notmuch-config) will be used.
*
* If any error occurs, (out of memory, or a permission-denied error,
* etc.), this function will print a message to stderr and return
@@ -168,6 +169,7 @@ notmuch_config_open (void *ctx,
{
GError *error = NULL;
int is_new = 0;
+ char *notmuch_config_env = NULL;
if (is_new_ret)
*is_new_ret = 0;
@@ -180,11 +182,15 @@ notmuch_config_open (void *ctx,
talloc_set_destructor (config, notmuch_config_destructor);
- if (filename)
+ if (filename) {
config->filename = talloc_strdup (config, filename);
- else
+ } else if ((notmuch_config_env = getenv ("NOTMUCH_CONFIG"))) {
+ config->filename = talloc_strdup (config, notmuch_config_env);
+ notmuch_config_env = NULL;
+ } else {
config->filename = talloc_asprintf (config, "%s/.notmuch-config",
getenv ("HOME"));
+ }
config->key_file = g_key_file_new ();