diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-09 10:26:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-09 10:26:23 +0000 |
commit | d0a9f269aa6575253b1c284d594a467e6fdeb7c7 (patch) | |
tree | 21cf2183b906bd550eff83616552097c977ad530 /src/util | |
parent | d4baeee37d09e53b5f176398a1b4aaa0aa747883 (diff) | |
download | gnunet-d0a9f269aa6575253b1c284d594a467e6fdeb7c7.tar.gz gnunet-d0a9f269aa6575253b1c284d594a467e6fdeb7c7.zip |
more work towards XDG spec (#3000) -- config file location
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/program.c | 24 | ||||
-rw-r--r-- | src/util/service.c | 34 | ||||
-rw-r--r-- | src/util/test_resolver_api_data.conf | 2 | ||||
-rw-r--r-- | src/util/util.conf | 9 |
4 files changed, 50 insertions, 19 deletions
diff --git a/src/util/program.c b/src/util/program.c index aae58db49..73003891e 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -145,6 +145,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
145 | #endif | 145 | #endif |
146 | char *loglev; | 146 | char *loglev; |
147 | char *logfile; | 147 | char *logfile; |
148 | char *cfg_fn; | ||
149 | const char *xdg; | ||
148 | int ret; | 150 | int ret; |
149 | unsigned int cnt; | 151 | unsigned int cnt; |
150 | unsigned long long skew_offset; | 152 | unsigned long long skew_offset; |
@@ -195,7 +197,6 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
195 | cc.task = task; | 197 | cc.task = task; |
196 | cc.task_cls = task_cls; | 198 | cc.task_cls = task_cls; |
197 | cc.cfg = cfg = GNUNET_CONFIGURATION_create (); | 199 | cc.cfg = cfg = GNUNET_CONFIGURATION_create (); |
198 | |||
199 | /* prepare */ | 200 | /* prepare */ |
200 | #if ENABLE_NLS | 201 | #if ENABLE_NLS |
201 | setlocale (LC_ALL, ""); | 202 | setlocale (LC_ALL, ""); |
@@ -223,7 +224,15 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
223 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), | 224 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), |
224 | &cmd_sorter); | 225 | &cmd_sorter); |
225 | loglev = NULL; | 226 | loglev = NULL; |
226 | cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | 227 | xdg = getenv ("XDG_CONFIG_HOME"); |
228 | if (NULL != xdg) | ||
229 | GNUNET_asprintf (&cfg_fn, | ||
230 | "%s%s%s", | ||
231 | xdg, | ||
232 | DIR_SEPARATOR_STR, | ||
233 | "gnunet.config"); | ||
234 | else | ||
235 | cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | ||
227 | lpfx = GNUNET_strdup (binaryName); | 236 | lpfx = GNUNET_strdup (binaryName); |
228 | if (NULL != (spc = strstr (lpfx, " "))) | 237 | if (NULL != (spc = strstr (lpfx, " "))) |
229 | *spc = '\0'; | 238 | *spc = '\0'; |
@@ -239,13 +248,15 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
239 | GNUNET_free (lpfx); | 248 | GNUNET_free (lpfx); |
240 | return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK; | 249 | return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK; |
241 | } | 250 | } |
251 | if (NULL == cc.cfgfile) | ||
252 | cc.cfgfile = GNUNET_strdup (cfg_fn); | ||
242 | if (GNUNET_YES == | 253 | if (GNUNET_YES == |
243 | GNUNET_DISK_file_test (cc.cfgfile)) | 254 | GNUNET_DISK_file_test (cc.cfgfile)) |
244 | (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); | 255 | (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); |
245 | else | 256 | else |
246 | { | 257 | { |
247 | (void) GNUNET_CONFIGURATION_load (cfg, NULL); | 258 | (void) GNUNET_CONFIGURATION_load (cfg, NULL); |
248 | if (0 != strcmp (cc.cfgfile, GNUNET_DEFAULT_USER_CONFIG_FILE)) | 259 | if (0 != strcmp (cc.cfgfile, cfg_fn)) |
249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 260 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
250 | _("Could not access configuration file `%s'\n"), | 261 | _("Could not access configuration file `%s'\n"), |
251 | cc.cfgfile); | 262 | cc.cfgfile); |
@@ -276,7 +287,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
276 | /* clean up */ | 287 | /* clean up */ |
277 | GNUNET_SPEEDUP_stop_ (); | 288 | GNUNET_SPEEDUP_stop_ (); |
278 | GNUNET_CONFIGURATION_destroy (cfg); | 289 | GNUNET_CONFIGURATION_destroy (cfg); |
279 | GNUNET_free_non_null (cc.cfgfile); | 290 | GNUNET_free (cc.cfgfile); |
291 | GNUNET_free (cfg_fn); | ||
280 | GNUNET_free_non_null (loglev); | 292 | GNUNET_free_non_null (loglev); |
281 | GNUNET_free_non_null (logfile); | 293 | GNUNET_free_non_null (logfile); |
282 | return GNUNET_OK; | 294 | return GNUNET_OK; |
@@ -292,8 +304,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
292 | * @param binaryHelp help text for the program | 304 | * @param binaryHelp help text for the program |
293 | * @param options command line options | 305 | * @param options command line options |
294 | * @param task main function to run | 306 | * @param task main function to run |
295 | * @param task_cls closure for task | 307 | * @param task_cls closure for @a task |
296 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 308 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
297 | */ | 309 | */ |
298 | int | 310 | int |
299 | GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, | 311 | GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, |
diff --git a/src/util/service.c b/src/util/service.c index d8ca5eba6..9190e0b13 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -1716,8 +1716,8 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) | |||
1716 | * @param service_name our service name | 1716 | * @param service_name our service name |
1717 | * @param options service options | 1717 | * @param options service options |
1718 | * @param task main task of the service | 1718 | * @param task main task of the service |
1719 | * @param task_cls closure for task | 1719 | * @param task_cls closure for @a task |
1720 | * @return GNUNET_SYSERR on error, GNUNET_OK | 1720 | * @return #GNUNET_SYSERR on error, #GNUNET_OK |
1721 | * if we shutdown nicely | 1721 | * if we shutdown nicely |
1722 | */ | 1722 | */ |
1723 | int | 1723 | int |
@@ -1730,6 +1730,7 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | |||
1730 | int err; | 1730 | int err; |
1731 | int ret; | 1731 | int ret; |
1732 | char *cfg_fn; | 1732 | char *cfg_fn; |
1733 | char *opt_cfg_fn; | ||
1733 | char *loglev; | 1734 | char *loglev; |
1734 | char *logfile; | 1735 | char *logfile; |
1735 | int do_daemonize; | 1736 | int do_daemonize; |
@@ -1739,9 +1740,10 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | |||
1739 | long long clock_offset; | 1740 | long long clock_offset; |
1740 | struct GNUNET_SERVICE_Context sctx; | 1741 | struct GNUNET_SERVICE_Context sctx; |
1741 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1742 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1743 | const char *xdg; | ||
1742 | 1744 | ||
1743 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 1745 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
1744 | GNUNET_GETOPT_OPTION_CFG_FILE (&cfg_fn), | 1746 | GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_fn), |
1745 | {'d', "daemonize", NULL, | 1747 | {'d', "daemonize", NULL, |
1746 | gettext_noop ("do daemonize (detach from terminal)"), 0, | 1748 | gettext_noop ("do daemonize (detach from terminal)"), 0, |
1747 | GNUNET_GETOPT_set_one, &do_daemonize}, | 1749 | GNUNET_GETOPT_set_one, &do_daemonize}, |
@@ -1755,7 +1757,16 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | |||
1755 | do_daemonize = 0; | 1757 | do_daemonize = 0; |
1756 | logfile = NULL; | 1758 | logfile = NULL; |
1757 | loglev = NULL; | 1759 | loglev = NULL; |
1758 | cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | 1760 | opt_cfg_fn = NULL; |
1761 | xdg = getenv ("XDG_CONFIG_HOME"); | ||
1762 | if (NULL != xdg) | ||
1763 | GNUNET_asprintf (&cfg_fn, | ||
1764 | "%s%s%s", | ||
1765 | xdg, | ||
1766 | DIR_SEPARATOR_STR, | ||
1767 | "gnunet.config"); | ||
1768 | else | ||
1769 | cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | ||
1759 | memset (&sctx, 0, sizeof (sctx)); | 1770 | memset (&sctx, 0, sizeof (sctx)); |
1760 | sctx.options = options; | 1771 | sctx.options = options; |
1761 | sctx.ready_confirm_fd = -1; | 1772 | sctx.ready_confirm_fd = -1; |
@@ -1777,16 +1788,18 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | |||
1777 | } | 1788 | } |
1778 | if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) | 1789 | if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) |
1779 | HANDLE_ERROR; | 1790 | HANDLE_ERROR; |
1791 | if (NULL == opt_cfg_fn) | ||
1792 | opt_cfg_fn = GNUNET_strdup (cfg_fn); | ||
1780 | if (GNUNET_YES == | 1793 | if (GNUNET_YES == |
1781 | GNUNET_DISK_file_test (cfg_fn)) | 1794 | GNUNET_DISK_file_test (opt_cfg_fn)) |
1782 | (void) GNUNET_CONFIGURATION_load (cfg, cfg_fn); | 1795 | (void) GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn); |
1783 | else | 1796 | else |
1784 | { | 1797 | { |
1785 | (void) GNUNET_CONFIGURATION_load (cfg, NULL); | 1798 | (void) GNUNET_CONFIGURATION_load (cfg, NULL); |
1786 | if (0 != strcmp (cfg_fn, GNUNET_DEFAULT_USER_CONFIG_FILE)) | 1799 | if (0 != strcmp (opt_cfg_fn, cfg_fn)) |
1787 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1800 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1788 | _("Could not access configuration file `%s'\n"), | 1801 | _("Could not access configuration file `%s'\n"), |
1789 | cfg_fn); | 1802 | opt_cfg_fn); |
1790 | } | 1803 | } |
1791 | if (GNUNET_OK != setup_service (&sctx)) | 1804 | if (GNUNET_OK != setup_service (&sctx)) |
1792 | goto shutdown; | 1805 | goto shutdown; |
@@ -1795,7 +1808,9 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | |||
1795 | if (GNUNET_OK != set_user_id (&sctx)) | 1808 | if (GNUNET_OK != set_user_id (&sctx)) |
1796 | goto shutdown; | 1809 | goto shutdown; |
1797 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1810 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1798 | "Service `%s' runs with configuration from `%s'\n", service_name, cfg_fn); | 1811 | "Service `%s' runs with configuration from `%s'\n", |
1812 | service_name, | ||
1813 | opt_cfg_fn); | ||
1799 | if ((GNUNET_OK == | 1814 | if ((GNUNET_OK == |
1800 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", | 1815 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", |
1801 | "SKEW_OFFSET", &skew_offset)) && | 1816 | "SKEW_OFFSET", &skew_offset)) && |
@@ -1853,6 +1868,7 @@ shutdown: | |||
1853 | GNUNET_free_non_null (logfile); | 1868 | GNUNET_free_non_null (logfile); |
1854 | GNUNET_free_non_null (loglev); | 1869 | GNUNET_free_non_null (loglev); |
1855 | GNUNET_free (cfg_fn); | 1870 | GNUNET_free (cfg_fn); |
1871 | GNUNET_free (opt_cfg_fn); | ||
1856 | GNUNET_free_non_null (sctx.v4_denied); | 1872 | GNUNET_free_non_null (sctx.v4_denied); |
1857 | GNUNET_free_non_null (sctx.v6_denied); | 1873 | GNUNET_free_non_null (sctx.v6_denied); |
1858 | GNUNET_free_non_null (sctx.v4_allowed); | 1874 | GNUNET_free_non_null (sctx.v4_allowed); |
diff --git a/src/util/test_resolver_api_data.conf b/src/util/test_resolver_api_data.conf index 3e264ebb7..42b36d66a 100644 --- a/src/util/test_resolver_api_data.conf +++ b/src/util/test_resolver_api_data.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | [PATHS] | 1 | [PATHS] |
2 | SERVICEHOME = /tmp/test-gnunetd-statistics/ | 2 | GNUNET_TEST_HOME = /tmp/test-gnunetd-statistics/ |
3 | 3 | ||
4 | [resolver] | 4 | [resolver] |
5 | PORT = 22354 | 5 | PORT = 22354 |
diff --git a/src/util/util.conf b/src/util/util.conf index b7f9deb04..7a4d3c704 100644 --- a/src/util/util.conf +++ b/src/util/util.conf | |||
@@ -5,7 +5,10 @@ | |||
5 | # defaults with the syntax "${VAR:-default}". Here, "default" can again | 5 | # defaults with the syntax "${VAR:-default}". Here, "default" can again |
6 | # be a $-expression. | 6 | # be a $-expression. |
7 | # | 7 | # |
8 | GNUNET_HOME = $HOME | 8 | # We usually want $HOME for $GNUNET_HOME, but we allow testcases to |
9 | # easily override this by setting $GNUNET_TEST_HOME. | ||
10 | # | ||
11 | GNUNET_HOME = ${GNUNET_TEST_HOME:-$HOME} | ||
9 | 12 | ||
10 | # see XDG Base Directory Specification at | 13 | # see XDG Base Directory Specification at |
11 | # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 14 | # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
@@ -24,8 +27,8 @@ GNUNET_CACHE_HOME = ${XDG_CACHE_HOME:-$GNUNET_HOME/.cache/}gnunet/ | |||
24 | GNUNET_RUNTIME_DIR = ${XDG_RUNTIME_DIR:-${TMPDIR:-${TMP:-/tmp}}}gnunet/ | 27 | GNUNET_RUNTIME_DIR = ${XDG_RUNTIME_DIR:-${TMPDIR:-${TMP:-/tmp}}}gnunet/ |
25 | 28 | ||
26 | # Legacy option... | 29 | # Legacy option... |
27 | SERVICEHOME = ~/.gnunet/ | 30 | GNUNET_TEST_HOME = ~/.gnunet/ |
28 | # SERVICEHOME = /var/lib/gnunet/ | 31 | # GNUNET_TEST_HOME = /var/lib/gnunet/ |
29 | 32 | ||
30 | # DEFAULTCONFIG = /etc/gnunet.conf | 33 | # DEFAULTCONFIG = /etc/gnunet.conf |
31 | # If 'DEFAULTCONFIG' is not defined, the current | 34 | # If 'DEFAULTCONFIG' is not defined, the current |