Download raw body.
godot/pack3: get_executable_path via getexecpath(3)
Hi,
Diff to fix the previously rather painful handling and discussion with
upstream, see [1]. Following mostly the linux example. I'm not sure how
critical the whole append_utf8 stuff is, but kept it in line with
Linux. I tested it with running commercial games (Road to Vostok, How
to Kill a Fly), and with the editor. For the curious, I tested it first
with a printf in there, and launching the editor and then a project
leads to 9 calls to get_executable_path FYI; running the games only
one or 2.
Made a new PR with upstream at [2].
Planning to commit this in the next days if I don't hear objections,
but sharing here to see if there is feedback or ok's.
[1] https://github.com/godotengine/godot/pull/61540
[2] https://github.com/godotengine/godot/pull/123566
Index: Makefile
===================================================================
RCS file: /cvs/ports/games/godot/pack3/Makefile,v
diff -u -p -r1.7 Makefile
--- Makefile 22 Aug 2026 22:42:44 -0000 1.7
+++ Makefile 16 Sep 2026 21:40:26 -0000
@@ -9,6 +9,7 @@ COMMENT-editor= 2D and 3D game engine (w
VERSION = 4.7.2
PKGNAME = godot-${VERSION}
DIST_TUPLE += codeberg godotsteam godotsteam v4.5.4 godotsteam
+REVISION = 0
MULTI_PACKAGES = -main -editor
PKGSPEC-main = godot->=4.5
Index: patches/patch-drivers_unix_os_unix_cpp
===================================================================
RCS file: /cvs/ports/games/godot/pack3/patches/patch-drivers_unix_os_unix_cpp,v
diff -u -p -r1.2 patch-drivers_unix_os_unix_cpp
--- patches/patch-drivers_unix_os_unix_cpp 8 Jul 2026 04:05:53 -0000 1.2
+++ patches/patch-drivers_unix_os_unix_cpp 16 Sep 2026 21:40:26 -0000
@@ -1,65 +1,26 @@
-fix get_executable_path(); backport of
-<https://github.com/godotengine/godot/pull/61540>.
+get_executable_path(): use getexecpath(3)
+https://github.com/godotengine/godot/pull/123566
Index: drivers/unix/os_unix.cpp
--- drivers/unix/os_unix.cpp.orig
+++ drivers/unix/os_unix.cpp
-@@ -1158,12 +1158,6 @@ String OS_Unix::get_executable_path() const {
- return OS::get_executable_path();
+@@ -1159,11 +1159,16 @@ String OS_Unix::get_executable_path() const {
}
return b;
--#elif defined(__OpenBSD__)
+ #elif defined(__OpenBSD__)
- char resolved_path[MAXPATHLEN];
--
++ char buf[PATH_MAX];
++ String b;
+
- realpath(OS::get_executable_path().utf8().get_data(), resolved_path);
--
++ if (getexecpath(buf, sizeof(buf)) != 0) {
++ ERR_FAIL_V(vformat("getexecpath error: %d - %s", errno, strerror(errno)));
++ }
+
- return String(resolved_path);
++ b.append_utf8(buf, strnlen(buf, sizeof(buf)));
++
++ return b;
#elif defined(__NetBSD__)
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
char buf[MAXPATHLEN];
-@@ -1205,8 +1199,43 @@ String OS_Unix::get_executable_path() const {
-
- return path;
- #else
-- ERR_PRINT("Warning, don't know how to obtain executable path on this OS! Please override this function properly.");
-- return OS::get_executable_path();
-+ char path[PATH_MAX];
-+ String prog;
-+ const char *argv0;
-+ char *e, *dup, *t, *entry;
-+
-+ prog = OS::get_executable_path();
-+ argv0 = prog.utf8().get_data(); // XXX what if it's not utf8?
-+
-+ if (*argv0 == '/' || strncmp(argv0, "./", 2) == 0) {
-+ if (realpath(argv0, path) != NULL)
-+ return String(path);
-+ }
-+
-+ if ((e = getenv("PATH")) == NULL) {
-+ WARN_PRINT("PATH not defined and argv[0] doesn't seem"
-+ " a path");
-+ return prog;
-+ }
-+
-+ if ((dup = strdup(e)) == NULL)
-+ return prog;
-+
-+ t = dup;
-+ while ((entry = strsep(&t, ":")) != NULL) {
-+ int r = snprintf(path, sizeof(path), "%s/%s",
-+ entry, argv0);
-+ if (r < 0 || (size_t)r >= sizeof(path))
-+ continue;
-+ if (access(path, X_OK) == 0) {
-+ free(dup);
-+ return String(path);
-+ }
-+ }
-+ free(dup);
-+
-+ WARN_PRINT("executable path not found!");
-+ return prog;
- #endif
- }
-
godot/pack3: get_executable_path via getexecpath(3)