Commit 3dbb0db4 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1599 from gmile/fix-dlinfo

Do not rely on RTLD_DI_ORIGIN
parents f3d3c94b 6cd2a9c0
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <link.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -137,6 +138,7 @@ static int mntns_func(void *arg) { ...@@ -137,6 +138,7 @@ static int mntns_func(void *arg) {
char libpath[1024]; char libpath[1024];
ssize_t rb; ssize_t rb;
void *dlhdl; void *dlhdl;
struct link_map *lm;
if (setup_tmp_mnts() < 0) { if (setup_tmp_mnts() < 0) {
return -1; return -1;
...@@ -149,16 +151,17 @@ static int mntns_func(void *arg) { ...@@ -149,16 +151,17 @@ static int mntns_func(void *arg) {
return -1; return -1;
} }
if (dlinfo(dlhdl, RTLD_DI_ORIGIN, &libpath) < 0) { if (dlinfo(dlhdl, RTLD_DI_LINKMAP, &lm) < 0) {
fprintf(stderr, "Unable to find origin of libz.so.1: %s\n", dlerror()); fprintf(stderr, "Unable to find origin of libz.so.1: %s\n", dlerror());
return -1; return -1;
} }
strncpy(libpath, lm->l_name, 1024);
dlclose(dlhdl); dlclose(dlhdl);
dlhdl = NULL; dlhdl = NULL;
// Copy a shared library from shared mntns to private /tmp // Copy a shared library from shared mntns to private /tmp
snprintf(buf, 4096, "%s/libz.so.1", libpath); snprintf(buf, 4096, "%s", libpath);
in_fd = open(buf, O_RDONLY); in_fd = open(buf, O_RDONLY);
if (in_fd < 0) { if (in_fd < 0) {
fprintf(stderr, "Unable to open %s: %s\n", buf, strerror(errno)); fprintf(stderr, "Unable to open %s: %s\n", buf, strerror(errno));
......
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