Mercurial > hg > truffle
comparison agent/src/os/linux/libproc_impl.c @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | d7cb88bd7046 |
children |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
27 #include <string.h> | 27 #include <string.h> |
28 #include <fcntl.h> | 28 #include <fcntl.h> |
29 #include <thread_db.h> | 29 #include <thread_db.h> |
30 #include "libproc_impl.h" | 30 #include "libproc_impl.h" |
31 | 31 |
32 static const char* alt_root = NULL; | |
33 static int alt_root_len = -1; | |
34 | |
32 #define SA_ALTROOT "SA_ALTROOT" | 35 #define SA_ALTROOT "SA_ALTROOT" |
33 | 36 |
37 static void init_alt_root() { | |
38 if (alt_root_len == -1) { | |
39 alt_root = getenv(SA_ALTROOT); | |
40 if (alt_root) { | |
41 alt_root_len = strlen(alt_root); | |
42 } else { | |
43 alt_root_len = 0; | |
44 } | |
45 } | |
46 } | |
47 | |
34 int pathmap_open(const char* name) { | 48 int pathmap_open(const char* name) { |
35 static const char *alt_root = NULL; | 49 int fd; |
36 static int alt_root_initialized = 0; | 50 char alt_path[PATH_MAX + 1]; |
37 | 51 |
38 int fd; | 52 init_alt_root(); |
39 char alt_path[PATH_MAX + 1], *alt_path_end; | 53 |
40 const char *s; | 54 if (alt_root_len > 0) { |
41 | 55 strcpy(alt_path, alt_root); |
42 if (!alt_root_initialized) { | 56 strcat(alt_path, name); |
43 alt_root_initialized = -1; | 57 fd = open(alt_path, O_RDONLY); |
44 alt_root = getenv(SA_ALTROOT); | 58 if (fd >= 0) { |
45 } | 59 print_debug("path %s substituted for %s\n", alt_path, name); |
46 | 60 return fd; |
47 if (alt_root == NULL) { | 61 } |
48 return open(name, O_RDONLY); | 62 |
49 } | 63 if (strrchr(name, '/')) { |
50 | 64 strcpy(alt_path, alt_root); |
51 strcpy(alt_path, alt_root); | 65 strcat(alt_path, strrchr(name, '/')); |
52 alt_path_end = alt_path + strlen(alt_path); | 66 fd = open(alt_path, O_RDONLY); |
53 | 67 if (fd >= 0) { |
54 // Strip path items one by one and try to open file with alt_root prepended | 68 print_debug("path %s substituted for %s\n", alt_path, name); |
55 s = name; | 69 return fd; |
56 while (1) { | 70 } |
57 strcat(alt_path, s); | 71 } |
58 s += 1; | 72 } else { |
59 | 73 fd = open(name, O_RDONLY); |
60 fd = open(alt_path, O_RDONLY); | 74 if (fd >= 0) { |
61 if (fd >= 0) { | 75 return fd; |
62 print_debug("path %s substituted for %s\n", alt_path, name); | 76 } |
63 return fd; | 77 } |
64 } | 78 |
65 | 79 return -1; |
66 // Linker always put full path to solib to process, so we can rely | |
67 // on presence of /. If slash is not present, it means, that SOlib doesn't | |
68 // physically exist (e.g. linux-gate.so) and we fail opening it anyway | |
69 if ((s = strchr(s, '/')) == NULL) { | |
70 break; | |
71 } | |
72 | |
73 *alt_path_end = 0; | |
74 } | |
75 | |
76 return -1; | |
77 } | 80 } |
78 | 81 |
79 static bool _libsaproc_debug; | 82 static bool _libsaproc_debug; |
80 | 83 |
81 void print_debug(const char* format,...) { | 84 void print_debug(const char* format,...) { |