introduce GNUNET_OS_installation_get_path (useful for custom helper paths)
authorlurchi <lurchi@strangeplace.net>
Thu, 27 Jun 2019 15:39:03 +0000 (17:39 +0200)
committerlurchi <lurchi@strangeplace.net>
Thu, 27 Jun 2019 15:39:03 +0000 (17:39 +0200)
src/include/gnunet_os_lib.h
src/util/os_installation.c

index 285dfb68ded7af2577d27ac6ea8515ab4a6ee259..82203267c26b0740e9e7d2235be5d0f5b0d01409 100644 (file)
@@ -305,6 +305,19 @@ char *
 GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind);
 
 
+/**
+ * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary and
+ * a prefix, construct the full path to the binary.
+ *
+ * @param progname name of the binary
+ * @param prefix the path to use as a prefix (if NULL this function is
+ *        equivalent to GNUNET_OS_get_libexec_binary_path)
+ * @return full path to the binary, if possible, otherwise copy of 'progname'
+ */
+char *
+GNUNET_OS_get_binary_path (const char *progname, const char* prefix);
+
+
 /**
  * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon
  * binary, try to prefix it with the libexec/-directory to get the
index f2d24f85e72eeae777177f132c7272222fdf24d5..973cda6b1440f28b05c70cc4c062a20a36efb824 100644 (file)
@@ -769,18 +769,19 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
 
 
 /**
- * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon
- * binary, try to prefix it with the libexec/-directory to get the
- * full path.
+ * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary and
+ * a prefix, construct the full path to the binary.
  *
  * @param progname name of the binary
+ * @param prefix the path to use as a prefix (if NULL this function is
+ *        equivalent to GNUNET_OS_get_libexec_binary_path)
  * @return full path to the binary, if possible, otherwise copy of 'progname'
  */
 char *
-GNUNET_OS_get_libexec_binary_path (const char *progname)
+GNUNET_OS_get_binary_path (const char *progname, const char* prefix)
 {
-  static char *cache;
-  char *libexecdir;
+  static const char *cache;
+  const char *path;
   char *binary;
 
   if ( (DIR_SEPARATOR == progname[0]) ||
@@ -789,21 +790,38 @@ GNUNET_OS_get_libexec_binary_path (const char *progname)
                                          GNUNET_NO,
                                          NULL, NULL)) )
     return GNUNET_strdup (progname);
-  if (NULL != cache)
-    libexecdir = cache;
+  if (NULL != prefix)
+    path = prefix;
+  else if (NULL != cache)
+    path = cache;
   else
-    libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR);
-  if (NULL == libexecdir)
+    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR);
+  if (NULL == path)
     return GNUNET_strdup (progname);
   GNUNET_asprintf (&binary,
                   "%s%s",
-                  libexecdir,
+                  path,
                   progname);
-  cache = libexecdir;
+  cache = path;
   return binary;
 }
 
 
+/**
+ * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon
+ * binary, try to prefix it with the libexec/-directory to get the
+ * full path.
+ *
+ * @param progname name of the binary
+ * @return full path to the binary, if possible, otherwise copy of 'progname'
+ */
+char *
+GNUNET_OS_get_libexec_binary_path (const char *progname)
+{
+  return GNUNET_OS_get_binary_path (progname, NULL);
+}
+
+
 /**
  * Check whether an executable exists and possibly if the suid bit is
  * set on the file.  Attempts to find the file using the current PATH