summaryrefslogtreecommitdiff
path: root/mysys/my_addr_resolve.c
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-02-02 11:41:16 +0100
committerSergei Golubchik <serg@mariadb.org>2018-02-02 11:42:07 +0100
commit29031fe391d53f6befcd55737539af477c447a9d (patch)
treef091da17789b6bbedb10de42b1e4124f997f3c8f /mysys/my_addr_resolve.c
parentbd0eb2bdd7523aa6341645886ef02e28dc31b4b5 (diff)
downloadmariadb-git-29031fe391d53f6befcd55737539af477c447a9d.tar.gz
my_addr_resolve fixes
* use a longer timeout, 10ms is not always enough * stop waiting as long as the data is read, do not unconditionally wait for timeout every time
Diffstat (limited to 'mysys/my_addr_resolve.c')
-rw-r--r--mysys/my_addr_resolve.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/mysys/my_addr_resolve.c b/mysys/my_addr_resolve.c
index e9685985660..82043dc03fe 100644
--- a/mysys/my_addr_resolve.c
+++ b/mysys/my_addr_resolve.c
@@ -186,13 +186,13 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
ssize_t total_bytes_read = 0;
ssize_t extra_bytes_read = 0;
+ ssize_t parsed = 0;
fd_set set;
struct timeval timeout;
int filename_start = -1;
int line_number_start = -1;
- ssize_t i;
Dl_info info;
void *offset;
@@ -221,11 +221,12 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
FD_ZERO(&set);
FD_SET(out[0], &set);
- /* 10 ms should be plenty of time for addr2line to issue a response. */
+ /* 100 ms should be plenty of time for addr2line to issue a response. */
timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
+ timeout.tv_usec = 100000;
/* Read in a loop till all the output from addr2line is complete. */
- while (select(out[0] + 1, &set, NULL, NULL, &timeout) > 0)
+ while (parsed == total_bytes_read &&
+ select(out[0] + 1, &set, NULL, NULL, &timeout) > 0)
{
extra_bytes_read= read(out[0], output + total_bytes_read,
sizeof(output) - total_bytes_read);
@@ -236,35 +237,33 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
break;
total_bytes_read += extra_bytes_read;
- }
-
- /* Failed starting addr2line. */
- if (total_bytes_read == 0)
- return 1;
- /* Go through the addr2line response and get the required data.
- The response is structured in 2 lines. The first line contains the function
- name, while the second one contains <filename>:<line number> */
- for (i = 0; i < total_bytes_read; i++) {
- if (output[i] == '\n') {
- filename_start = i + 1;
- output[i] = '\0';
- }
- if (filename_start != -1 && output[i] == ':') {
- line_number_start = i + 1;
- output[i] = '\0';
- }
- if (line_number_start != -1) {
- loc->line= atoi(output + line_number_start);
- break;
+ /* Go through the addr2line response and get the required data.
+ The response is structured in 2 lines. The first line contains the function
+ name, while the second one contains <filename>:<line number> */
+ for (; parsed < total_bytes_read; parsed++)
+ {
+ if (output[parsed] == '\n')
+ {
+ filename_start = parsed + 1;
+ output[parsed] = '\0';
+ }
+ if (filename_start != -1 && output[parsed] == ':')
+ {
+ line_number_start = parsed + 1;
+ output[parsed] = '\0';
+ break;
+ }
}
}
+
/* Response is malformed. */
if (filename_start == -1 || line_number_start == -1)
return 1;
loc->func= output;
loc->file= output + filename_start;
+ loc->line= atoi(output + line_number_start);
/* Addr2line was unable to extract any meaningful information. */
if (strcmp(loc->file, "??") == 0)