diff options
-rw-r--r-- | src/include/gnunet_os_lib.h | 13 | ||||
-rw-r--r-- | src/util/os_installation.c | 42 |
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); | |||
306 | 306 | ||
307 | 307 | ||
308 | /** | 308 | /** |
309 | * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary and | ||
310 | * a prefix, construct the full path to the binary. | ||
311 | * | ||
312 | * @param progname name of the binary | ||
313 | * @param prefix the path to use as a prefix (if NULL this function is | ||
314 | * equivalent to GNUNET_OS_get_libexec_binary_path) | ||
315 | * @return full path to the binary, if possible, otherwise copy of 'progname' | ||
316 | */ | ||
317 | char * | ||
318 | GNUNET_OS_get_binary_path (const char *progname, const char* prefix); | ||
319 | |||
320 | |||
321 | /** | ||
309 | * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon | 322 | * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon |
310 | * binary, try to prefix it with the libexec/-directory to get the | 323 | * binary, try to prefix it with the libexec/-directory to get the |
311 | * full path. | 324 | * 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) | |||
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 | */ |
779 | char * | 780 | char * |
780 | GNUNET_OS_get_libexec_binary_path (const char *progname) | 781 | GNUNET_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 | */ | ||
818 | char * | ||
819 | GNUNET_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. |