diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-10-22 22:00:49 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-10-23 12:26:51 +0200 |
commit | bdb10815a6003052417421e2b1eb1faf61f52931 (patch) | |
tree | 0d8889b35a00f51b295614ba16311b2a059926bf /sal | |
parent | 5481ca586df8eed2c832e00bc5f7e910fa2cd174 (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.cxx | 22 |
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 |