diff options
Diffstat (limited to 'src/util/service.c')
-rw-r--r-- | src/util/service.c | 34 |
1 files changed, 25 insertions, 9 deletions
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); |