summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Drahoš <drahosp@gmail.com>2013-04-01 14:40:24 +0200
committerPeter Drahoš <drahosp@gmail.com>2013-04-01 14:40:24 +0200
commiteb0e9be8bd00ffd814da0fba9786df5d844d3e98 (patch)
treef138c1c059e770e28da266df82e6a1eff92ae79a
parenteccb1aec0386293903219aa73130bab480d8e181 (diff)
downloadlua-eb0e9be8bd00ffd814da0fba9786df5d844d3e98.tar.gz
Relative path fix for FreeBSD and Solaris
-rw-r--r--CMakeLists.txt7
-rw-r--r--src/loadlib_rel.c25
2 files changed, 26 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f8e72f..d96b4bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2012 LuaDist.
+# Copyright (C) 2007-2013 LuaDist.
# Created by Peter Drahoš, Peter Kapec
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
@@ -82,7 +82,10 @@ endif ( )
if ( LUA_USE_DLOPEN )
# Link to dynamic linker library "dl"
- list ( APPEND LIBS dl )
+ find_library ( DL_LIBRARY NAMES dl )
+ if ( DL_LIBRARY )
+ list ( APPEND LIBS ${DL_LIBRARY} )
+ endif ( )
endif ( )
if ( LUA_USE_READLINE )
diff --git a/src/loadlib_rel.c b/src/loadlib_rel.c
index 81bf220..b503740 100644
--- a/src/loadlib_rel.c
+++ b/src/loadlib_rel.c
@@ -132,7 +132,12 @@ static void setprogdir (lua_State *L);
#include <mach-o/dyld.h>
#endif
-static void setprogdir (lua_State *L) {
+#if defined(__FreeBSD__)
+ #include <sys/types.h>
+ #include <sys/sysctl.h>
+#endif
+
+static char* setprogdir () {
char progdir[_PATH_MAX + 1];
char *lb;
int nsize = sizeof(progdir)/sizeof(char);
@@ -147,7 +152,22 @@ static void setprogdir (lua_State *L) {
#elif defined(__linux__)
n = readlink("/proc/self/exe", progdir, nsize);
if (n > 0) progdir[n] = 0;
+#elif defined(__sun)
+ pid_t pid = getpid();
+ char linkname[256]
+ sprintf(linkname, "/proc/%d/path/a.out", pid);
+ n = readlink(linkname, progdir, nsize);
+ if (n > 0) progdir[n] = 0;
#elif defined(__FreeBSD__)
+ int mib[4];
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PATHNAME;
+ mib[3] = -1;
+ size_t cb = sizeof(progdir);
+ sysctl(mib, 4, progdir, &cb, NULL, 0);
+ n = cb;
+#elif defined(__BSD__)
n = readlink("/proc/curproc/file", progdir, nsize);
if (n > 0) progdir[n] = 0;
#elif defined(__APPLE__)
@@ -174,9 +194,6 @@ static void setprogdir (lua_State *L) {
luaL_error(L, "unable to get process executable path");
else {
*lb = '\0';
- // Set progdir global
- lua_pushstring(L, progdir);
- lua_setglobal(L, "_PROGDIR");
// Replace the relative path placeholder
luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, progdir);