aboutsummaryrefslogtreecommitdiff
path: root/src/util
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 /src/util
parent32063cf3f2f09f39634dac791f4b71e4bd15cc47 (diff)
downloadgnunet-526f247237ac70910b4974349418bbcbe7d9a123.tar.gz
gnunet-526f247237ac70910b4974349418bbcbe7d9a123.zip
introduce GNUNET_OS_installation_get_path (useful for custom helper paths)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/os_installation.c42
1 files changed, 30 insertions, 12 deletions
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)
769 769
770 770
771/** 771/**
772 * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon 772 * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary and
773 * binary, try to prefix it with the libexec/-directory to get the 773 * a prefix, construct the full path to the binary.
774 * full path.
775 * 774 *
776 * @param progname name of the binary 775 * @param progname name of the binary
776 * @param prefix the path to use as a prefix (if NULL this function is
777 * equivalent to GNUNET_OS_get_libexec_binary_path)
777 * @return full path to the binary, if possible, otherwise copy of 'progname' 778 * @return full path to the binary, if possible, otherwise copy of 'progname'
778 */ 779 */
779char * 780char *
780GNUNET_OS_get_libexec_binary_path (const char *progname) 781GNUNET_OS_get_binary_path (const char *progname, const char* prefix)
781{ 782{
782 static char *cache; 783 static const char *cache;
783 char *libexecdir; 784 const char *path;
784 char *binary; 785 char *binary;
785 786
786 if ( (DIR_SEPARATOR == progname[0]) || 787 if ( (DIR_SEPARATOR == progname[0]) ||
@@ -789,22 +790,39 @@ GNUNET_OS_get_libexec_binary_path (const char *progname)
789 GNUNET_NO, 790 GNUNET_NO,
790 NULL, NULL)) ) 791 NULL, NULL)) )
791 return GNUNET_strdup (progname); 792 return GNUNET_strdup (progname);
792 if (NULL != cache) 793 if (NULL != prefix)
793 libexecdir = cache; 794 path = prefix;
795 else if (NULL != cache)
796 path = cache;
794 else 797 else
795 libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); 798 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR);
796 if (NULL == libexecdir) 799 if (NULL == path)
797 return GNUNET_strdup (progname); 800 return GNUNET_strdup (progname);
798 GNUNET_asprintf (&binary, 801 GNUNET_asprintf (&binary,
799 "%s%s", 802 "%s%s",
800 libexecdir, 803 path,
801 progname); 804 progname);
802 cache = libexecdir; 805 cache = path;
803 return binary; 806 return binary;
804} 807}
805 808
806 809
807/** 810/**
811 * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon
812 * binary, try to prefix it with the libexec/-directory to get the
813 * full path.
814 *
815 * @param progname name of the binary
816 * @return full path to the binary, if possible, otherwise copy of 'progname'
817 */
818char *
819GNUNET_OS_get_libexec_binary_path (const char *progname)
820{
821 return GNUNET_OS_get_binary_path (progname, NULL);
822}
823
824
825/**
808 * Check whether an executable exists and possibly if the suid bit is 826 * Check whether an executable exists and possibly if the suid bit is
809 * set on the file. Attempts to find the file using the current PATH 827 * set on the file. Attempts to find the file using the current PATH
810 * environment variable as a search path. 828 * environment variable as a search path.