summaryrefslogtreecommitdiff
path: root/drivers/unix/os_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix/os_unix.cpp')
-rw-r--r--drivers/unix/os_unix.cpp73
1 files changed, 52 insertions, 21 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index bc18707deb..05dfd69f58 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "os_unix.h"
#ifdef UNIX_ENABLED
@@ -52,6 +53,7 @@
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/param.h>
+#include <sys/sysctl.h>
#endif
#include "project_settings.h"
#include <assert.h>
@@ -71,13 +73,21 @@ void OS_Unix::debug_break() {
assert(false);
};
-int OS_Unix::get_audio_driver_count() const {
+static void handle_interrupt(int sig) {
+ if (ScriptDebugger::get_singleton() == NULL)
+ return;
- return 1;
+ ScriptDebugger::get_singleton()->set_depth(-1);
+ ScriptDebugger::get_singleton()->set_lines_left(1);
}
-const char *OS_Unix::get_audio_driver_name(int p_driver) const {
- return "dummy";
+void OS_Unix::initialize_debugging() {
+
+ if (ScriptDebugger::get_singleton() != NULL) {
+ struct sigaction action;
+ action.sa_handler = handle_interrupt;
+ sigaction(SIGINT, &action, NULL);
+ }
}
int OS_Unix::unix_initialize_audio(int p_audio_driver) {
@@ -96,10 +106,11 @@ void handle_sigchld(int sig) {
void OS_Unix::initialize_core() {
-#ifdef NO_PTHREADS
+#ifdef NO_THREADS
ThreadDummy::make_default();
SemaphoreDummy::make_default();
MutexDummy::make_default();
+ RWLockDummy::make_default();
#else
ThreadPosix::make_default();
SemaphorePosix::make_default();
@@ -233,7 +244,7 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
void OS_Unix::delay_usec(uint32_t p_usec) const {
- struct timespec rem = { p_usec / 1000000, (p_usec % 1000000) * 1000 };
+ struct timespec rem = { static_cast<time_t>(p_usec / 1000000), static_cast<long>((p_usec % 1000000) * 1000) };
while (nanosleep(&rem, &rem) == EINTR) {
}
}
@@ -294,20 +305,10 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
Vector<char *> args;
for (int i = 0; i < cs.size(); i++)
- args.push_back((char *)cs[i].get_data()); // shitty C cast
+ args.push_back((char *)cs[i].get_data());
args.push_back(0);
-#ifdef __FreeBSD__
- if (p_path.find("/")) {
- // 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();
@@ -362,7 +363,26 @@ String OS_Unix::get_locale() const {
}
Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
- p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW);
+
+ String path = p_path;
+
+ if (FileAccess::exists(path) && path.is_rel_path()) {
+ // dlopen expects a slash, in this case a leading ./ for it to be interpreted as a relative path,
+ // otherwise it will end up searching various system directories for the lib instead and finally failing.
+ path = "./" + path;
+ }
+
+ if (!FileAccess::exists(path)) {
+ //this code exists so gdnative can load .so files from within the executable path
+ path = get_executable_path().get_base_dir().plus_file(p_path.get_file());
+ }
+
+ if (!FileAccess::exists(path)) {
+ //this code exists so gdnative can load .so files from a standard unix location
+ path = get_executable_path().get_base_dir().plus_file("../lib").plus_file(p_path.get_file());
+ }
+
+ p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
if (!p_library_handle) {
ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror());
ERR_FAIL_V(ERR_CANT_OPEN);
@@ -448,12 +468,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;