gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r36919 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r36919 - gnunet/src/util
Date: Sun, 28 Feb 2016 21:40:00 +0100

Author: dold
Date: 2016-02-28 21:40:00 +0100 (Sun, 28 Feb 2016)
New Revision: 36919

Modified:
   gnunet/src/util/configuration_loader.c
   gnunet/src/util/resolver_api.c
Log:
Add support for $GNUNET_BASE_CONFIG

The environment variable GNUNET_BASE_CONFIG allows
specifying the directory from which all base config
files will be loaded.  This is useful when ARM is
to be used to supervise things otherwise unrelated to
GNUnet.  Modifying GNUNET_PREFIX is not sufficient
for this use case, since e.g. libexec files need
to be under GNUNET_PREFIX, and GNUNET_BASE_CONFIG
provides a way to only modify the base config
directory independent of where GNUnet was installed.


Modified: gnunet/src/util/configuration_loader.c
===================================================================
--- gnunet/src/util/configuration_loader.c      2016-02-24 21:31:07 UTC (rev 
36918)
+++ gnunet/src/util/configuration_loader.c      2016-02-28 20:40:00 UTC (rev 
36919)
@@ -29,7 +29,7 @@
 
 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
 
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file 
(kind, "util", syscall, filename)
+
 /**
  * Load configuration (starts with defaults, then loads
  * system-specific configuration).
@@ -43,15 +43,22 @@
                            const char *filename)
 {
   char *baseconfig;
-  char *ipath;
 
-  ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
-  if (NULL == ipath)
-    return GNUNET_SYSERR;
-  baseconfig = NULL;
-  GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
-  GNUNET_free (ipath);
+  if (NULL != (baseconfig = getenv ("GNUNET_BASE_CONFIG")))
+  {
+    baseconfig = GNUNET_strdup (baseconfig);
+  }
+  else
+  {
+    char *ipath;
 
+    ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+    if (NULL == ipath)
+      return GNUNET_SYSERR;
+    GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
+    GNUNET_free (ipath);
+  }
+
   if (GNUNET_SYSERR ==
       GNUNET_CONFIGURATION_load_from (cfg,
                                       baseconfig))

Modified: gnunet/src/util/resolver_api.c
===================================================================
--- gnunet/src/util/resolver_api.c      2016-02-24 21:31:07 UTC (rev 36918)
+++ gnunet/src/util/resolver_api.c      2016-02-28 20:40:00 UTC (rev 36919)
@@ -171,8 +171,11 @@
 /**
  * Check that the resolver service runs on localhost
  * (or equivalent).
+ *
+ * @return #GNUNET_OK if the resolver is properly configured,
+ *         #GNUNET_SYSERR otherwise.
  */
-static void
+static int
 check_config ()
 {
   char *hostname;
@@ -197,17 +200,17 @@
                                              "HOSTNAME",
                                              &hostname))
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Must specify `%s' for `%s' in configuration!\n"),
+    LOG (GNUNET_ERROR_TYPE_INFO,
+         _("Missing `%s' for `%s' in configuration, DNS resolution will be 
unavailable.\n"),
          "HOSTNAME",
          "resolver");
-    GNUNET_assert (0);
+    return GNUNET_SYSERR;
   }
   if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
       (1 != inet_pton (AF_INET6, hostname, &v6)))
   {
     GNUNET_free (hostname);
-    return;
+    return GNUNET_SYSERR;
   }
   i = 0;
   while (NULL != loopback[i])
@@ -214,15 +217,15 @@
     if (0 == strcasecmp (loopback[i++], hostname))
     {
       GNUNET_free (hostname);
-      return;
+      return GNUNET_OK;
     }
-  LOG (GNUNET_ERROR_TYPE_ERROR,
-       _("Must specify `%s' or numeric IP address for `%s' of `%s' in 
configuration!\n"),
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       _("Missing `%s' or numeric IP address for `%s' of `%s' in 
configuration, DNS resolution will be unavailable.\n"),
        "localhost",
        "HOSTNAME",
        "resolver");
   GNUNET_free (hostname);
-  GNUNET_assert (0);
+  return GNUNET_SYSERR;
 }
 
 
@@ -237,7 +240,7 @@
   GNUNET_assert (NULL != cfg);
   backoff = GNUNET_TIME_UNIT_MILLISECONDS;
   resolver_cfg = cfg;
-  check_config ();
+  (void) check_config ();
 }
 
 
@@ -951,7 +954,13 @@
   size_t ip_len;
   const void *ip;
 
-  check_config ();
+  if (GNUNET_OK != check_config ())
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Resolver not configured correctly.\n"));
+    return NULL;
+  }
+
   switch (sa->sa_family)
   {
   case AF_INET:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]