summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2019-06-27 17:39:03 +0200
committerlurchi <lurchi@strangeplace.net>2019-06-27 17:39:03 +0200
commit526f247237ac70910b4974349418bbcbe7d9a123 (patch)
tree7b87624c2d0e907034bf522b00a0af48d962167e
parent32063cf3f2f09f39634dac791f4b71e4bd15cc47 (diff)
introduce GNUNET_OS_installation_get_path (useful for custom helper paths)
-rw-r--r--src/include/gnunet_os_lib.h13
-rw-r--r--src/util/os_installation.c42
2 files changed, 43 insertions, 12 deletions
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index 285dfb68d..82203267c 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -306,6 +306,19 @@ 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
* full path.
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index f2d24f85e..973cda6b1 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -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,22 +790,39 @@ 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
* environment variable as a search path.