From ce50ea323045407b7c71bf3253464498a5efa880 Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Mon, 6 Mar 2017 07:58:06 +0200 Subject: [PATCH] Add workaround to make possible to close memfds after dlopen --- client/sources-linux/tmplibrary.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/sources-linux/tmplibrary.c b/client/sources-linux/tmplibrary.c index ed9f68a4..c27afc82 100644 --- a/client/sources-linux/tmplibrary.c +++ b/client/sources-linux/tmplibrary.c @@ -189,8 +189,24 @@ void *memdlopen(const char *soname, const char *buffer, size_t size) { dprint("Library \"%s\" dropped to \"%s\" (memfd=%d) \n", soname, buf, is_memfd); - base = dlopen(buf, RTLD_NOW | RTLD_GLOBAL); +#ifndef NO_MEMFD_DLOPEN_WORKAROUND + if (is_memfd) { + char *fake_path = tempnam("/dev/shm", NULL); + if (!fake_path) { + fake_path = tempnam("/tmp", NULL); + } + if (fake_path) { + if (!symlink(buf, fake_path)) { + strncpy(buf, fake_path, sizeof(buf)-1); + is_memfd = false; + } + free(fake_path); + } + } +#endif + + base = dlopen(buf, RTLD_NOW | RTLD_GLOBAL); if (!is_memfd) { close(fd); }