summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2018-02-08 19:06:25 +0400
committerAlexander Barkov <bar@mariadb.org>2018-02-08 19:06:25 +0400
commit3cad31f2a758f797ef0acac5625d0e007ecbce93 (patch)
tree73c054636c4858b2a51eddf7eaa653746d67524e /mysys
parent560b9895d413bdfedda0a0ca871a635858990c05 (diff)
parent5c057b3fef3aa92cfadbd63043799b430132a494 (diff)
downloadmariadb-git-3cad31f2a758f797ef0acac5625d0e007ecbce93.tar.gz
Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Diffstat (limited to 'mysys')
-rw-r--r--mysys/ma_dyncol.c60
-rw-r--r--mysys/mf_iocache.c2
-rw-r--r--mysys/my_addr_resolve.c165
-rw-r--r--mysys/my_alloc.c10
-rw-r--r--mysys/my_default.c5
-rw-r--r--mysys/my_lib.c10
-rw-r--r--mysys/my_thr_init.c1
7 files changed, 161 insertions, 92 deletions
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c
index 3c15e373182..2e00ca72f74 100644
--- a/mysys/ma_dyncol.c
+++ b/mysys/ma_dyncol.c
@@ -3818,6 +3818,58 @@ end:
DBUG_RETURN(rc);
}
+static
+my_bool dynstr_append_json_quoted(DYNAMIC_STRING *str,
+ const char *append, size_t len)
+{
+ uint additional= ((str->alloc_increment && str->alloc_increment > 6) ?
+ str->alloc_increment :
+ 10);
+ uint lim= additional;
+ uint i;
+ if (dynstr_realloc(str, len + additional + 2))
+ return TRUE;
+ str->str[str->length++]= '"';
+ for (i= 0; i < len; i++)
+ {
+ register char c= append[i];
+ if (unlikely(c <= 0x1F))
+ {
+ if (lim < 5)
+ {
+ if (dynstr_realloc(str, additional))
+ return TRUE;
+ lim+= additional;
+ }
+ lim-= 5;
+ str->str[str->length++]= '\\';
+ str->str[str->length++]= 'u';
+ str->str[str->length++]= '0';
+ str->str[str->length++]= '0';
+ str->str[str->length++]= (c < 0x10 ? '0' : '1');
+ c%= 0x10;
+ str->str[str->length++]= (c < 0xA ? '0' + c : 'A' + (c - 0xA));
+ }
+ else
+ {
+ if (c == '"' || c == '\\')
+ {
+ if (!lim)
+ {
+ if (dynstr_realloc(str, additional))
+ return TRUE;
+ lim= additional;
+ }
+ lim--;
+ str->str[str->length++]= '\\';
+ }
+ str->str[str->length++]= c;
+ }
+ }
+ str->str[str->length++]= '"';
+ return FALSE;
+}
+
enum enum_dyncol_func_result
mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
@@ -3883,7 +3935,10 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
return ER_DYNCOL_RESOURCE;
}
if (quote)
- rc= dynstr_append_quoted(str, from, len, quote);
+ if (quote == DYNCOL_JSON_ESC)
+ rc= dynstr_append_json_quoted(str, from, len);
+ else
+ rc= dynstr_append_quoted(str, from, len, quote);
else
rc= dynstr_append_mem(str, from, len);
if (alloc)
@@ -4183,7 +4238,8 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json,
}
else
{
- if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, '"')) < 0)
+ if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, DYNCOL_JSON_ESC))
+ < 0)
goto err;
}
}
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index 4dd0f7500aa..09adb704622 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -272,7 +272,7 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize,
else
{
/* Clear mutex so that safe_mutex will notice that it's not initialized */
- bzero((char*) &info->append_buffer_lock, sizeof(info));
+ bzero((char*) &info->append_buffer_lock, sizeof(info->append_buffer_lock));
}
#endif
diff --git a/mysys/my_addr_resolve.c b/mysys/my_addr_resolve.c
index 83716bf11e1..10f8552f226 100644
--- a/mysys/my_addr_resolve.c
+++ b/mysys/my_addr_resolve.c
@@ -34,13 +34,6 @@ static const char *strip_path(const char *s)
return prev;
}
-#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN)
-#include <link.h>
-static ptrdiff_t offset= 0;
-#else
-#define offset 0
-#endif
-
/*
The following is very much single-threaded code and it's only supposed
to be used on shutdown or for a crash report
@@ -145,10 +138,52 @@ err:
#include <m_string.h>
#include <ctype.h>
+#include <sys/wait.h>
static int in[2], out[2];
-static int initialized= 0;
+static pid_t pid;
+static char addr2line_binary[1024];
static char output[1024];
+
+int start_addr2line_fork(const char *binary_path)
+{
+
+ if (pid > 0)
+ {
+ /* Don't leak FDs */
+ close(in[1]);
+ close(out[0]);
+ /* Don't create zombie processes. */
+ waitpid(pid, NULL, 0);
+ }
+
+ if (pipe(in) < 0)
+ return 1;
+ if (pipe(out) < 0)
+ return 1;
+
+ pid = fork();
+ if (pid == -1)
+ return 1;
+
+ if (!pid) /* child */
+ {
+ dup2(in[0], 0);
+ dup2(out[1], 1);
+ close(in[0]);
+ close(in[1]);
+ close(out[0]);
+ close(out[1]);
+ execlp("addr2line", "addr2line", "-C", "-f", "-e", binary_path, NULL);
+ exit(1);
+ }
+
+ close(in[0]);
+ close(out[1]);
+
+ return 0;
+}
+
int my_addr_resolve(void *ptr, my_addr_loc *loc)
{
char input[32];
@@ -156,69 +191,88 @@ 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;
- FD_ZERO(&set);
- FD_SET(out[0], &set);
+ Dl_info info;
+ void *offset;
+ if (!dladdr(ptr, &info))
+ return 1;
+
+ if (strcmp(addr2line_binary, info.dli_fname))
+ {
+ /* We use dli_fname in case the path is longer than the length of our static
+ string. We don't want to allocate anything dynamicaly here as we are in
+ a "crashed" state. */
+ if (start_addr2line_fork(info.dli_fname))
+ {
+ addr2line_binary[0] = '\0';
+ return 2;
+ }
+ /* Save result for future comparisons. */
+ strnmov(addr2line_binary, info.dli_fname, sizeof(addr2line_binary));
+ }
+ offset = info.dli_fbase;
len= my_snprintf(input, sizeof(input), "%p\n", ptr - offset);
if (write(in[1], input, len) <= 0)
- return 1;
+ return 3;
+
+ 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);
if (extra_bytes_read < 0)
- return 2;
+ return 4;
/* Timeout or max bytes read. */
if (extra_bytes_read == 0)
break;
total_bytes_read += extra_bytes_read;
- }
-
- /* Failed starting addr2line. */
- if (total_bytes_read == 0)
- return 3;
- /* 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 4;
+ return 5;
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)
- return 5;
+ return 6;
loc->file= strip_path(loc->file);
@@ -227,41 +281,6 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
const char *my_addr_resolve_init()
{
- if (!initialized)
- {
- pid_t pid;
-
-#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN)
- struct link_map *lm = (struct link_map*) dlopen(0, RTLD_NOW);
- if (lm)
- offset= lm->l_addr;
-#endif
-
- if (pipe(in) < 0)
- return "pipe(in)";
- if (pipe(out) < 0)
- return "pipe(out)";
-
- pid = fork();
- if (pid == -1)
- return "fork";
-
- if (!pid) /* child */
- {
- dup2(in[0], 0);
- dup2(out[1], 1);
- close(in[0]);
- close(in[1]);
- close(out[0]);
- close(out[1]);
- execlp("addr2line", "addr2line", "-C", "-f", "-e", my_progname, NULL);
- exit(1);
- }
-
- close(in[0]);
- close(out[1]);
- initialized= 1;
- }
return 0;
}
#endif
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 0dbd571c7fd..7139466be17 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -26,6 +26,8 @@
#define MALLOC_FLAG(A) ((A & 1) ? MY_THREAD_SPECIFIC : 0)
+#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
+
/*
Initialize memory root
@@ -76,13 +78,14 @@ void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size,
if (pre_alloc_size)
{
if ((mem_root->free= mem_root->pre_alloc=
- (USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
- MYF(my_flags))))
+ (USED_MEM*) my_malloc(pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM)),
+ MYF(my_flags))))
{
mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
mem_root->total_alloc= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
mem_root->free->left= pre_alloc_size;
mem_root->free->next= 0;
+ TRASH_MEM(mem_root->free);
}
}
#endif
@@ -154,6 +157,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
mem->left= pre_alloc_size;
mem->next= *prev;
*prev= mem_root->pre_alloc= mem;
+ TRASH_MEM(mem);
}
else
{
@@ -257,6 +261,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
next->size= get_size;
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
*prev=next;
+ TRASH_MEM(next);
}
point= (uchar*) ((char*) next+ (next->size-next->left));
@@ -329,7 +334,6 @@ void *multi_alloc_root(MEM_ROOT *root, ...)
DBUG_RETURN((void*) start);
}
-#define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
/** Mark all data in blocks free for reusage */
diff --git a/mysys/my_default.c b/mysys/my_default.c
index eed87341d8e..ddcc869fa66 100644
--- a/mysys/my_default.c
+++ b/mysys/my_default.c
@@ -1,4 +1,5 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2011, 2018, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -233,7 +234,7 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv,
(char **) &my_defaults_group_suffix);
if (! my_defaults_group_suffix)
- my_defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV));
+ my_defaults_group_suffix= getenv("MYSQL_GROUP_SUFFIX");
if (forced_extra_defaults && !defaults_already_read)
{
diff --git a/mysys/my_lib.c b/mysys/my_lib.c
index 9c465fd5e68..5ab3facc348 100644
--- a/mysys/my_lib.c
+++ b/mysys/my_lib.c
@@ -119,10 +119,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
DBUG_ENTER("my_dir");
DBUG_PRINT("my",("path: '%s' MyFlags: %lu",path,MyFlags));
-#if !defined(HAVE_READDIR_R)
- mysql_mutex_lock(&THR_LOCK_open);
-#endif
-
tmp_file= directory_file_name(tmp_path, path);
if (!(dirp= opendir(tmp_path)))
@@ -174,9 +170,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
}
(void) closedir(dirp);
-#if !defined(HAVE_READDIR_R)
- mysql_mutex_unlock(&THR_LOCK_open);
-#endif
if (MyFlags & MY_WANT_SORT)
sort_dynamic(&dirh->array, (qsort_cmp) comp_names);
@@ -187,9 +180,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
DBUG_RETURN(&dirh->dir);
error:
-#if !defined(HAVE_READDIR_R)
- mysql_mutex_unlock(&THR_LOCK_open);
-#endif
my_errno=errno;
if (dirp)
(void) closedir(dirp);
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 678bfc459c7..3f9c8eeba10 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -385,7 +385,6 @@ void my_thread_end(void)
/* Trash variable so that we can detect false accesses to my_thread_var */
tmp->init= 2;
- TRASH(tmp, sizeof(*tmp));
free(tmp);
}
}