summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsambler <Develop@Shaneware.Biz>2018-01-08 11:22:24 +1030
committersambler <Develop@Shaneware.Biz>2018-01-08 12:07:28 +1030
commit384055c86fa7a079c2f41e2437389bd5358f4b03 (patch)
tree6d8c2efe9a576e42cd277c24768e097010dc9498
parent37ca542d2bfd9aac296e82e30a76117090dea08e (diff)
Fix use of execvp, earlier fix was short sighted and only worked
when godot could be found in PATH. The correct fix is to use sysctl to get the path to the current executable this also fixes the ability to call external commands.
-rw-r--r--drivers/unix/os_unix.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 0f30e3afdb..5f45f06c79 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -53,6 +53,7 @@
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/param.h>
+#include <sys/sysctl.h>
#endif
#include "project_settings.h"
#include <assert.h>
@@ -298,17 +299,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
args.push_back((char *)cs[i].get_data()); // shitty C cast
args.push_back(0);
-#ifdef __FreeBSD__
- if (p_path.find("/") != -1) {
- // exec name contains path so use it
- execv(p_path.utf8().get_data(), &args[0]);
- } else {
- // use program name and search through PATH to find it
- execvp(getprogname(), &args[0]);
- }
-#else
execvp(p_path.utf8().get_data(), &args[0]);
-#endif
// still alive? something failed..
fprintf(stderr, "**ERROR** OS_Unix::execute - Could not create child process while executing: %s\n", p_path.utf8().get_data());
abort();
@@ -462,12 +453,23 @@ String OS_Unix::get_executable_path() const {
return OS::get_executable_path();
}
return b;
-#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+#elif defined(__OpenBSD__)
char resolved_path[MAXPATHLEN];
realpath(OS::get_executable_path().utf8().get_data(), resolved_path);
return String(resolved_path);
+#elif defined(__FreeBSD__)
+ int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ char buf[MAXPATHLEN];
+ size_t len = sizeof(buf);
+ if (sysctl(mib, 4, buf, &len, NULL, 0) != 0) {
+ WARN_PRINT("Couldn't get executable path from sysctl");
+ return OS::get_executable_path();
+ }
+ String b;
+ b.parse_utf8(buf);
+ return b;
#elif defined(__APPLE__)
char temp_path[1];
uint32_t buff_size = 1;