summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2018-10-22 22:00:49 +0300
committerTor Lillqvist <tml@collabora.com>2018-10-23 12:26:51 +0200
commitbdb10815a6003052417421e2b1eb1faf61f52931 (patch)
tree0d8889b35a00f51b295614ba16311b2a059926bf /sal
parent5481ca586df8eed2c832e00bc5f7e910fa2cd174 (diff)
dlsym() typically does not find "main" so use readlink() on /proc/self/exe
Change-Id: I37b77fbc393b743fd508b7e3330409e90c7097b9 Reviewed-on: https://gerrit.libreoffice.org/62196 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/process_impl.cxx22
1 files changed, 21 insertions, 1 deletions
diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx
index f7397d48f242..b232695cd57f 100644
--- a/sal/osl/unx/process_impl.cxx
+++ b/sal/osl/unx/process_impl.cxx
@@ -25,7 +25,7 @@
#include <string.h>
#include <osl/diagnose.h>
-#include <osl/file.h>
+#include <osl/file.hxx>
#include <osl/module.h>
#include <osl/thread.h>
#include <rtl/alloc.h>
@@ -100,6 +100,26 @@ oslProcessError bootstrap_getExecutableFile(rtl_uString ** ppFileURL)
* any */
void * addr = dlsym (RTLD_DEFAULT, "JNI_OnLoad");
#else
+#if defined __linux
+ // The below code looking for "main" with dlsym() will typically
+ // fail, as there is little reason for "main" to be exported, in
+ // the dlsym() sense, from an executable. But Linux has
+ // /proc/self/exe, try using that.
+ char buf[PATH_MAX];
+ int rc = readlink("/proc/self/exe", buf, sizeof(buf));
+ if (rc > 0 && rc < PATH_MAX)
+ {
+ buf[rc] = '\0';
+ OUString path = OUString::fromUtf8(buf);
+ OUString fileURL;
+ if (osl::File::getFileURLFromSystemPath(path, fileURL) == osl::File::E_None)
+ {
+ rtl_uString_acquire(fileURL.pData);
+ *ppFileURL = fileURL.pData;
+ return osl_Process_E_None;
+ }
+ }
+#endif
/* Determine address of "main()" function. */
void * addr = dlsym (RTLD_DEFAULT, "main");
#endif