Kaydet (Commit) bdb10815 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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: 's avatarTor Lillqvist <tml@collabora.com>
üst 5481ca58
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment