Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2022-04-04 17:55:54 +0300
committerArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2022-04-04 17:55:54 +0300
commit602917216b2c11aaa03bf4832ff05b01505dea39 (patch)
tree94845f3b95e845735b9de978327ac424777290e8 /src
parentc31ed1d161e3f97b7437c1361a5868a2ae566e57 (diff)
parent91d6033c9bbfd3c50ecb9febae242a03fcf18aaa (diff)
.......... [DEV-2113] updated to the latest master
Diffstat (limited to 'src')
-rw-r--r--src/libs/Makefile.am6
-rw-r--r--src/libs/zbxalgo/hashmap.c6
-rw-r--r--src/libs/zbxalgo/hashset.c5
-rw-r--r--src/libs/zbxcomms/Makefile.am1
-rw-r--r--src/libs/zbxcomms/comms.c1
-rw-r--r--src/libs/zbxcomms/comms.h43
-rw-r--r--src/libs/zbxcomms/telnet.c30
-rw-r--r--src/libs/zbxdbcache/dbcache.c68
-rw-r--r--src/libs/zbxdbcache/dbconfig.c237
-rw-r--r--src/libs/zbxdbcache/valuecache.c39
-rw-r--r--src/libs/zbxdbcache/valuecache.h4
-rw-r--r--src/libs/zbxdiag/diag.c10
-rw-r--r--src/libs/zbxdiag/diag.h4
-rw-r--r--src/libs/zbxdiag/diag_server.c2
-rw-r--r--src/libs/zbxserver/evalfunc.c1
-rw-r--r--src/libs/zbxserver/expression.c2
-rw-r--r--src/libs/zbxshmem/Makefile.am (renamed from src/libs/zbxmemory/Makefile.am)4
-rw-r--r--src/libs/zbxshmem/memalloc.c (renamed from src/libs/zbxmemory/memalloc.c)228
-rw-r--r--src/libs/zbxsysinfo/simple/simple.c3
-rw-r--r--src/libs/zbxtrends/cache.c20
-rw-r--r--src/zabbix_proxy/Makefile.am2
-rw-r--r--src/zabbix_server/Makefile.am2
-rw-r--r--src/zabbix_server/alerter/alert_manager.c6
-rw-r--r--src/zabbix_server/ipmi/ipmi_manager.c11
-rw-r--r--src/zabbix_server/poller/checks_snmp.c3
-rw-r--r--src/zabbix_server/poller/checks_telnet.c7
-rw-r--r--src/zabbix_server/preprocessor/preproc_manager.c3
-rw-r--r--src/zabbix_server/reporter/report_manager.c53
-rw-r--r--src/zabbix_server/vmware/vmware.c114
29 files changed, 508 insertions, 407 deletions
diff --git a/src/libs/Makefile.am b/src/libs/Makefile.am
index e4232113685..67598051664 100644
--- a/src/libs/Makefile.am
+++ b/src/libs/Makefile.am
@@ -5,7 +5,7 @@ DIST_SUBDIRS = \
zbxdbhigh \
zbxdb \
zbxdbupgrade \
- zbxmemory \
+ zbxshmem \
zbxalgo \
zbxmedia \
zbxcrypto \
@@ -53,7 +53,7 @@ SERVER_SUBDIRS = \
zbxdbcache \
zbxdbhigh \
zbxhttp \
- zbxmemory \
+ zbxshmem \
zbxserver \
zbxicmpping \
zbxmedia \
@@ -84,7 +84,7 @@ PROXY_SUBDIRS = \
zbxdbcache \
zbxdbhigh \
zbxhttp \
- zbxmemory \
+ zbxshmem \
zbxserver \
zbxicmpping \
zbxself \
diff --git a/src/libs/zbxalgo/hashmap.c b/src/libs/zbxalgo/hashmap.c
index 1c95629c146..30943c0794f 100644
--- a/src/libs/zbxalgo/hashmap.c
+++ b/src/libs/zbxalgo/hashmap.c
@@ -38,12 +38,14 @@ static void __hashmap_ensure_free_entry(zbx_hashmap_t *hm, ZBX_HASHMAP_SLOT_T *s
{
slot->entries_num = 0;
slot->entries_alloc = 6;
- slot->entries = (ZBX_HASHMAP_ENTRY_T *)hm->mem_malloc_func(NULL, slot->entries_alloc * sizeof(ZBX_HASHMAP_ENTRY_T));
+ slot->entries = (ZBX_HASHMAP_ENTRY_T *)hm->mem_malloc_func(NULL, slot->entries_alloc *
+ sizeof(ZBX_HASHMAP_ENTRY_T));
}
else if (slot->entries_num == slot->entries_alloc)
{
slot->entries_alloc = slot->entries_alloc * ARRAY_GROWTH_FACTOR;
- slot->entries = (ZBX_HASHMAP_ENTRY_T *)hm->mem_realloc_func(slot->entries, slot->entries_alloc * sizeof(ZBX_HASHMAP_ENTRY_T));
+ slot->entries = (ZBX_HASHMAP_ENTRY_T *)hm->mem_realloc_func(slot->entries, slot->entries_alloc *
+ sizeof(ZBX_HASHMAP_ENTRY_T));
}
}
diff --git a/src/libs/zbxalgo/hashset.c b/src/libs/zbxalgo/hashset.c
index 01a0deab89c..f23fc549cdc 100644
--- a/src/libs/zbxalgo/hashset.c
+++ b/src/libs/zbxalgo/hashset.c
@@ -47,8 +47,11 @@ static int zbx_hashset_init_slots(zbx_hashset_t *hs, size_t init_size)
{
hs->num_slots = next_prime(init_size);
- if (NULL == (hs->slots = (ZBX_HASHSET_ENTRY_T **)hs->mem_malloc_func(NULL, hs->num_slots * sizeof(ZBX_HASHSET_ENTRY_T *))))
+ if (NULL == (hs->slots = (ZBX_HASHSET_ENTRY_T **)hs->mem_malloc_func(NULL, hs->num_slots *
+ sizeof(ZBX_HASHSET_ENTRY_T *))))
+ {
return FAIL;
+ }
memset(hs->slots, 0, hs->num_slots * sizeof(ZBX_HASHSET_ENTRY_T *));
}
diff --git a/src/libs/zbxcomms/Makefile.am b/src/libs/zbxcomms/Makefile.am
index 6821cd8a8a0..77105624244 100644
--- a/src/libs/zbxcomms/Makefile.am
+++ b/src/libs/zbxcomms/Makefile.am
@@ -3,6 +3,7 @@
noinst_LIBRARIES = libzbxcomms.a
libzbxcomms_a_SOURCES = \
+ comms.h \
comms.c \
telnet.c
diff --git a/src/libs/zbxcomms/comms.c b/src/libs/zbxcomms/comms.c
index 151ecb6aec4..a66a5d803fa 100644
--- a/src/libs/zbxcomms/comms.c
+++ b/src/libs/zbxcomms/comms.c
@@ -18,6 +18,7 @@
**/
#include "zbxcomms.h"
+#include "comms.h"
#include "common.h"
#include "base64.h"
diff --git a/src/libs/zbxcomms/comms.h b/src/libs/zbxcomms/comms.h
new file mode 100644
index 00000000000..f862b2ee63b
--- /dev/null
+++ b/src/libs/zbxcomms/comms.h
@@ -0,0 +1,43 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2022 Zabbix SIA
+**
+** 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
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**/
+
+#ifndef ZABBIX_COMMS_H
+#define ZABBIX_COMMS_H
+
+#include "config.h"
+
+#ifdef _WINDOWS
+# define ZBX_TCP_WRITE(s, b, bl) ((ssize_t)send((s), (b), (int)(bl), 0))
+# define ZBX_TCP_READ(s, b, bl) ((ssize_t)recv((s), (b), (int)(bl), 0))
+# define zbx_socket_close(s) if (ZBX_SOCKET_ERROR != (s)) closesocket(s)
+# define zbx_bind(s, a, l) (bind((s), (a), (int)(l)))
+# define zbx_sendto(fd, b, n, f, a, l) (sendto((fd), (b), (int)(n), (f), (a), (l)))
+# define ZBX_PROTO_AGAIN WSAEINTR
+# define ZBX_SOCKET_ERROR INVALID_SOCKET
+#else
+# define ZBX_TCP_WRITE(s, b, bl) ((ssize_t)write((s), (b), (bl)))
+# define ZBX_TCP_READ(s, b, bl) ((ssize_t)read((s), (b), (bl)))
+# define zbx_socket_close(s) if (ZBX_SOCKET_ERROR != (s)) close(s)
+# define zbx_bind(s, a, l) (bind((s), (a), (l)))
+# define zbx_sendto(fd, b, n, f, a, l) (sendto((fd), (b), (n), (f), (a), (l)))
+# define ZBX_PROTO_AGAIN EINTR
+# define ZBX_SOCKET_ERROR -1
+#endif
+
+#endif /* ZABBIX_COMMS_H */
diff --git a/src/libs/zbxcomms/telnet.c b/src/libs/zbxcomms/telnet.c
index 79c7ddf714a..c5ca664173c 100644
--- a/src/libs/zbxcomms/telnet.c
+++ b/src/libs/zbxcomms/telnet.c
@@ -17,11 +17,22 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "telnet.h"
+#include "zbxcomms.h"
+#include "comms.h"
#include "common.h"
#include "log.h"
+#define WAIT_READ 0
+#define WAIT_WRITE 1
+
+#define CMD_IAC 255
+#define CMD_WILL 251
+#define CMD_WONT 252
+#define CMD_DO 253
+#define CMD_DONT 254
+#define OPT_SGA 3
+
static char prompt_char = '\0';
static int telnet_waitsocket(ZBX_SOCKET socket_fd, int mode)
@@ -125,6 +136,9 @@ static ssize_t telnet_socket_write(ZBX_SOCKET socket_fd, const void *buf, size_t
return rc;
}
+#undef WAIT_READ
+#undef WAIT_WRITE
+
static ssize_t telnet_read(ZBX_SOCKET socket_fd, char *buf, size_t *buf_left, size_t *buf_offset)
{
unsigned char c, c1, c2, c3;
@@ -208,6 +222,13 @@ end:
return rc;
}
+#undef CMD_IAC
+#undef CMD_WILL
+#undef CMD_WONT
+#undef CMD_DO
+#undef CMD_DONT
+#undef OPT_SGA
+
/******************************************************************************
* *
* Comments: converts CR+LF to Unix LF and clears CR+NUL *
@@ -305,7 +326,7 @@ static void telnet_rm_prompt(const char *buf, size_t *offset)
}
}
-int telnet_test_login(ZBX_SOCKET socket_fd)
+int zbx_telnet_test_login(ZBX_SOCKET socket_fd)
{
char buf[MAX_BUFFER_LEN];
size_t sz, offset;
@@ -332,7 +353,7 @@ int telnet_test_login(ZBX_SOCKET socket_fd)
return ret;
}
-int telnet_login(ZBX_SOCKET socket_fd, const char *username, const char *password, AGENT_RESULT *result)
+int zbx_telnet_login(ZBX_SOCKET socket_fd, const char *username, const char *password, AGENT_RESULT *result)
{
char buf[MAX_BUFFER_LEN], c;
size_t sz, offset;
@@ -407,7 +428,7 @@ fail:
return ret;
}
-int telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *result, const char *encoding)
+int zbx_telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *result, const char *encoding)
{
char buf[MAX_BUFFER_LEN];
size_t sz, offset;
@@ -433,6 +454,7 @@ int telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *resu
sz = sizeof(buf);
offset = 0;
+
while (ZBX_PROTO_ERROR != (rc = telnet_read(socket_fd, buf, &sz, &offset)))
{
if (prompt_char == telnet_lastchar(buf, offset))
diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c
index 9a70b3bfe9c..ade22f81743 100644
--- a/src/libs/zbxdbcache/dbcache.c
+++ b/src/libs/zbxdbcache/dbcache.c
@@ -34,9 +34,9 @@
#include "zbxtrends.h"
#include "../zbxalgo/vectorimpl.h"
-static zbx_mem_info_t *hc_index_mem = NULL;
-static zbx_mem_info_t *hc_mem = NULL;
-static zbx_mem_info_t *trend_mem = NULL;
+static zbx_shmem_info_t *hc_index_mem = NULL;
+static zbx_shmem_info_t *hc_mem = NULL;
+static zbx_shmem_info_t *trend_mem = NULL;
#define LOCK_CACHE zbx_mutex_lock(cache_lock)
#define UNLOCK_CACHE zbx_mutex_unlock(cache_lock)
@@ -1898,6 +1898,9 @@ static void normalize_item_value(const DC_ITEM *item, ZBX_DC_HISTORY *hdata)
zbx_variant_set_str(&value_var, hdata->value.log->value);
hdata->value.log->value = NULL;
break;
+ default:
+ THIS_SHOULD_NEVER_HAPPEN;
+ return;
}
dc_history_set_value(hdata, item->value_type, &value_var);
@@ -3912,8 +3915,8 @@ void dc_flush_history(void)
* history cache storage *
* *
******************************************************************************/
-ZBX_MEM_FUNC_IMPL(__hc_index, hc_index_mem)
-ZBX_MEM_FUNC_IMPL(__hc, hc_mem)
+ZBX_SHMEM_FUNC_IMPL(__hc_index, hc_index_mem)
+ZBX_SHMEM_FUNC_IMPL(__hc, hc_mem)
/******************************************************************************
* *
@@ -3943,7 +3946,7 @@ static void hc_free_data(zbx_hc_data_t *data)
{
if (ITEM_STATE_NOTSUPPORTED == data->state)
{
- __hc_mem_free_func(data->value.str);
+ __hc_shmem_free_func(data->value.str);
}
else
{
@@ -3953,21 +3956,21 @@ static void hc_free_data(zbx_hc_data_t *data)
{
case ITEM_VALUE_TYPE_STR:
case ITEM_VALUE_TYPE_TEXT:
- __hc_mem_free_func(data->value.str);
+ __hc_shmem_free_func(data->value.str);
break;
case ITEM_VALUE_TYPE_LOG:
- __hc_mem_free_func(data->value.log->value);
+ __hc_shmem_free_func(data->value.log->value);
if (NULL != data->value.log->source)
- __hc_mem_free_func(data->value.log->source);
+ __hc_shmem_free_func(data->value.log->source);
- __hc_mem_free_func(data->value.log);
+ __hc_shmem_free_func(data->value.log);
break;
}
}
}
- __hc_mem_free_func(data);
+ __hc_shmem_free_func(data);
}
/******************************************************************************
@@ -4029,7 +4032,7 @@ static char *hc_mem_value_str_dup(const dc_value_str_t *str)
{
char *ptr;
- if (NULL == (ptr = (char *)__hc_mem_malloc_func(NULL, str->len)))
+ if (NULL == (ptr = (char *)__hc_shmem_malloc_func(NULL, str->len)))
return NULL;
memcpy(ptr, &string_values[str->pvalue], str->len - 1);
@@ -4087,7 +4090,7 @@ static int hc_clone_history_log_data(zbx_log_value_t **dst, const dc_item_value_
if (NULL == *dst)
{
/* using realloc instead of malloc just to suppress 'not used' warning for realloc */
- if (NULL == (*dst = (zbx_log_value_t *)__hc_mem_realloc_func(NULL, sizeof(zbx_log_value_t))))
+ if (NULL == (*dst = (zbx_log_value_t *)__hc_shmem_realloc_func(NULL, sizeof(zbx_log_value_t))))
return FAIL;
memset(*dst, 0, sizeof(zbx_log_value_t));
@@ -4124,7 +4127,7 @@ static int hc_clone_history_data(zbx_hc_data_t **data, const dc_item_value_t *it
{
if (NULL == *data)
{
- if (NULL == (*data = (zbx_hc_data_t *)__hc_mem_malloc_func(NULL, sizeof(zbx_hc_data_t))))
+ if (NULL == (*data = (zbx_hc_data_t *)__hc_shmem_malloc_func(NULL, sizeof(zbx_hc_data_t))))
return FAIL;
memset(*data, 0, sizeof(zbx_hc_data_t));
@@ -4487,7 +4490,7 @@ int hc_get_history_compression_age(void)
* *
******************************************************************************/
-ZBX_MEM_FUNC_IMPL(__trend, trend_mem)
+ZBX_SHMEM_FUNC_IMPL(__trend, trend_mem)
static int init_trend_cache(char **error)
{
@@ -4499,8 +4502,8 @@ static int init_trend_cache(char **error)
if (SUCCEED != (ret = zbx_mutex_create(&trends_lock, ZBX_MUTEX_TRENDS, error)))
goto out;
- sz = zbx_mem_required_size(1, "trend cache", "TrendCacheSize");
- if (SUCCEED != (ret = zbx_mem_create(&trend_mem, CONFIG_TRENDS_CACHE_SIZE, "trend cache", "TrendCacheSize", 0,
+ sz = zbx_shmem_required_size(1, "trend cache", "TrendCacheSize");
+ if (SUCCEED != (ret = zbx_shmem_create(&trend_mem, CONFIG_TRENDS_CACHE_SIZE, "trend cache", "TrendCacheSize", 0,
error)))
{
goto out;
@@ -4517,7 +4520,7 @@ static int init_trend_cache(char **error)
zbx_hashset_create_ext(&cache->trends, INIT_HASHSET_SIZE,
ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC, NULL,
- __trend_mem_malloc_func, __trend_mem_realloc_func, __trend_mem_free_func);
+ __trend_shmem_malloc_func, __trend_shmem_realloc_func, __trend_shmem_free_func);
#undef INIT_HASHSET_SIZE
out:
@@ -4549,38 +4552,39 @@ int init_database_cache(char **error)
if (SUCCEED != (ret = zbx_mutex_create(&cache_ids_lock, ZBX_MUTEX_CACHE_IDS, error)))
goto out;
- if (SUCCEED != (ret = zbx_mem_create(&hc_mem, CONFIG_HISTORY_CACHE_SIZE, "history cache",
+ if (SUCCEED != (ret = zbx_shmem_create(&hc_mem, CONFIG_HISTORY_CACHE_SIZE, "history cache",
"HistoryCacheSize", 1, error)))
{
goto out;
}
- if (SUCCEED != (ret = zbx_mem_create(&hc_index_mem, CONFIG_HISTORY_INDEX_CACHE_SIZE, "history index cache",
+ if (SUCCEED != (ret = zbx_shmem_create(&hc_index_mem, CONFIG_HISTORY_INDEX_CACHE_SIZE, "history index cache",
"HistoryIndexCacheSize", 0, error)))
{
goto out;
}
- cache = (ZBX_DC_CACHE *)__hc_index_mem_malloc_func(NULL, sizeof(ZBX_DC_CACHE));
+ cache = (ZBX_DC_CACHE *)__hc_index_shmem_malloc_func(NULL, sizeof(ZBX_DC_CACHE));
memset(cache, 0, sizeof(ZBX_DC_CACHE));
- ids = (ZBX_DC_IDS *)__hc_index_mem_malloc_func(NULL, sizeof(ZBX_DC_IDS));
+ ids = (ZBX_DC_IDS *)__hc_index_shmem_malloc_func(NULL, sizeof(ZBX_DC_IDS));
memset(ids, 0, sizeof(ZBX_DC_IDS));
zbx_hashset_create_ext(&cache->history_items, ZBX_HC_ITEMS_INIT_SIZE,
ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC, NULL,
- __hc_index_mem_malloc_func, __hc_index_mem_realloc_func, __hc_index_mem_free_func);
+ __hc_index_shmem_malloc_func, __hc_index_shmem_realloc_func, __hc_index_shmem_free_func);
zbx_binary_heap_create_ext(&cache->history_queue, hc_queue_elem_compare_func, ZBX_BINARY_HEAP_OPTION_EMPTY,
- __hc_index_mem_malloc_func, __hc_index_mem_realloc_func, __hc_index_mem_free_func);
+ __hc_index_shmem_malloc_func, __hc_index_shmem_realloc_func, __hc_index_shmem_free_func);
if (0 != (program_type & ZBX_PROGRAM_TYPE_SERVER))
{
zbx_hashset_create_ext(&(cache->proxyqueue.index), ZBX_HC_SYNC_MAX,
ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC, NULL,
- __hc_index_mem_malloc_func, __hc_index_mem_realloc_func, __hc_index_mem_free_func);
+ __hc_index_shmem_malloc_func, __hc_index_shmem_realloc_func, __hc_index_shmem_free_func);
- zbx_list_create_ext(&(cache->proxyqueue.list), __hc_index_mem_malloc_func, __hc_index_mem_free_func);
+ zbx_list_create_ext(&(cache->proxyqueue.list), __hc_index_shmem_malloc_func,
+ __hc_index_shmem_free_func);
cache->proxyqueue.state = ZBX_HC_PROXYQUEUE_STATE_NORMAL;
@@ -4676,9 +4680,9 @@ void free_database_cache(int sync)
cache = NULL;
- zbx_mem_destroy(hc_mem);
+ zbx_shmem_destroy(hc_mem);
hc_mem = NULL;
- zbx_mem_destroy(hc_index_mem);
+ zbx_shmem_destroy(hc_index_mem);
hc_index_mem = NULL;
zbx_mutex_destroy(&cache_lock);
@@ -4686,7 +4690,7 @@ void free_database_cache(int sync)
if (0 != (program_type & ZBX_PROGRAM_TYPE_SERVER))
{
- zbx_mem_destroy(trend_mem);
+ zbx_shmem_destroy(trend_mem);
trend_mem = NULL;
zbx_mutex_destroy(&trends_lock);
}
@@ -4815,15 +4819,15 @@ void zbx_hc_get_diag_stats(zbx_uint64_t *items_num, zbx_uint64_t *values_num)
* Purpose: get shared memory allocator statistics *
* *
******************************************************************************/
-void zbx_hc_get_mem_stats(zbx_mem_stats_t *data, zbx_mem_stats_t *index)
+void zbx_hc_get_mem_stats(zbx_shmem_stats_t *data, zbx_shmem_stats_t *index)
{
LOCK_CACHE;
if (NULL != data)
- zbx_mem_get_stats(hc_mem, data);
+ zbx_shmem_get_stats(hc_mem, data);
if (NULL != index)
- zbx_mem_get_stats(hc_index_mem, index);
+ zbx_shmem_get_stats(hc_index_mem, index);
UNLOCK_CACHE;
}
diff --git a/src/libs/zbxdbcache/dbconfig.c b/src/libs/zbxdbcache/dbconfig.c
index e60b34cb83a..1bc60ade728 100644
--- a/src/libs/zbxdbcache/dbconfig.c
+++ b/src/libs/zbxdbcache/dbconfig.c
@@ -81,14 +81,14 @@ int sync_in_progress = 0;
******************************************************************************/
typedef int (*zbx_value_validator_func_t)(const char *macro, const char *value, char **error);
-ZBX_DC_CONFIG *config = NULL;
-zbx_rwlock_t config_lock = ZBX_RWLOCK_NULL;
-static zbx_mem_info_t *config_mem;
+ZBX_DC_CONFIG *config = NULL;
+zbx_rwlock_t config_lock = ZBX_RWLOCK_NULL;
+static zbx_shmem_info_t *config_mem;
extern unsigned char program_type;
extern int CONFIG_TIMER_FORKS;
-ZBX_MEM_FUNC_IMPL(__config, config_mem)
+ZBX_SHMEM_FUNC_IMPL(__config, config_mem)
static void dc_maintenance_precache_nested_groups(void);
static void dc_item_reset_triggers(ZBX_DC_ITEM *item, ZBX_DC_TRIGGER *trigger_exclude);
@@ -109,7 +109,7 @@ static char *dc_strdup(const char *source)
size_t len;
len = strlen(source) + 1;
- dst = (char *)__config_mem_malloc_func(NULL, len);
+ dst = (char *)__config_shmem_malloc_func(NULL, len);
memcpy(dst, source, len);
return dst;
}
@@ -648,10 +648,11 @@ static ZBX_DC_GMACRO_M *config_gmacro_add_index(zbx_hashset_t *gmacro_index, ZBX
if (NULL == (gmacro_m = (ZBX_DC_GMACRO_M *)zbx_hashset_search(gmacro_index, &gmacro_m_local)))
{
gmacro_m_local.macro = zbx_strpool_acquire(gmacro->macro);
- zbx_vector_ptr_create_ext(&gmacro_m_local.gmacros, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&gmacro_m_local.gmacros, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
- gmacro_m = (ZBX_DC_GMACRO_M *)zbx_hashset_insert(gmacro_index, &gmacro_m_local, sizeof(ZBX_DC_GMACRO_M));
+ gmacro_m = (ZBX_DC_GMACRO_M *)zbx_hashset_insert(gmacro_index, &gmacro_m_local,
+ sizeof(ZBX_DC_GMACRO_M));
}
zbx_vector_ptr_append(&gmacro_m->gmacros, gmacro);
@@ -723,10 +724,11 @@ static ZBX_DC_HMACRO_HM *config_hmacro_add_index(zbx_hashset_t *hmacro_index, ZB
if (NULL == (hmacro_hm = (ZBX_DC_HMACRO_HM *)zbx_hashset_search(hmacro_index, &hmacro_hm_local)))
{
hmacro_hm_local.macro = zbx_strpool_acquire(hmacro->macro);
- zbx_vector_ptr_create_ext(&hmacro_hm_local.hmacros, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&hmacro_hm_local.hmacros, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
- hmacro_hm = (ZBX_DC_HMACRO_HM *)zbx_hashset_insert(hmacro_index, &hmacro_hm_local, sizeof(ZBX_DC_HMACRO_HM));
+ hmacro_hm = (ZBX_DC_HMACRO_HM *)zbx_hashset_insert(hmacro_index, &hmacro_hm_local,
+ sizeof(ZBX_DC_HMACRO_HM));
}
zbx_vector_ptr_append(&hmacro_hm->hmacros, hmacro);
@@ -809,12 +811,12 @@ static zbx_dc_kv_t *config_kvs_path_add(const char *path, const char *key)
if (FAIL == (i = zbx_vector_ptr_search(&config->kvs_paths, &kvs_path_local, dc_compare_kvs_path)))
{
- kvs_path = (zbx_dc_kvs_path_t *)__config_mem_malloc_func(NULL, sizeof(zbx_dc_kvs_path_t));
+ kvs_path = (zbx_dc_kvs_path_t *)__config_shmem_malloc_func(NULL, sizeof(zbx_dc_kvs_path_t));
DCstrpool_replace(0, &kvs_path->path, path);
zbx_vector_ptr_append(&config->kvs_paths, kvs_path);
zbx_hashset_create_ext(&kvs_path->kvs, 0, dc_kv_hash, dc_kv_compare, NULL,
- __config_mem_malloc_func, __config_mem_realloc_func, __config_mem_free_func);
+ __config_shmem_malloc_func, __config_shmem_realloc_func, __config_shmem_free_func);
kv = NULL;
}
else
@@ -868,7 +870,7 @@ static void config_kvs_path_remove(const char *value, zbx_dc_kv_t *kv)
if (0 == kvs_path->kvs.num_data)
{
zbx_strpool_release(kvs_path->path);
- __config_mem_free_func(kvs_path);
+ __config_shmem_free_func(kvs_path);
zbx_vector_ptr_remove_noorder(&config->kvs_paths, i);
}
clean:
@@ -929,7 +931,7 @@ static int DCsync_config(zbx_dbsync_t *sync, int *flags)
if (NULL == config->config)
{
found = 0;
- config->config = (ZBX_DC_CONFIG_TABLE *)__config_mem_malloc_func(NULL, sizeof(ZBX_DC_CONFIG_TABLE));
+ config->config = (ZBX_DC_CONFIG_TABLE *)__config_shmem_malloc_func(NULL, sizeof(ZBX_DC_CONFIG_TABLE));
}
if (SUCCEED != (ret = zbx_dbsync_next(sync, &rowid, &db_row, &tag)))
@@ -1423,8 +1425,8 @@ done:
host->data_expected_from = now;
host->update_items = 0;
- zbx_vector_ptr_create_ext(&host->interfaces_v, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&host->interfaces_v, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
else
{
@@ -1735,9 +1737,9 @@ static void DCsync_htmpls(zbx_dbsync_t *sync)
if (0 == found)
{
zbx_vector_uint64_create_ext(&htmpl->templateids,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
zbx_vector_uint64_reserve(&htmpl->templateids, 1);
}
@@ -2138,7 +2140,8 @@ void DCsync_kvs_paths(const struct zbx_json_parse *jp_kvs_paths)
}
else if (FAIL == zbx_vault_kvs_get(dc_kvs_path->path, &kvs, &error))
{
- zabbix_log(LOG_LEVEL_WARNING, "cannot get secrets for path \"%s\": %s", dc_kvs_path->path, error);
+ zabbix_log(LOG_LEVEL_WARNING, "cannot get secrets for path \"%s\": %s", dc_kvs_path->path,
+ error);
zbx_free(error);
continue;
}
@@ -2471,9 +2474,9 @@ static void DCsync_interfaces(zbx_dbsync_t *sync)
interface_snmpaddr = (ZBX_DC_INTERFACE_ADDR *)zbx_hashset_insert(&config->interface_snmpaddrs,
&interface_snmpaddr_local, sizeof(ZBX_DC_INTERFACE_ADDR));
zbx_vector_uint64_create_ext(&interface_snmpaddr->interfaceids,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
}
zbx_vector_uint64_append(&interface_snmpaddr->interfaceids, interfaceid);
@@ -2695,7 +2698,7 @@ static unsigned char *config_decode_serialized_expression(const char *src)
return NULL;
src_len = strlen(src) * 3 / 4;
- dst = __config_mem_malloc_func(NULL, src_len);
+ dst = __config_shmem_malloc_func(NULL, src_len);
str_base64_decode(src, (char *)dst, src_len, &data_len);
return dst;
@@ -2839,8 +2842,8 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
item->queue_priority = ZBX_QUEUE_PRIORITY_NORMAL;
item->schedulable = 1;
- zbx_vector_ptr_create_ext(&item->tags, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&item->tags, __config_shmem_malloc_func, __config_shmem_realloc_func,
+ __config_shmem_free_func);
}
else
{
@@ -3123,9 +3126,9 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
if (0 == found)
{
zbx_vector_uint64_create_ext(&interface_snmpitem->itemids,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
}
zbx_vector_uint64_append(&interface_snmpitem->itemids, itemid);
@@ -3141,7 +3144,7 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
DCstrpool_replace(found, &calcitem->params, row[11]);
if (1 == found && NULL != calcitem->formula_bin)
- __config_mem_free_func((void *)calcitem->formula_bin);
+ __config_shmem_free_func((void *)calcitem->formula_bin);
calcitem->formula_bin = config_decode_serialized_expression(row[49]);
}
@@ -3150,7 +3153,7 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
/* remove calculated item parameters */
if (NULL != calcitem->formula_bin)
- __config_mem_free_func((void *)calcitem->formula_bin);
+ __config_shmem_free_func((void *)calcitem->formula_bin);
zbx_strpool_release(calcitem->params);
zbx_hashset_remove_direct(&config->calcitems, calcitem);
}
@@ -3217,8 +3220,8 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
if (0 == found)
{
- zbx_vector_ptr_create_ext(&scriptitem->params, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&scriptitem->params, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
}
else if (NULL != (scriptitem = (ZBX_DC_SCRIPTITEM *)zbx_hashset_search(&config->scriptitems, &itemid)))
@@ -3292,8 +3295,8 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
master_local.itemid = depitem->master_itemid;
master = (ZBX_DC_MASTERITEM *)zbx_hashset_insert(&config->masteritems, &master_local, sizeof(master_local));
- zbx_vector_uint64_pair_create_ext(&master->dep_itemids, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_uint64_pair_create_ext(&master->dep_itemids, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
zbx_vector_uint64_pair_append(&master->dep_itemids, pair);
@@ -3446,7 +3449,7 @@ static void DCsync_items(zbx_dbsync_t *sync, int flags)
zbx_strpool_release(calcitem->params);
if (NULL != calcitem->formula_bin)
- __config_mem_free_func((void *)calcitem->formula_bin);
+ __config_shmem_free_func((void *)calcitem->formula_bin);
zbx_hashset_remove_direct(&config->calcitems, calcitem);
}
@@ -3689,17 +3692,17 @@ static void DCsync_triggers(zbx_dbsync_t *sync)
trigger->locked = 0;
trigger->timer_revision = 0;
- zbx_vector_ptr_create_ext(&trigger->tags, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&trigger->tags, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
trigger->topoindex = 1;
trigger->itemids = NULL;
}
else
{
if (NULL != trigger->expression_bin)
- __config_mem_free_func((void *)trigger->expression_bin);
+ __config_shmem_free_func((void *)trigger->expression_bin);
if (NULL != trigger->recovery_expression_bin)
- __config_mem_free_func((void *)trigger->recovery_expression_bin);
+ __config_shmem_free_func((void *)trigger->recovery_expression_bin);
}
trigger->expression_bin = config_decode_serialized_expression(row[16]);
@@ -3745,12 +3748,12 @@ static void DCsync_triggers(zbx_dbsync_t *sync)
zbx_vector_ptr_destroy(&trigger->tags);
if (NULL != trigger->expression_bin)
- __config_mem_free_func((void *)trigger->expression_bin);
+ __config_shmem_free_func((void *)trigger->expression_bin);
if (NULL != trigger->recovery_expression_bin)
- __config_mem_free_func((void *)trigger->recovery_expression_bin);
+ __config_shmem_free_func((void *)trigger->recovery_expression_bin);
if (NULL != trigger->itemids)
- __config_mem_free_func((void *)trigger->itemids);
+ __config_shmem_free_func((void *)trigger->itemids);
}
zbx_hashset_remove_direct(&config->triggers, trigger);
@@ -3788,8 +3791,8 @@ static void dc_trigger_deplist_init(ZBX_DC_TRIGGER_DEPLIST *trigdep, ZBX_DC_TRIG
{
trigdep->refcount = 1;
trigdep->trigger = trigger;
- zbx_vector_ptr_create_ext(&trigdep->dependencies, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&trigdep->dependencies, __config_shmem_malloc_func, __config_shmem_realloc_func,
+ __config_shmem_free_func);
}
/******************************************************************************
@@ -3801,8 +3804,8 @@ static void dc_trigger_deplist_init(ZBX_DC_TRIGGER_DEPLIST *trigdep, ZBX_DC_TRIG
static void dc_trigger_deplist_reset(ZBX_DC_TRIGGER_DEPLIST *trigdep)
{
zbx_vector_ptr_destroy(&trigdep->dependencies);
- zbx_vector_ptr_create_ext(&trigdep->dependencies, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&trigdep->dependencies, __config_shmem_malloc_func, __config_shmem_realloc_func,
+ __config_shmem_free_func);
}
static void DCsync_trigdeps(zbx_dbsync_t *sync)
@@ -4018,7 +4021,7 @@ static zbx_trigger_timer_t *dc_trigger_function_timer_create(ZBX_DC_FUNCTION *fu
type = ZBX_TRIGGER_TIMER_FUNCTION_TIME;
}
- timer = (zbx_trigger_timer_t *)__config_mem_malloc_func(NULL, sizeof(zbx_trigger_timer_t));
+ timer = (zbx_trigger_timer_t *)__config_shmem_malloc_func(NULL, sizeof(zbx_trigger_timer_t));
timer->objectid = function->functionid;
timer->triggerid = function->triggerid;
@@ -4048,7 +4051,7 @@ static zbx_trigger_timer_t *dc_trigger_timer_create(ZBX_DC_TRIGGER *trigger)
{
zbx_trigger_timer_t *timer;
- timer = (zbx_trigger_timer_t *)__config_mem_malloc_func(NULL, sizeof(zbx_trigger_timer_t));
+ timer = (zbx_trigger_timer_t *)__config_shmem_malloc_func(NULL, sizeof(zbx_trigger_timer_t));
timer->type = ZBX_TRIGGER_TIMER_TRIGGER;
timer->objectid = trigger->triggerid;
timer->triggerid = trigger->triggerid;
@@ -4072,7 +4075,7 @@ static void dc_trigger_timer_free(zbx_trigger_timer_t *timer)
if (NULL != timer->parameter)
zbx_strpool_release(timer->parameter);
- __config_mem_free_func(timer);
+ __config_shmem_free_func(timer);
}
/******************************************************************************
@@ -4342,9 +4345,9 @@ static void DCsync_expressions(zbx_dbsync_t *sync)
{
DCstrpool_replace(0, &regexp_local.name, row[0]);
zbx_vector_uint64_create_ext(&regexp_local.expressionids,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
regexp = (ZBX_DC_REGEXP *)zbx_hashset_insert(&config->regexps, &regexp_local, sizeof(ZBX_DC_REGEXP));
}
@@ -4432,8 +4435,8 @@ static void DCsync_actions(zbx_dbsync_t *sync)
if (EVENT_SOURCE_INTERNAL == action->eventsource)
config->internal_actions++;
- zbx_vector_ptr_create_ext(&action->conditions, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&action->conditions, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
zbx_vector_ptr_reserve(&action->conditions, 1);
@@ -4649,11 +4652,11 @@ static void DCsync_correlations(zbx_dbsync_t *sync)
if (0 == found)
{
- zbx_vector_ptr_create_ext(&correlation->conditions, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&correlation->conditions, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
- zbx_vector_ptr_create_ext(&correlation->operations, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&correlation->operations, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
DCstrpool_replace(found, &correlation->name, row[1]);
@@ -5031,8 +5034,8 @@ static void DCsync_hostgroups(zbx_dbsync_t *sync)
zbx_vector_ptr_append(&config->hostgroups_name, group);
zbx_hashset_create_ext(&group->hostids, 0, ZBX_DEFAULT_UINT64_HASH_FUNC,
- ZBX_DEFAULT_UINT64_COMPARE_FUNC, NULL, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ ZBX_DEFAULT_UINT64_COMPARE_FUNC, NULL, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
DCstrpool_replace(found, &group->name, row[1]);
@@ -5130,8 +5133,8 @@ static void DCsync_trigger_tags(zbx_dbsync_t *sync)
if (0 == trigger->tags.values_num)
{
zbx_vector_ptr_destroy(&trigger->tags);
- zbx_vector_ptr_create_ext(&trigger->tags, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&trigger->tags, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
}
}
@@ -5214,8 +5217,8 @@ static void DCsync_item_tags(zbx_dbsync_t *sync)
if (0 == item->tags.values_num)
{
zbx_vector_ptr_destroy(&item->tags);
- zbx_vector_ptr_create_ext(&item->tags, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&item->tags, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
}
}
@@ -5281,8 +5284,8 @@ static void DCsync_host_tags(zbx_dbsync_t *sync)
if (0 == found)
{
- zbx_vector_ptr_create_ext(&host_tag_index_entry->tags, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&host_tag_index_entry->tags, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
}
zbx_vector_ptr_append(&host_tag_index_entry->tags, host_tag);
@@ -5402,25 +5405,28 @@ static void DCsync_item_preproc(zbx_dbsync_t *sync, int timestamp)
if (NULL == preprocitem || itemid != preprocitem->itemid)
{
- if (NULL == (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems, &itemid)))
+ if (NULL == (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems,
+ &itemid)))
{
ZBX_DC_PREPROCITEM preprocitem_local;
preprocitem_local.itemid = itemid;
+ preprocitem_local.update_time = timestamp;
- preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_insert(&config->preprocitems, &preprocitem_local,
- sizeof(preprocitem_local));
+ zbx_vector_ptr_create_ext(&preprocitem_local.preproc_ops, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
- zbx_vector_ptr_create_ext(&preprocitem->preproc_ops, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_insert(&config->preprocitems,
+ &preprocitem_local, sizeof(preprocitem_local));
}
-
- preprocitem->update_time = timestamp;
+ else
+ preprocitem->update_time = timestamp;
}
ZBX_STR2UINT64(item_preprocid, row[0]);
- op = (zbx_dc_preproc_op_t *)DCfind_id(&config->preprocops, item_preprocid, sizeof(zbx_dc_preproc_op_t), &found);
+ op = (zbx_dc_preproc_op_t *)DCfind_id(&config->preprocops, item_preprocid, sizeof(zbx_dc_preproc_op_t),
+ &found);
ZBX_STR2UCHAR(op->type, row[2]);
DCstrpool_replace(found, &op->params, row[3]);
@@ -5444,7 +5450,8 @@ static void DCsync_item_preproc(zbx_dbsync_t *sync, int timestamp)
if (NULL == (op = (zbx_dc_preproc_op_t *)zbx_hashset_search(&config->preprocops, &rowid)))
continue;
- if (NULL != (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems, &op->itemid)))
+ if (NULL != (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems,
+ &op->itemid)))
{
if (FAIL != (index = zbx_vector_ptr_search(&preprocitem->preproc_ops, op,
ZBX_DEFAULT_PTR_COMPARE_FUNC)))
@@ -5719,12 +5726,12 @@ static void dc_trigger_add_itemids(ZBX_DC_TRIGGER *trigger, const zbx_vector_uin
for (itemid = trigger->itemids; 0 != *itemid; itemid++)
itemids_num++;
- trigger->itemids = (zbx_uint64_t *)__config_mem_realloc_func(trigger->itemids,
+ trigger->itemids = (zbx_uint64_t *)__config_shmem_realloc_func(trigger->itemids,
sizeof(zbx_uint64_t) * (size_t)(itemids->values_num + itemids_num + 1));
}
else
{
- trigger->itemids = (zbx_uint64_t *)__config_mem_malloc_func(trigger->itemids,
+ trigger->itemids = (zbx_uint64_t *)__config_shmem_malloc_func(trigger->itemids,
sizeof(zbx_uint64_t) * (size_t)(itemids->values_num + 1));
trigger->itemids[0] = 0;
}
@@ -6680,7 +6687,7 @@ void DCsync_configuration(unsigned char mode)
zabbix_log(LOG_LEVEL_DEBUG, "%s() strings : %d (%d slots)", __func__,
config->strpool.num_data, config->strpool.num_slots);
- zbx_mem_dump_stats(LOG_LEVEL_DEBUG, config_mem);
+ zbx_shmem_dump_stats(LOG_LEVEL_DEBUG, config_mem);
}
out:
if (0 == sync_in_progress)
@@ -7067,13 +7074,13 @@ int init_configuration_cache(char **error)
if (SUCCEED != (ret = zbx_rwlock_create(&config_lock, ZBX_RWLOCK_CONFIG, error)))
goto out;
- if (SUCCEED != (ret = zbx_mem_create(&config_mem, CONFIG_CONF_CACHE_SIZE, "configuration cache",
+ if (SUCCEED != (ret = zbx_shmem_create(&config_mem, CONFIG_CONF_CACHE_SIZE, "configuration cache",
"CacheSize", 0, error)))
{
goto out;
}
- config = (ZBX_DC_CONFIG *)__config_mem_malloc_func(NULL, sizeof(ZBX_DC_CONFIG) +
+ config = (ZBX_DC_CONFIG *)__config_shmem_malloc_func(NULL, sizeof(ZBX_DC_CONFIG) +
CONFIG_TIMER_FORKS * sizeof(zbx_vector_ptr_t));
#define CREATE_HASHSET(hashset, hashset_size) \
@@ -7083,7 +7090,7 @@ int init_configuration_cache(char **error)
#define CREATE_HASHSET_EXT(hashset, hashset_size, hash_func, compare_func) \
\
zbx_hashset_create_ext(&hashset, hashset_size, hash_func, compare_func, NULL, \
- __config_mem_malloc_func, __config_mem_realloc_func, __config_mem_free_func)
+ __config_shmem_malloc_func, __config_shmem_realloc_func, __config_shmem_free_func)
CREATE_HASHSET(config->items, 100);
CREATE_HASHSET(config->numitems, 0);
@@ -7131,10 +7138,10 @@ int init_configuration_cache(char **error)
CREATE_HASHSET(config->corr_conditions, 0);
CREATE_HASHSET(config->corr_operations, 0);
CREATE_HASHSET(config->hostgroups, 0);
- zbx_vector_ptr_create_ext(&config->hostgroups_name, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
- zbx_vector_ptr_create_ext(&config->kvs_paths, __config_mem_malloc_func, __config_mem_realloc_func,
- __config_mem_free_func);
+ zbx_vector_ptr_create_ext(&config->hostgroups_name, __config_shmem_malloc_func, __config_shmem_realloc_func,
+ __config_shmem_free_func);
+ zbx_vector_ptr_create_ext(&config->kvs_paths, __config_shmem_malloc_func, __config_shmem_realloc_func,
+ __config_shmem_free_func);
CREATE_HASHSET(config->preprocops, 0);
@@ -7165,25 +7172,25 @@ int init_configuration_cache(char **error)
zbx_binary_heap_create_ext(&config->queues[i],
__config_java_elem_compare,
ZBX_BINARY_HEAP_OPTION_DIRECT,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
break;
case ZBX_POLLER_TYPE_PINGER:
zbx_binary_heap_create_ext(&config->queues[i],
__config_pinger_elem_compare,
ZBX_BINARY_HEAP_OPTION_DIRECT,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
break;
default:
zbx_binary_heap_create_ext(&config->queues[i],
__config_heap_elem_compare,
ZBX_BINARY_HEAP_OPTION_DIRECT,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
break;
}
}
@@ -7191,22 +7198,22 @@ int init_configuration_cache(char **error)
zbx_binary_heap_create_ext(&config->pqueue,
__config_proxy_compare,
ZBX_BINARY_HEAP_OPTION_DIRECT,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
zbx_binary_heap_create_ext(&config->trigger_queue,
__config_timer_compare,
ZBX_BINARY_HEAP_OPTION_EMPTY,
- __config_mem_malloc_func,
- __config_mem_realloc_func,
- __config_mem_free_func);
+ __config_shmem_malloc_func,
+ __config_shmem_realloc_func,
+ __config_shmem_free_func);
CREATE_HASHSET_EXT(config->data_sessions, 0, __config_data_session_hash, __config_data_session_compare);
config->config = NULL;
- config->status = (ZBX_DC_STATUS *)__config_mem_malloc_func(NULL, sizeof(ZBX_DC_STATUS));
+ config->status = (ZBX_DC_STATUS *)__config_shmem_malloc_func(NULL, sizeof(ZBX_DC_STATUS));
config->status->last_update = 0;
config->availability_diff_ts = 0;
@@ -7220,8 +7227,8 @@ int init_configuration_cache(char **error)
if (0 != CONFIG_TIMER_FORKS)
{
config->maintenance_update = ZBX_MAINTENANCE_UPDATE_FALSE;
- config->maintenance_update_flags = (zbx_uint64_t *)__config_mem_malloc_func(NULL, sizeof(zbx_uint64_t) *
- ZBX_MAINTENANCE_UPDATE_FLAGS_NUM());
+ config->maintenance_update_flags = (zbx_uint64_t *)__config_shmem_malloc_func(NULL,
+ sizeof(zbx_uint64_t) * ZBX_MAINTENANCE_UPDATE_FLAGS_NUM());
memset(config->maintenance_update_flags, 0, sizeof(zbx_uint64_t) * ZBX_MAINTENANCE_UPDATE_FLAGS_NUM());
}
@@ -7262,7 +7269,7 @@ void free_configuration_cache(void)
UNLOCK_CACHE;
- zbx_mem_destroy(config_mem);
+ zbx_shmem_destroy(config_mem);
config_mem = NULL;
zbx_rwlock_destroy(&config_lock);
@@ -12708,8 +12715,8 @@ void dc_hostgroup_cache_nested_groupids(zbx_dc_hostgroup_t *parent_group)
{
int index, len;
- zbx_vector_uint64_create_ext(&parent_group->nested_groupids, __config_mem_malloc_func,
- __config_mem_realloc_func, __config_mem_free_func);
+ zbx_vector_uint64_create_ext(&parent_group->nested_groupids, __config_shmem_malloc_func,
+ __config_shmem_realloc_func, __config_shmem_free_func);
index = zbx_vector_ptr_bsearch(&config->hostgroups_name, parent_group, dc_compare_hgroups);
len = strlen(parent_group->name);
@@ -13546,16 +13553,18 @@ zbx_data_session_t *zbx_dc_get_or_create_data_session(zbx_uint64_t hostid, const
if (NULL == session)
{
+ session_local.last_valueid = 0;
+ session_local.lastaccess = now;
+ session_local.token = dc_strdup(token);
+
WRLOCK_CACHE;
+
session = (zbx_data_session_t *)zbx_hashset_insert(&config->data_sessions, &session_local,
sizeof(session_local));
- session->token = dc_strdup(token);
UNLOCK_CACHE;
-
- session->last_valueid = 0;
}
-
- session->lastaccess = now;
+ else
+ session->lastaccess = now;
return session;
}
@@ -13580,7 +13589,7 @@ void zbx_dc_cleanup_data_sessions(void)
{
if (session->lastaccess + SEC_PER_DAY <= now)
{
- __config_mem_free_func((char *)session->token);
+ __config_shmem_free_func((char *)session->token);
zbx_hashset_iter_remove(&iter);
}
}
diff --git a/src/libs/zbxdbcache/valuecache.c b/src/libs/zbxdbcache/valuecache.c
index e67eb699b51..9da241c5e71 100644
--- a/src/libs/zbxdbcache/valuecache.c
+++ b/src/libs/zbxdbcache/valuecache.c
@@ -58,7 +58,7 @@
#define ZBX_VC_LOW_MEMORY_ITEM_PRINT_LIMIT 25
-static zbx_mem_info_t *vc_mem = NULL;
+static zbx_shmem_info_t *vc_mem = NULL;
zbx_rwlock_t vc_lock = ZBX_RWLOCK_NULL;
@@ -72,7 +72,7 @@ static int vc_state = ZBX_VC_DISABLED;
/* the value cache size */
extern zbx_uint64_t CONFIG_VALUE_CACHE_SIZE;
-ZBX_MEM_FUNC_IMPL(__vc, vc_mem)
+ZBX_SHMEM_FUNC_IMPL(__vc, vc_mem)
#define VC_STRPOOL_INIT_SIZE (1000)
#define VC_ITEMS_INIT_SIZE (1000)
@@ -751,7 +751,7 @@ static void vc_warn_low_memory(void)
{
vc_cache->last_warning_time = now;
vc_dump_items_statistics();
- zbx_mem_dump_stats(LOG_LEVEL_WARNING, vc_mem);
+ zbx_shmem_dump_stats(LOG_LEVEL_WARNING, vc_mem);
zabbix_log(LOG_LEVEL_WARNING, "value cache is fully used: please increase ValueCacheSize"
" configuration parameter");
@@ -953,13 +953,13 @@ static void *vc_item_malloc(zbx_vc_item_t *item, size_t size)
{
char *ptr;
- if (NULL == (ptr = (char *)__vc_mem_malloc_func(NULL, size)))
+ if (NULL == (ptr = (char *)__vc_shmem_malloc_func(NULL, size)))
{
/* If failed to allocate required memory, try to free space in */
/* cache and allocate again. If there still is not enough space - */
/* return NULL as failure. */
vc_release_space(item, size);
- ptr = (char *)__vc_mem_malloc_func(NULL, size);
+ ptr = (char *)__vc_shmem_malloc_func(NULL, size);
}
return ptr;
@@ -1091,7 +1091,7 @@ static zbx_log_value_t *vc_item_logdup(zbx_vc_item_t *item, const zbx_log_value_
fail:
vc_item_strfree(plog->source);
- __vc_mem_free_func(plog);
+ __vc_shmem_free_func(plog);
return NULL;
}
@@ -1117,7 +1117,7 @@ static size_t vc_item_logfree(zbx_log_value_t *log)
freed += vc_item_strfree(log->source);
freed += vc_item_strfree(log->value);
- __vc_mem_free_func(log);
+ __vc_shmem_free_func(log);
freed += sizeof(zbx_log_value_t);
}
@@ -1589,7 +1589,7 @@ static size_t vch_item_free_chunk(zbx_vc_item_t *item, zbx_vc_chunk_t *chunk)
freed = sizeof(zbx_vc_chunk_t) + (chunk->slots_num - 1) * sizeof(zbx_history_record_t);
freed += vc_item_free_values(item, chunk->slots, chunk->first_value, chunk->last_value);
- __vc_mem_free_func(chunk);
+ __vc_shmem_free_func(chunk);
return freed;
}
@@ -2350,14 +2350,17 @@ int zbx_vc_init(char **error)
if (SUCCEED != (ret = zbx_rwlock_create(&vc_lock, ZBX_RWLOCK_VALUECACHE, error)))
goto out;
- size_reserved = zbx_mem_required_size(1, "value cache size", "ValueCacheSize");
+ size_reserved = zbx_shmem_required_size(1, "value cache size", "ValueCacheSize");
- if (SUCCEED != zbx_mem_create(&vc_mem, CONFIG_VALUE_CACHE_SIZE, "value cache size", "ValueCacheSize", 1, error))
+ if (SUCCEED != zbx_shmem_create(&vc_mem, CONFIG_VALUE_CACHE_SIZE, "value cache size", "ValueCacheSize", 1,
+ error))
+ {
goto out;
+ }
CONFIG_VALUE_CACHE_SIZE -= size_reserved;
- vc_cache = (zbx_vc_cache_t *)__vc_mem_malloc_func(vc_cache, sizeof(zbx_vc_cache_t));
+ vc_cache = (zbx_vc_cache_t *)__vc_shmem_malloc_func(vc_cache, sizeof(zbx_vc_cache_t));
if (NULL == vc_cache)
{
@@ -2368,7 +2371,7 @@ int zbx_vc_init(char **error)
zbx_hashset_create_ext(&vc_cache->items, VC_ITEMS_INIT_SIZE,
ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC, NULL,
- __vc_mem_malloc_func, __vc_mem_realloc_func, __vc_mem_free_func);
+ __vc_shmem_malloc_func, __vc_shmem_realloc_func, __vc_shmem_free_func);
if (NULL == vc_cache->items.slots)
{
@@ -2378,7 +2381,7 @@ int zbx_vc_init(char **error)
zbx_hashset_create_ext(&vc_cache->strpool, VC_STRPOOL_INIT_SIZE,
vc_strpool_hash_func, vc_strpool_compare_func, NULL,
- __vc_mem_malloc_func, __vc_mem_realloc_func, __vc_mem_free_func);
+ __vc_shmem_malloc_func, __vc_shmem_realloc_func, __vc_shmem_free_func);
if (NULL == vc_cache->strpool.slots)
{
@@ -2419,10 +2422,10 @@ void zbx_vc_destroy(void)
zbx_hashset_destroy(&vc_cache->items);
zbx_hashset_destroy(&vc_cache->strpool);
- __vc_mem_free_func(vc_cache);
+ __vc_shmem_free_func(vc_cache);
vc_cache = NULL;
- zbx_mem_destroy(vc_mem);
+ zbx_shmem_destroy(vc_mem);
vc_mem = NULL;
zbx_rwlock_destroy(&vc_lock);
}
@@ -2735,16 +2738,16 @@ void zbx_vc_get_diag_stats(zbx_uint64_t *items_num, zbx_uint64_t *values_num, in
* Purpose: get value cache shared memory statistics *
* *
******************************************************************************/
-void zbx_vc_get_mem_stats(zbx_mem_stats_t *mem)
+void zbx_vc_get_mem_stats(zbx_shmem_stats_t *mem)
{
if (ZBX_VC_DISABLED == vc_state)
{
- memset(mem, 0, sizeof(zbx_mem_stats_t));
+ memset(mem, 0, sizeof(zbx_shmem_stats_t));
return;
}
RDLOCK_CACHE;
- zbx_mem_get_stats(vc_mem, mem);
+ zbx_shmem_get_stats(vc_mem, mem);
UNLOCK_CACHE;
}
diff --git a/src/libs/zbxdbcache/valuecache.h b/src/libs/zbxdbcache/valuecache.h
index 31f0975569b..3b280e5a4df 100644
--- a/src/libs/zbxdbcache/valuecache.h
+++ b/src/libs/zbxdbcache/valuecache.h
@@ -23,7 +23,7 @@
#include "zbxtypes.h"
#include "zbxalgo.h"
#include "zbxhistory.h"
-#include "memalloc.h"
+#include "zbxshmem.h"
/*
* The Value Cache provides read caching of item historical data residing in history
@@ -114,7 +114,7 @@ int zbx_vc_get_statistics(zbx_vc_stats_t *stats);
void zbx_vc_housekeeping_value_cache(void);
void zbx_vc_get_diag_stats(zbx_uint64_t *items_num, zbx_uint64_t *values_num, int *mode);
-void zbx_vc_get_mem_stats(zbx_mem_stats_t *mem);
+void zbx_vc_get_mem_stats(zbx_shmem_stats_t *mem);
void zbx_vc_get_item_stats(zbx_vector_ptr_t *stats);
void zbx_vc_flush_stats(void);
diff --git a/src/libs/zbxdiag/diag.c b/src/libs/zbxdiag/diag.c
index 6e38031c77a..786ef67fef3 100644
--- a/src/libs/zbxdiag/diag.c
+++ b/src/libs/zbxdiag/diag.c
@@ -138,7 +138,7 @@ out:
* stats - [IN] the memory statistics *
* *
******************************************************************************/
-void diag_add_mem_stats(struct zbx_json *json, const char *name, const zbx_mem_stats_t *stats)
+void diag_add_mem_stats(struct zbx_json *json, const char *name, const zbx_shmem_stats_t *stats)
{
int i;
@@ -160,14 +160,14 @@ void diag_add_mem_stats(struct zbx_json *json, const char *name, const zbx_mem_s
zbx_json_addarray(json, "buckets");
- for (i = 0; i < MEM_BUCKET_COUNT; i++)
+ for (i = 0; i < ZBX_SHMEM_BUCKET_COUNT; i++)
{
if (0 != stats->chunks_num[i])
{
char buf[MAX_ID_LEN + 2];
- zbx_snprintf(buf, sizeof(buf), "%d%s", MEM_MIN_BUCKET_SIZE + 8 * i,
- (MEM_BUCKET_COUNT - 1 == i ? "+" : ""));
+ zbx_snprintf(buf, sizeof(buf), "%d%s", ZBX_SHMEM_MIN_BUCKET_SIZE + 8 * i,
+ (ZBX_SHMEM_BUCKET_COUNT - 1 == i ? "+" : ""));
zbx_json_addobject(json, NULL);
zbx_json_adduint64(json, buf, stats->chunks_num[i]);
zbx_json_close(json);
@@ -272,7 +272,7 @@ int diag_add_historycache_info(const struct zbx_json_parse *jp, struct zbx_json
if (0 != (fields & ZBX_DIAG_HISTORYCACHE_MEMORY))
{
- zbx_mem_stats_t data_mem, index_mem, *pdata_mem, *pindex_mem;
+ zbx_shmem_stats_t data_mem, index_mem, *pdata_mem, *pindex_mem;
pdata_mem = (0 != (fields & ZBX_DIAG_HISTORYCACHE_MEMORY_DATA) ? &data_mem : NULL);
pindex_mem = (0 != (fields & ZBX_DIAG_HISTORYCACHE_MEMORY_INDEX) ? &index_mem : NULL);
diff --git a/src/libs/zbxdiag/diag.h b/src/libs/zbxdiag/diag.h
index 791ac7c6736..09f334c8fe3 100644
--- a/src/libs/zbxdiag/diag.h
+++ b/src/libs/zbxdiag/diag.h
@@ -22,7 +22,7 @@
#include "zbxjson.h"
#include "zbxalgo.h"
-#include "memalloc.h"
+#include "zbxshmem.h"
#define ZBX_DIAG_SECTION_MAX 64
#define ZBX_DIAG_FIELD_MAX 64
@@ -75,7 +75,7 @@ void diag_map_free(zbx_diag_map_t *map);
int diag_parse_request(const struct zbx_json_parse *jp, const zbx_diag_map_t *field_map, zbx_uint64_t *field_mask,
zbx_vector_ptr_t *top_views, char **error);
-void diag_add_mem_stats(struct zbx_json *json, const char *name, const zbx_mem_stats_t *stats);
+void diag_add_mem_stats(struct zbx_json *json, const char *name, const zbx_shmem_stats_t *stats);
int diag_add_section_info(const char *section, const struct zbx_json_parse *jp, struct zbx_json *json, char **error);
diff --git a/src/libs/zbxdiag/diag_server.c b/src/libs/zbxdiag/diag_server.c
index 08b899acd98..867fe1a522a 100644
--- a/src/libs/zbxdiag/diag_server.c
+++ b/src/libs/zbxdiag/diag_server.c
@@ -127,7 +127,7 @@ static int diag_add_valuecache_info(const struct zbx_json_parse *jp, struct zbx_
if (0 != (fields & ZBX_DIAG_VALUECACHE_MEMORY))
{
- zbx_mem_stats_t mem;
+ zbx_shmem_stats_t mem;
time1 = zbx_time();
zbx_vc_get_mem_stats(&mem);
diff --git a/src/libs/zbxserver/evalfunc.c b/src/libs/zbxserver/evalfunc.c
index 290bad8d960..c38d616a39f 100644
--- a/src/libs/zbxserver/evalfunc.c
+++ b/src/libs/zbxserver/evalfunc.c
@@ -2623,6 +2623,7 @@ static int trends_eval_stl(const char *table, zbx_uint64_t itemid, int start, in
zbx_history_record_t val;
val.timestamp.sec = period_counter;
+ val.timestamp.ns = 0;
if (FAIL == zbx_trends_eval_avg(table, itemid, period_counter, period_counter, &tmp_res, NULL))
{
diff --git a/src/libs/zbxserver/expression.c b/src/libs/zbxserver/expression.c
index 2a6513eea72..c55763b03fa 100644
--- a/src/libs/zbxserver/expression.c
+++ b/src/libs/zbxserver/expression.c
@@ -5292,7 +5292,7 @@ static void substitute_functions(zbx_vector_ptr_t *triggers, const zbx_vector_ui
ZBX_DEFAULT_UINT64_COMPARE_FUNC);
zbx_hashset_create_ext(&funcs, triggers->values_num, func_hash_func, func_compare_func, func_clean,
- ZBX_DEFAULT_MEM_MALLOC_FUNC, ZBX_DEFAULT_MEM_REALLOC_FUNC, ZBX_DEFAULT_MEM_FREE_FUNC);
+ ZBX_DEFAULT_MEM_MALLOC_FUNC, ZBX_DEFAULT_MEM_REALLOC_FUNC, ZBX_DEFAULT_MEM_FREE_FUNC);
zbx_populate_function_items(&functionids, &funcs, &ifuncs, triggers);
diff --git a/src/libs/zbxmemory/Makefile.am b/src/libs/zbxshmem/Makefile.am
index 7dcd4dbfbbd..1694e7e8132 100644
--- a/src/libs/zbxmemory/Makefile.am
+++ b/src/libs/zbxshmem/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-noinst_LIBRARIES = libzbxmemory.a
+noinst_LIBRARIES = libzbxshmem.a
-libzbxmemory_a_SOURCES = \
+libzbxshmem_a_SOURCES = \
memalloc.c
diff --git a/src/libs/zbxmemory/memalloc.c b/src/libs/zbxshmem/memalloc.c
index 080be17efd6..d181b71d3e3 100644
--- a/src/libs/zbxmemory/memalloc.c
+++ b/src/libs/zbxshmem/memalloc.c
@@ -17,7 +17,7 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "memalloc.h"
+#include "zbxshmem.h"
#include "common.h"
#include "log.h"
@@ -44,7 +44,7 @@
* *
* 8-aligned 8-aligned *
* *
- * when a chunk is used, `size' fields have MEM_FLG_USED bit set *
+ * when a chunk is used, `size' fields have SHMEM_FLG_USED bit set *
* *
* when a chunk is free, the first 2 * ZBX_PTR_SIZE bytes of allocatable *
* memory contain pointers to the previous and next chunks, in that order *
@@ -55,7 +55,7 @@
* *
* - size is kept on both left and right ends for quick merging *
* (when freeing a chunk, we can quickly see if the previous *
- * and next chunks are free, those will not have MEM_FLG_USED) *
+ * and next chunks are free, those will not have SHMEM_FLG_USED) *
* *
* (*) free chunks are stored in doubly-linked lists according to their sizes *
* *
@@ -80,7 +80,7 @@
* | | *
* *
* lo_bound `size' fields in chunk B hi_bound *
- * (aligned) have MEM_FLG_USED bit set (aligned) *
+ * (aligned) have SHMEM_FLG_USED bit set (aligned) *
* *
******************************************************************************/
@@ -101,22 +101,22 @@ static void mem_set_next_chunk(void *chunk, void *next);
static void **mem_ptr_to_prev_field(void *chunk);
static void **mem_ptr_to_next_field(void *chunk, void **first_chunk);
-static void mem_link_chunk(zbx_mem_info_t *info, void *chunk);
-static void mem_unlink_chunk(zbx_mem_info_t *info, void *chunk);
+static void mem_link_chunk(zbx_shmem_info_t *info, void *chunk);
+static void mem_unlink_chunk(zbx_shmem_info_t *info, void *chunk);
-static void *__mem_malloc(zbx_mem_info_t *info, zbx_uint64_t size);
-static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size);
-static void __mem_free(zbx_mem_info_t *info, void *ptr);
+static void *__mem_malloc(zbx_shmem_info_t *info, zbx_uint64_t size);
+static void *__mem_realloc(zbx_shmem_info_t *info, void *old, zbx_uint64_t size);
+static void __mem_free(zbx_shmem_info_t *info, void *ptr);
-#define MEM_SIZE_FIELD sizeof(zbx_uint64_t)
+#define SHMEM_SIZE_FIELD sizeof(zbx_uint64_t)
-#define MEM_FLG_USED ((__UINT64_C(1))<<63)
+#define SHMEM_FLG_USED ((__UINT64_C(1))<<63)
-#define FREE_CHUNK(ptr) (((*(zbx_uint64_t *)(ptr)) & MEM_FLG_USED) == 0)
-#define CHUNK_SIZE(ptr) ((*(zbx_uint64_t *)(ptr)) & ~MEM_FLG_USED)
+#define FREE_CHUNK(ptr) (((*(zbx_uint64_t *)(ptr)) & SHMEM_FLG_USED) == 0)
+#define CHUNK_SIZE(ptr) ((*(zbx_uint64_t *)(ptr)) & ~SHMEM_FLG_USED)
-#define MEM_MIN_SIZE __UINT64_C(128)
-#define MEM_MAX_SIZE __UINT64_C(0x1000000000) /* 64 GB */
+#define SHMEM_MIN_SIZE __UINT64_C(128)
+#define SHMEM_MAX_SIZE __UINT64_C(0x1000000000) /* 64 GB */
/* helper functions */
@@ -141,64 +141,64 @@ static void *ALIGNPTR(void *ptr)
static zbx_uint64_t mem_proper_alloc_size(zbx_uint64_t size)
{
- if (size >= MEM_MIN_ALLOC)
+ if (size >= SHMEM_MIN_ALLOC)
return size + ((8 - (size & 7)) & 7); /* allocate in multiples of 8... */
else
- return MEM_MIN_ALLOC; /* ...and at least MEM_MIN_ALLOC */
+ return SHMEM_MIN_ALLOC; /* ...and at least SHMEM_MIN_ALLOC */
}
static int mem_bucket_by_size(zbx_uint64_t size)
{
- if (size < MEM_MIN_BUCKET_SIZE)
+ if (size < ZBX_SHMEM_MIN_BUCKET_SIZE)
return 0;
- if (size < MEM_MAX_BUCKET_SIZE)
- return (size - MEM_MIN_BUCKET_SIZE) >> 3;
- return MEM_BUCKET_COUNT - 1;
+ if (size < SHMEM_MAX_BUCKET_SIZE)
+ return (size - ZBX_SHMEM_MIN_BUCKET_SIZE) >> 3;
+ return ZBX_SHMEM_BUCKET_COUNT - 1;
}
static void mem_set_chunk_size(void *chunk, zbx_uint64_t size)
{
*(zbx_uint64_t *)chunk = size;
- *(zbx_uint64_t *)((char *)chunk + MEM_SIZE_FIELD + size) = size;
+ *(zbx_uint64_t *)((char *)chunk + SHMEM_SIZE_FIELD + size) = size;
}
static void mem_set_used_chunk_size(void *chunk, zbx_uint64_t size)
{
- *(zbx_uint64_t *)chunk = MEM_FLG_USED | size;
- *(zbx_uint64_t *)((char *)chunk + MEM_SIZE_FIELD + size) = MEM_FLG_USED | size;
+ *(zbx_uint64_t *)chunk = SHMEM_FLG_USED | size;
+ *(zbx_uint64_t *)((char *)chunk + SHMEM_SIZE_FIELD + size) = SHMEM_FLG_USED | size;
}
static void *mem_get_prev_chunk(void *chunk)
{
- return *(void **)((char *)chunk + MEM_SIZE_FIELD);
+ return *(void **)((char *)chunk + SHMEM_SIZE_FIELD);
}
static void mem_set_prev_chunk(void *chunk, void *prev)
{
- *(void **)((char *)chunk + MEM_SIZE_FIELD) = prev;
+ *(void **)((char *)chunk + SHMEM_SIZE_FIELD) = prev;
}
static void *mem_get_next_chunk(void *chunk)
{
- return *(void **)((char *)chunk + MEM_SIZE_FIELD + ZBX_PTR_SIZE);
+ return *(void **)((char *)chunk + SHMEM_SIZE_FIELD + ZBX_PTR_SIZE);
}
static void mem_set_next_chunk(void *chunk, void *next)
{
- *(void **)((char *)chunk + MEM_SIZE_FIELD + ZBX_PTR_SIZE) = next;
+ *(void **)((char *)chunk + SHMEM_SIZE_FIELD + ZBX_PTR_SIZE) = next;
}
static void **mem_ptr_to_prev_field(void *chunk)
{
- return (NULL != chunk ? (void **)((char *)chunk + MEM_SIZE_FIELD) : NULL);
+ return (NULL != chunk ? (void **)((char *)chunk + SHMEM_SIZE_FIELD) : NULL);
}
static void **mem_ptr_to_next_field(void *chunk, void **first_chunk)
{
- return (NULL != chunk ? (void **)((char *)chunk + MEM_SIZE_FIELD + ZBX_PTR_SIZE) : first_chunk);
+ return (NULL != chunk ? (void **)((char *)chunk + SHMEM_SIZE_FIELD + ZBX_PTR_SIZE) : first_chunk);
}
-static void mem_link_chunk(zbx_mem_info_t *info, void *chunk)
+static void mem_link_chunk(zbx_shmem_info_t *info, void *chunk)
{
int index;
@@ -213,7 +213,7 @@ static void mem_link_chunk(zbx_mem_info_t *info, void *chunk)
info->buckets[index] = chunk;
}
-static void mem_unlink_chunk(zbx_mem_info_t *info, void *chunk)
+static void mem_unlink_chunk(zbx_shmem_info_t *info, void *chunk)
{
int index;
void *prev_chunk, *next_chunk;
@@ -234,7 +234,7 @@ static void mem_unlink_chunk(zbx_mem_info_t *info, void *chunk)
/* private memory functions */
-static void *__mem_malloc(zbx_mem_info_t *info, zbx_uint64_t size)
+static void *__mem_malloc(zbx_shmem_info_t *info, zbx_uint64_t size)
{
int index;
void *chunk;
@@ -246,12 +246,12 @@ static void *__mem_malloc(zbx_mem_info_t *info, zbx_uint64_t size)
index = mem_bucket_by_size(size);
- while (index < MEM_BUCKET_COUNT - 1 && NULL == info->buckets[index])
+ while (index < ZBX_SHMEM_BUCKET_COUNT - 1 && NULL == info->buckets[index])
index++;
chunk = info->buckets[index];
- if (index == MEM_BUCKET_COUNT - 1)
+ if (index == ZBX_SHMEM_BUCKET_COUNT - 1)
{
/* otherwise, find a chunk big enough according to first-fit strategy */
@@ -292,7 +292,7 @@ static void *__mem_malloc(zbx_mem_info_t *info, zbx_uint64_t size)
/* either use the full chunk or split it */
- if (chunk_size < size + 2 * MEM_SIZE_FIELD + MEM_MIN_ALLOC)
+ if (chunk_size < size + 2 * SHMEM_SIZE_FIELD + SHMEM_MIN_ALLOC)
{
info->used_size += chunk_size;
info->free_size -= chunk_size;
@@ -304,8 +304,8 @@ static void *__mem_malloc(zbx_mem_info_t *info, zbx_uint64_t size)
void *new_chunk;
zbx_uint64_t new_chunk_size;
- new_chunk = (void *)((char *)chunk + MEM_SIZE_FIELD + size + MEM_SIZE_FIELD);
- new_chunk_size = chunk_size - size - 2 * MEM_SIZE_FIELD;
+ new_chunk = (void *)((char *)chunk + SHMEM_SIZE_FIELD + size + SHMEM_SIZE_FIELD);
+ new_chunk_size = chunk_size - size - 2 * SHMEM_SIZE_FIELD;
mem_set_chunk_size(new_chunk, new_chunk_size);
mem_link_chunk(info, new_chunk);
@@ -319,7 +319,7 @@ static void *__mem_malloc(zbx_mem_info_t *info, zbx_uint64_t size)
return chunk;
}
-static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
+static void *__mem_realloc(zbx_shmem_info_t *info, void *old, zbx_uint64_t size)
{
void *chunk, *new_chunk, *next_chunk;
zbx_uint64_t chunk_size, new_chunk_size;
@@ -327,10 +327,10 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
size = mem_proper_alloc_size(size);
- chunk = (void *)((char *)old - MEM_SIZE_FIELD);
+ chunk = (void *)((char *)old - SHMEM_SIZE_FIELD);
chunk_size = CHUNK_SIZE(chunk);
- next_chunk = (void *)((char *)chunk + MEM_SIZE_FIELD + chunk_size + MEM_SIZE_FIELD);
+ next_chunk = (void *)((char *)chunk + SHMEM_SIZE_FIELD + chunk_size + SHMEM_SIZE_FIELD);
next_free = (next_chunk < info->hi_bound && FREE_CHUNK(next_chunk));
if (size <= chunk_size)
@@ -347,7 +347,7 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
info->used_size -= chunk_size - size;
info->free_size += chunk_size - size;
- new_chunk = (void *)((char *)chunk + MEM_SIZE_FIELD + size + MEM_SIZE_FIELD);
+ new_chunk = (void *)((char *)chunk + SHMEM_SIZE_FIELD + size + SHMEM_SIZE_FIELD);
new_chunk_size = CHUNK_SIZE(next_chunk) + (chunk_size - size);
mem_unlink_chunk(info, next_chunk);
@@ -362,10 +362,10 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
/* split the current one */
info->used_size -= chunk_size - size;
- info->free_size += chunk_size - size - 2 * MEM_SIZE_FIELD;
+ info->free_size += chunk_size - size - 2 * SHMEM_SIZE_FIELD;
- new_chunk = (void *)((char *)chunk + MEM_SIZE_FIELD + size + MEM_SIZE_FIELD);
- new_chunk_size = chunk_size - size - 2 * MEM_SIZE_FIELD;
+ new_chunk = (void *)((char *)chunk + SHMEM_SIZE_FIELD + size + SHMEM_SIZE_FIELD);
+ new_chunk_size = chunk_size - size - 2 * SHMEM_SIZE_FIELD;
mem_set_chunk_size(new_chunk, new_chunk_size);
mem_link_chunk(info, new_chunk);
@@ -376,18 +376,18 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
return chunk;
}
- if (next_free && chunk_size + 2 * MEM_SIZE_FIELD + CHUNK_SIZE(next_chunk) >= size)
+ if (next_free && chunk_size + 2 * SHMEM_SIZE_FIELD + CHUNK_SIZE(next_chunk) >= size)
{
info->used_size -= chunk_size;
- info->free_size += chunk_size + 2 * MEM_SIZE_FIELD;
+ info->free_size += chunk_size + 2 * SHMEM_SIZE_FIELD;
- chunk_size += 2 * MEM_SIZE_FIELD + CHUNK_SIZE(next_chunk);
+ chunk_size += 2 * SHMEM_SIZE_FIELD + CHUNK_SIZE(next_chunk);
mem_unlink_chunk(info, next_chunk);
/* either use the full next_chunk or split it */
- if (chunk_size < size + 2 * MEM_SIZE_FIELD + MEM_MIN_ALLOC)
+ if (chunk_size < size + 2 * SHMEM_SIZE_FIELD + SHMEM_MIN_ALLOC)
{
info->used_size += chunk_size;
info->free_size -= chunk_size;
@@ -396,8 +396,8 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
}
else
{
- new_chunk = (void *)((char *)chunk + MEM_SIZE_FIELD + size + MEM_SIZE_FIELD);
- new_chunk_size = chunk_size - size - 2 * MEM_SIZE_FIELD;
+ new_chunk = (void *)((char *)chunk + SHMEM_SIZE_FIELD + size + SHMEM_SIZE_FIELD);
+ new_chunk_size = chunk_size - size - 2 * SHMEM_SIZE_FIELD;
mem_set_chunk_size(new_chunk, new_chunk_size);
mem_link_chunk(info, new_chunk);
@@ -412,7 +412,7 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
}
else if (NULL != (new_chunk = __mem_malloc(info, size)))
{
- memcpy((char *)new_chunk + MEM_SIZE_FIELD, (char *)chunk + MEM_SIZE_FIELD, chunk_size);
+ memcpy((char *)new_chunk + SHMEM_SIZE_FIELD, (char *)chunk + SHMEM_SIZE_FIELD, chunk_size);
__mem_free(info, old);
@@ -427,17 +427,17 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
new_chunk_size = chunk_size;
if (0 != next_free)
- new_chunk_size += CHUNK_SIZE(next_chunk) + 2 * MEM_SIZE_FIELD;
+ new_chunk_size += CHUNK_SIZE(next_chunk) + 2 * SHMEM_SIZE_FIELD;
- if (info->lo_bound < chunk && FREE_CHUNK((char *)chunk - MEM_SIZE_FIELD))
- new_chunk_size += CHUNK_SIZE((char *)chunk - MEM_SIZE_FIELD) + 2 * MEM_SIZE_FIELD;
+ if (info->lo_bound < chunk && FREE_CHUNK((char *)chunk - SHMEM_SIZE_FIELD))
+ new_chunk_size += CHUNK_SIZE((char *)chunk - SHMEM_SIZE_FIELD) + 2 * SHMEM_SIZE_FIELD;
if (size > new_chunk_size)
return NULL;
tmp = zbx_malloc(tmp, chunk_size);
- memcpy(tmp, (char *)chunk + MEM_SIZE_FIELD, chunk_size);
+ memcpy(tmp, (char *)chunk + SHMEM_SIZE_FIELD, chunk_size);
__mem_free(info, old);
@@ -447,7 +447,7 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
exit(EXIT_FAILURE);
}
- memcpy((char *)new_chunk + MEM_SIZE_FIELD, tmp, chunk_size);
+ memcpy((char *)new_chunk + SHMEM_SIZE_FIELD, tmp, chunk_size);
zbx_free(tmp);
@@ -455,14 +455,14 @@ static void *__mem_realloc(zbx_mem_info_t *info, void *old, zbx_uint64_t size)
}
}
-static void __mem_free(zbx_mem_info_t *info, void *ptr)
+static void __mem_free(zbx_shmem_info_t *info, void *ptr)
{
void *chunk;
void *prev_chunk, *next_chunk;
zbx_uint64_t chunk_size;
int prev_free, next_free;
- chunk = (void *)((char *)ptr - MEM_SIZE_FIELD);
+ chunk = (void *)((char *)ptr - SHMEM_SIZE_FIELD);
chunk_size = CHUNK_SIZE(chunk);
info->used_size -= chunk_size;
@@ -470,19 +470,19 @@ static void __mem_free(zbx_mem_info_t *info, void *ptr)
/* see if we can merge with previous and next chunks */
- next_chunk = (void *)((char *)chunk + MEM_SIZE_FIELD + chunk_size + MEM_SIZE_FIELD);
+ next_chunk = (void *)((char *)chunk + SHMEM_SIZE_FIELD + chunk_size + SHMEM_SIZE_FIELD);
- prev_free = (info->lo_bound < chunk && FREE_CHUNK((char *)chunk - MEM_SIZE_FIELD));
+ prev_free = (info->lo_bound < chunk && FREE_CHUNK((char *)chunk - SHMEM_SIZE_FIELD));
next_free = (next_chunk < info->hi_bound && FREE_CHUNK(next_chunk));
if (prev_free && next_free)
{
- info->free_size += 4 * MEM_SIZE_FIELD;
+ info->free_size += 4 * SHMEM_SIZE_FIELD;
- prev_chunk = (char *)chunk - MEM_SIZE_FIELD - CHUNK_SIZE((char *)chunk - MEM_SIZE_FIELD) -
- MEM_SIZE_FIELD;
+ prev_chunk = (char *)chunk - SHMEM_SIZE_FIELD - CHUNK_SIZE((char *)chunk - SHMEM_SIZE_FIELD) -
+ SHMEM_SIZE_FIELD;
- chunk_size += 4 * MEM_SIZE_FIELD + CHUNK_SIZE(prev_chunk) + CHUNK_SIZE(next_chunk);
+ chunk_size += 4 * SHMEM_SIZE_FIELD + CHUNK_SIZE(prev_chunk) + CHUNK_SIZE(next_chunk);
mem_unlink_chunk(info, prev_chunk);
mem_unlink_chunk(info, next_chunk);
@@ -493,12 +493,12 @@ static void __mem_free(zbx_mem_info_t *info, void *ptr)
}
else if (prev_free)
{
- info->free_size += 2 * MEM_SIZE_FIELD;
+ info->free_size += 2 * SHMEM_SIZE_FIELD;
- prev_chunk = (void *)((char *)chunk - MEM_SIZE_FIELD - CHUNK_SIZE((char *)chunk - MEM_SIZE_FIELD) -
- MEM_SIZE_FIELD);
+ prev_chunk = (void *)((char *)chunk - SHMEM_SIZE_FIELD - CHUNK_SIZE((char *)chunk - SHMEM_SIZE_FIELD) -
+ SHMEM_SIZE_FIELD);
- chunk_size += 2 * MEM_SIZE_FIELD + CHUNK_SIZE(prev_chunk);
+ chunk_size += 2 * SHMEM_SIZE_FIELD + CHUNK_SIZE(prev_chunk);
mem_unlink_chunk(info, prev_chunk);
@@ -508,9 +508,9 @@ static void __mem_free(zbx_mem_info_t *info, void *ptr)
}
else if (next_free)
{
- info->free_size += 2 * MEM_SIZE_FIELD;
+ info->free_size += 2 * SHMEM_SIZE_FIELD;
- chunk_size += 2 * MEM_SIZE_FIELD + CHUNK_SIZE(next_chunk);
+ chunk_size += 2 * SHMEM_SIZE_FIELD + CHUNK_SIZE(next_chunk);
mem_unlink_chunk(info, next_chunk);
@@ -526,8 +526,8 @@ static void __mem_free(zbx_mem_info_t *info, void *ptr)
/* public memory interface */
-int zbx_mem_create(zbx_mem_info_t **info, zbx_uint64_t size, const char *descr, const char *param, int allow_oom,
- char **error)
+int zbx_shmem_create(zbx_shmem_info_t **info, zbx_uint64_t size, const char *descr, const char *param,
+ int allow_oom, char **error)
{
int shm_id, index, ret = FAIL;
void *base;
@@ -546,10 +546,10 @@ int zbx_mem_create(zbx_mem_info_t **info, zbx_uint64_t size, const char *descr,
goto out;
}
- if (!(MEM_MIN_SIZE <= size && size <= MEM_MAX_SIZE))
+ if (!(SHMEM_MIN_SIZE <= size && size <= SHMEM_MAX_SIZE))
{
*error = zbx_dsprintf(*error, "requested size " ZBX_FS_SIZE_T " not within bounds [" ZBX_FS_UI64
- " <= size <= " ZBX_FS_UI64 "]", (zbx_fs_size_t)size, MEM_MIN_SIZE, MEM_MAX_SIZE);
+ " <= size <= " ZBX_FS_UI64 "]", (zbx_fs_size_t)size, SHMEM_MIN_SIZE, SHMEM_MAX_SIZE);
goto out;
}
@@ -571,9 +571,9 @@ int zbx_mem_create(zbx_mem_info_t **info, zbx_uint64_t size, const char *descr,
ret = SUCCEED;
- /* allocate zbx_mem_info_t structure, its buckets, and description inside shared memory */
+ /* allocate zbx_shmem_info_t structure, its buckets, and description inside shared memory */
- *info = (zbx_mem_info_t *)ALIGN8(base);
+ *info = (zbx_shmem_info_t *)ALIGN8(base);
(*info)->base = base;
(*info)->shm_id = shm_id;
(*info)->orig_size = size;
@@ -582,9 +582,9 @@ int zbx_mem_create(zbx_mem_info_t **info, zbx_uint64_t size, const char *descr,
base = (void *)(*info + 1);
(*info)->buckets = (void **)ALIGNPTR(base);
- memset((*info)->buckets, 0, MEM_BUCKET_COUNT * ZBX_PTR_SIZE);
- size -= (char *)((*info)->buckets + MEM_BUCKET_COUNT) - (char *)base;
- base = (void *)((*info)->buckets + MEM_BUCKET_COUNT);
+ memset((*info)->buckets, 0, ZBX_SHMEM_BUCKET_COUNT * ZBX_PTR_SIZE);
+ size -= (char *)((*info)->buckets + ZBX_SHMEM_BUCKET_COUNT) - (char *)base;
+ base = (void *)((*info)->buckets + ZBX_SHMEM_BUCKET_COUNT);
zbx_strlcpy((char *)base, descr, size);
(*info)->mem_descr = (char *)base;
@@ -603,7 +603,7 @@ int zbx_mem_create(zbx_mem_info_t **info, zbx_uint64_t size, const char *descr,
(*info)->hi_bound = ALIGN8((char *)base + size - 8);
(*info)->total_size = (zbx_uint64_t)((char *)((*info)->hi_bound) - (char *)((*info)->lo_bound) -
- 2 * MEM_SIZE_FIELD);
+ 2 * SHMEM_SIZE_FIELD);
index = mem_bucket_by_size((*info)->total_size);
(*info)->buckets[index] = (*info)->lo_bound;
@@ -615,8 +615,8 @@ int zbx_mem_create(zbx_mem_info_t **info, zbx_uint64_t size, const char *descr,
(*info)->free_size = (*info)->total_size;
zabbix_log(LOG_LEVEL_DEBUG, "valid user addresses: [%p, %p] total size: " ZBX_FS_SIZE_T,
- (void *)((char *)(*info)->lo_bound + MEM_SIZE_FIELD),
- (void *)((char *)(*info)->hi_bound - MEM_SIZE_FIELD),
+ (void *)((char *)(*info)->lo_bound + SHMEM_SIZE_FIELD),
+ (void *)((char *)(*info)->hi_bound - SHMEM_SIZE_FIELD),
(zbx_fs_size_t)(*info)->total_size);
out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
@@ -624,12 +624,12 @@ out:
return ret;
}
-void zbx_mem_destroy(zbx_mem_info_t *info)
+void zbx_shmem_destroy(zbx_shmem_info_t *info)
{
(void)shmdt(info->base);
}
-void *__zbx_mem_malloc(const char *file, int line, zbx_mem_info_t *info, const void *old, size_t size)
+void *__zbx_shmem_malloc(const char *file, int line, zbx_shmem_info_t *info, const void *old, size_t size)
{
void *chunk;
@@ -640,7 +640,7 @@ void *__zbx_mem_malloc(const char *file, int line, zbx_mem_info_t *info, const v
exit(EXIT_FAILURE);
}
- if (0 == size || size > MEM_MAX_SIZE)
+ if (0 == size || size > SHMEM_MAX_SIZE)
{
zabbix_log(LOG_LEVEL_CRIT, "[file:%s,line:%d] %s(): asking for a bad number of bytes (" ZBX_FS_SIZE_T
")", file, line, __func__, (zbx_fs_size_t)size);
@@ -658,19 +658,19 @@ void *__zbx_mem_malloc(const char *file, int line, zbx_mem_info_t *info, const v
file, line, __func__, (zbx_fs_size_t)size);
zabbix_log(LOG_LEVEL_CRIT, "[file:%s,line:%d] %s(): please increase %s configuration parameter",
file, line, __func__, info->mem_param);
- zbx_mem_dump_stats(LOG_LEVEL_CRIT, info);
+ zbx_shmem_dump_stats(LOG_LEVEL_CRIT, info);
zbx_backtrace();
exit(EXIT_FAILURE);
}
- return (void *)((char *)chunk + MEM_SIZE_FIELD);
+ return (void *)((char *)chunk + SHMEM_SIZE_FIELD);
}
-void *__zbx_mem_realloc(const char *file, int line, zbx_mem_info_t *info, void *old, size_t size)
+void *__zbx_shmem_realloc(const char *file, int line, zbx_shmem_info_t *info, void *old, size_t size)
{
void *chunk;
- if (0 == size || size > MEM_MAX_SIZE)
+ if (0 == size || size > SHMEM_MAX_SIZE)
{
zabbix_log(LOG_LEVEL_CRIT, "[file:%s,line:%d] %s(): asking for a bad number of bytes (" ZBX_FS_SIZE_T
")", file, line, __func__, (zbx_fs_size_t)size);
@@ -691,15 +691,15 @@ void *__zbx_mem_realloc(const char *file, int line, zbx_mem_info_t *info, void *
file, line, __func__, (zbx_fs_size_t)size);
zabbix_log(LOG_LEVEL_CRIT, "[file:%s,line:%d] %s(): please increase %s configuration parameter",
file, line, __func__, info->mem_param);
- zbx_mem_dump_stats(LOG_LEVEL_CRIT, info);
+ zbx_shmem_dump_stats(LOG_LEVEL_CRIT, info);
zbx_backtrace();
exit(EXIT_FAILURE);
}
- return (void *)((char *)chunk + MEM_SIZE_FIELD);
+ return (void *)((char *)chunk + SHMEM_SIZE_FIELD);
}
-void __zbx_mem_free(const char *file, int line, zbx_mem_info_t *info, void *ptr)
+void __zbx_shmem_free(const char *file, int line, zbx_shmem_info_t *info, void *ptr)
{
if (NULL == ptr)
{
@@ -710,13 +710,13 @@ void __zbx_mem_free(const char *file, int line, zbx_mem_info_t *info, void *ptr)
__mem_free(info, ptr);
}
-void zbx_mem_clear(zbx_mem_info_t *info)
+void zbx_shmem_clear(zbx_shmem_info_t *info)
{
int index;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
- memset(info->buckets, 0, MEM_BUCKET_COUNT * ZBX_PTR_SIZE);
+ memset(info->buckets, 0, ZBX_SHMEM_BUCKET_COUNT * ZBX_PTR_SIZE);
index = mem_bucket_by_size(info->total_size);
info->buckets[index] = info->lo_bound;
mem_set_chunk_size(info->buckets[index], info->total_size);
@@ -728,7 +728,7 @@ void zbx_mem_clear(zbx_mem_info_t *info)
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
}
-void zbx_mem_get_stats(const zbx_mem_info_t *info, zbx_mem_stats_t *stats)
+void zbx_shmem_get_stats(const zbx_shmem_info_t *info, zbx_shmem_stats_t *stats)
{
void *chunk;
int i;
@@ -738,7 +738,7 @@ void zbx_mem_get_stats(const zbx_mem_info_t *info, zbx_mem_stats_t *stats)
stats->max_chunk_size = __UINT64_C(0);
stats->min_chunk_size = __UINT64_C(0xffffffffffffffff);
- for (i = 0; i < MEM_BUCKET_COUNT; i++)
+ for (i = 0; i < ZBX_SHMEM_BUCKET_COUNT; i++)
{
counter = 0;
chunk = info->buckets[i];
@@ -756,27 +756,27 @@ void zbx_mem_get_stats(const zbx_mem_info_t *info, zbx_mem_stats_t *stats)
}
stats->overhead = info->total_size - info->used_size - info->free_size;
- stats->used_chunks = stats->overhead / (2 * MEM_SIZE_FIELD) + 1 - stats->free_chunks;
+ stats->used_chunks = stats->overhead / (2 * SHMEM_SIZE_FIELD) + 1 - stats->free_chunks;
stats->free_size = info->free_size;
stats->used_size = info->used_size;
}
-void zbx_mem_dump_stats(int level, zbx_mem_info_t *info)
+void zbx_shmem_dump_stats(int level, zbx_shmem_info_t *info)
{
- zbx_mem_stats_t stats;
+ zbx_shmem_stats_t stats;
int i;
- zbx_mem_get_stats(info, &stats);
+ zbx_shmem_get_stats(info, &stats);
zabbix_log(level, "=== memory statistics for %s ===", info->mem_descr);
- for (i = 0; i < MEM_BUCKET_COUNT; i++)
+ for (i = 0; i < ZBX_SHMEM_BUCKET_COUNT; i++)
{
if (0 == stats.chunks_num[i])
continue;
- zabbix_log(level, "free chunks of size %2s %3d bytes: %8u", i == MEM_BUCKET_COUNT - 1 ? ">=" : "",
- MEM_MIN_BUCKET_SIZE + 8 * i, stats.chunks_num[i]);
+ zabbix_log(level, "free chunks of size %2s %3d bytes: %8u", i == ZBX_SHMEM_BUCKET_COUNT - 1 ? ">=" : "",
+ ZBX_SHMEM_MIN_BUCKET_SIZE + 8 * i, stats.chunks_num[i]);
}
zabbix_log(level, "min chunk size: %10llu bytes", (unsigned long long)stats.min_chunk_size);
@@ -795,7 +795,7 @@ void zbx_mem_dump_stats(int level, zbx_mem_info_t *info)
zabbix_log(level, "================================");
}
-size_t zbx_mem_required_size(int chunks_num, const char *descr, const char *param)
+size_t zbx_shmem_required_size(int chunks_num, const char *descr, const char *param)
{
size_t size = 0;
@@ -806,27 +806,27 @@ size_t zbx_mem_required_size(int chunks_num, const char *descr, const char *para
/* that we will be able to get ourselves 'chunks_num' pieces of memory with a */
/* total size of 'size', given that we also have to store 'descr' and 'param'? */
- size += 7; /* ensure we allocate enough to 8-align zbx_mem_info_t */
- size += sizeof(zbx_mem_info_t);
+ size += 7; /* ensure we allocate enough to 8-align zbx_shmem_info_t */
+ size += sizeof(zbx_shmem_info_t);
size += ZBX_PTR_SIZE - 1; /* ensure we allocate enough to align bucket pointers */
- size += ZBX_PTR_SIZE * MEM_BUCKET_COUNT;
+ size += ZBX_PTR_SIZE * ZBX_SHMEM_BUCKET_COUNT;
size += strlen(descr) + 1;
size += strlen(param) + 1;
- size += (MEM_SIZE_FIELD - 1) + 8; /* ensure we allocate enough to align the first chunk */
- size += (MEM_SIZE_FIELD - 1) + 8; /* ensure we allocate enough to align right size field */
+ size += (SHMEM_SIZE_FIELD - 1) + 8; /* ensure we allocate enough to align the first chunk */
+ size += (SHMEM_SIZE_FIELD - 1) + 8; /* ensure we allocate enough to align right size field */
- size += (chunks_num - 1) * MEM_SIZE_FIELD * 2; /* each additional chunk requires 16 bytes of overhead */
- size += chunks_num * (MEM_MIN_ALLOC - 1); /* each chunk has size of at least MEM_MIN_ALLOC bytes */
+ size += (chunks_num - 1) * SHMEM_SIZE_FIELD * 2;/* each additional chunk requires 16 bytes of overhead */
+ size += chunks_num * (SHMEM_MIN_ALLOC - 1); /* each chunk has size of at least SHMEM_MIN_ALLOC bytes */
zabbix_log(LOG_LEVEL_DEBUG, "End of %s() size:" ZBX_FS_SIZE_T, __func__, (zbx_fs_size_t)size);
return size;
}
-zbx_uint64_t zbx_mem_required_chunk_size(zbx_uint64_t size)
+zbx_uint64_t zbx_shmem_required_chunk_size(zbx_uint64_t size)
{
if (0 == size)
return 0;
- return mem_proper_alloc_size(size) + MEM_SIZE_FIELD * 2;
+ return mem_proper_alloc_size(size) + SHMEM_SIZE_FIELD * 2;
}
diff --git a/src/libs/zbxsysinfo/simple/simple.c b/src/libs/zbxsysinfo/simple/simple.c
index 469fbf7fbab..5ed55af6f2c 100644
--- a/src/libs/zbxsysinfo/simple/simple.c
+++ b/src/libs/zbxsysinfo/simple/simple.c
@@ -24,7 +24,6 @@
#include "zbxcomms.h"
#include "log.h"
#include "cfg.h"
-#include "telnet.h"
#include "../common/net.h"
#include "ntp.h"
@@ -238,7 +237,7 @@ static int check_telnet(const char *host, unsigned short port, int timeout, int
zbx_strerror(errno));
}
#endif
- if (SUCCEED == telnet_test_login(s.socket))
+ if (SUCCEED == zbx_telnet_test_login(s.socket))
*value_int = 1;
else
zabbix_log(LOG_LEVEL_DEBUG, "Telnet check error: no login prompt");
diff --git a/src/libs/zbxtrends/cache.c b/src/libs/zbxtrends/cache.c
index c8e8826622c..9041848d64e 100644
--- a/src/libs/zbxtrends/cache.c
+++ b/src/libs/zbxtrends/cache.c
@@ -22,7 +22,7 @@
#include "log.h"
#include "zbxtrends.h"
#include "mutexs.h"
-#include "memalloc.h"
+#include "zbxshmem.h"
#include "trends.h"
extern zbx_uint64_t CONFIG_TREND_FUNC_CACHE_SIZE;
@@ -73,11 +73,11 @@ static int alloc_num = 0;
* 2) indexing hashset slots pointer array, allocated during cache initialization
* 3) slots array, allocated during cache initialization and used for hashset entry allocations
*/
-static zbx_mem_info_t *tfc_mem = NULL;
+static zbx_shmem_info_t *tfc_mem = NULL;
static zbx_mutex_t tfc_lock = ZBX_MUTEX_NULL;
-ZBX_MEM_FUNC_IMPL(__tfc, tfc_mem)
+ZBX_SHMEM_FUNC_IMPL(__tfc, tfc_mem)
#define LOCK_CACHE zbx_mutex_lock(tfc_lock)
#define UNLOCK_CACHE zbx_mutex_unlock(tfc_lock)
@@ -157,7 +157,7 @@ static void *tfc_malloc_func(void *old, size_t size)
return tfc_alloc_slot();
if (0 == alloc_num++)
- return __tfc_mem_malloc_func(old, size);
+ return __tfc_shmem_malloc_func(old, size);
return NULL;
}
@@ -178,7 +178,7 @@ static void tfc_free_func(void *ptr)
return;
}
- __tfc_mem_free_func(ptr);
+ __tfc_shmem_free_func(ptr);
}
/******************************************************************************
@@ -388,15 +388,15 @@ int zbx_tfc_init(char **error)
if (SUCCEED != zbx_mutex_create(&tfc_lock, ZBX_MUTEX_TREND_FUNC, error))
goto out;
- size_reserved = zbx_mem_required_size(1, "trend function cache size", "TrendFunctionCacheSize");
+ size_reserved = zbx_shmem_required_size(1, "trend function cache size", "TrendFunctionCacheSize");
- if (SUCCEED != zbx_mem_create(&tfc_mem, CONFIG_TREND_FUNC_CACHE_SIZE, "trend function cache size",
+ if (SUCCEED != zbx_shmem_create(&tfc_mem, CONFIG_TREND_FUNC_CACHE_SIZE, "trend function cache size",
"TrendFunctionCacheSize", 1, error))
{
goto out;
}
- cache = (zbx_tfc_t *)__tfc_mem_realloc_func(NULL, sizeof(zbx_tfc_t));
+ cache = (zbx_tfc_t *)__tfc_shmem_realloc_func(NULL, sizeof(zbx_tfc_t));
size_actual = CONFIG_TREND_FUNC_CACHE_SIZE;
/* (8 + 8) * 3 - overhead for 3 allocations */
@@ -414,7 +414,7 @@ int zbx_tfc_init(char **error)
cache->lru_head = UINT32_MAX;
cache->lru_tail = UINT32_MAX;
- cache->slots = (zbx_tfc_slot_t *)__tfc_mem_malloc_func(NULL, sizeof(zbx_tfc_slot_t) * cache->slots_num);
+ cache->slots = (zbx_tfc_slot_t *)__tfc_shmem_malloc_func(NULL, sizeof(zbx_tfc_slot_t) * cache->slots_num);
cache->free_head = UINT32_MAX;
cache->free_slot = 0;
@@ -439,7 +439,7 @@ void zbx_tfc_destroy(void)
{
if (0 != CONFIG_TREND_FUNC_CACHE_SIZE)
{
- zbx_mem_destroy(tfc_mem);
+ zbx_shmem_destroy(tfc_mem);
tfc_mem = NULL;
zbx_mutex_destroy(&tfc_lock);
alloc_num = 0;
diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am
index e427a042ccf..4c13c203bbf 100644
--- a/src/zabbix_proxy/Makefile.am
+++ b/src/zabbix_proxy/Makefile.am
@@ -55,7 +55,7 @@ zabbix_proxy_LDADD = \
$(top_builddir)/src/libs/zbxserver/libzbxserver_proxy.a \
$(top_builddir)/src/libs/zbxeval/libzbxeval.a \
$(top_builddir)/src/libs/zbxhistory/libzbxhistory.a \
- $(top_builddir)/src/libs/zbxmemory/libzbxmemory.a \
+ $(top_builddir)/src/libs/zbxshmem/libzbxshmem.a \
$(top_builddir)/src/libs/zbxregexp/libzbxregexp.a \
$(top_builddir)/src/libs/zbxself/libzbxself.a \
$(top_builddir)/src/libs/zbxself/libzbxself_proxy.a \
diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am
index ae986fbc970..a056b208c92 100644
--- a/src/zabbix_server/Makefile.am
+++ b/src/zabbix_server/Makefile.am
@@ -88,7 +88,7 @@ zabbix_server_LDADD = \
$(top_builddir)/src/libs/zbxserver/libzbxserver.a \
$(top_builddir)/src/libs/zbxeval/libzbxeval.a \
$(top_builddir)/src/libs/zbxhistory/libzbxhistory.a \
- $(top_builddir)/src/libs/zbxmemory/libzbxmemory.a \
+ $(top_builddir)/src/libs/zbxshmem/libzbxshmem.a \
$(top_builddir)/src/libs/zbxregexp/libzbxregexp.a \
$(top_builddir)/src/libs/zbxself/libzbxself.a \
$(top_builddir)/src/libs/zbxself/libzbxself_server.a \
diff --git a/src/zabbix_server/alerter/alert_manager.c b/src/zabbix_server/alerter/alert_manager.c
index 3c34f8255b7..cb0530fa827 100644
--- a/src/zabbix_server/alerter/alert_manager.c
+++ b/src/zabbix_server/alerter/alert_manager.c
@@ -34,8 +34,8 @@
#define ZBX_UPDATE_STR(dst, src) \
if (NULL == src) \
- zbx_free(dst); \
- else if (NULL == dst || 0 != strcmp(dst, src)) \
+ zbx_free(dst); \
+ else if (NULL == dst || 0 != strcmp(dst, src)) \
dst = zbx_strdup(dst, src);
#define ZBX_AM_DB_POLL_DELAY 1
@@ -2199,8 +2199,8 @@ static void am_process_diag_top_sources(zbx_am_t *manager, zbx_ipc_client_t *cli
if (NULL == (source = zbx_hashset_search(&sources, &source_local)))
{
+ source_local.alerts_num = 0;
source = zbx_hashset_insert(&sources, &source_local, sizeof(source_local));
- source->alerts_num = 0;
zbx_vector_ptr_append(&view, source);
}
source->alerts_num++;
diff --git a/src/zabbix_server/ipmi/ipmi_manager.c b/src/zabbix_server/ipmi/ipmi_manager.c
index 1f8cf3ab1a4..6dba5990aa7 100644
--- a/src/zabbix_server/ipmi/ipmi_manager.c
+++ b/src/zabbix_server/ipmi/ipmi_manager.c
@@ -588,13 +588,14 @@ static zbx_ipmi_manager_host_t *ipmi_manager_cache_host(zbx_ipmi_manager_t *mana
zbx_ipmi_manager_host_t host_local;
host_local.hostid = hostid;
- host = (zbx_ipmi_manager_host_t *)zbx_hashset_insert(&manager->hosts, &host_local, sizeof(host_local));
+ host_local.disable_until = 0;
+ host_local.poller = ipmi_manager_get_host_poller(manager);
+ host_local.lastcheck = now;
- host->disable_until = 0;
- host->poller = ipmi_manager_get_host_poller(manager);
+ host = (zbx_ipmi_manager_host_t *)zbx_hashset_insert(&manager->hosts, &host_local, sizeof(host_local));
}
-
- host->lastcheck = now;
+ else
+ host->lastcheck = now;
return host;
}
diff --git a/src/zabbix_server/poller/checks_snmp.c b/src/zabbix_server/poller/checks_snmp.c
index c92ae465afd..9def7bd59bc 100644
--- a/src/zabbix_server/poller/checks_snmp.c
+++ b/src/zabbix_server/poller/checks_snmp.c
@@ -294,7 +294,8 @@ static void cache_put_snmp_index(const DC_ITEM *item, const char *snmp_oid, cons
__snmpidx_mapping_hash, __snmpidx_mapping_compare, __snmpidx_mapping_clean,
ZBX_DEFAULT_MEM_MALLOC_FUNC, ZBX_DEFAULT_MEM_REALLOC_FUNC, ZBX_DEFAULT_MEM_FREE_FUNC);
- main_key = (zbx_snmpidx_main_key_t *)zbx_hashset_insert(&snmpidx, &main_key_local, sizeof(main_key_local));
+ main_key = (zbx_snmpidx_main_key_t *)zbx_hashset_insert(&snmpidx, &main_key_local,
+ sizeof(main_key_local));
}
if (NULL == (mapping = (zbx_snmpidx_mapping_t *)zbx_hashset_search(main_key->mappings, &value)))
diff --git a/src/zabbix_server/poller/checks_telnet.c b/src/zabbix_server/poller/checks_telnet.c
index e736c0d33a4..e0c011de7d9 100644
--- a/src/zabbix_server/poller/checks_telnet.c
+++ b/src/zabbix_server/poller/checks_telnet.c
@@ -19,7 +19,6 @@
#include "checks_telnet.h"
-#include "telnet.h"
#include "zbxcomms.h"
#include "log.h"
@@ -57,10 +56,10 @@ static int telnet_run(DC_ITEM *item, AGENT_RESULT *result, const char *encoding)
zbx_strerror(errno)));
}
- if (FAIL == telnet_login(s.socket, item->username, item->password, result))
+ if (FAIL == zbx_telnet_login(s.socket, item->username, item->password, result))
goto tcp_close;
- if (FAIL == telnet_execute(s.socket, item->params, result, encoding))
+ if (FAIL == zbx_telnet_execute(s.socket, item->params, result, encoding))
goto tcp_close;
ret = SUCCEED;
@@ -123,3 +122,5 @@ out:
return ret;
}
+
+#undef TELNET_RUN_KEY
diff --git a/src/zabbix_server/preprocessor/preproc_manager.c b/src/zabbix_server/preprocessor/preproc_manager.c
index 19f21b5c3f5..004eda81111 100644
--- a/src/zabbix_server/preprocessor/preproc_manager.c
+++ b/src/zabbix_server/preprocessor/preproc_manager.c
@@ -1300,9 +1300,10 @@ static void preprocessor_update_history(zbx_preprocessing_manager_t *manager, zb
zbx_preproc_history_t history_local;
history_local.itemid = itemid;
+ zbx_vector_ptr_create(&history_local.history);
+
vault = (zbx_preproc_history_t *)zbx_hashset_insert(&manager->history_cache, &history_local,
sizeof(history_local));
- zbx_vector_ptr_create(&vault->history);
}
zbx_vector_ptr_append_array(&vault->history, history->values, history->values_num);
diff --git a/src/zabbix_server/reporter/report_manager.c b/src/zabbix_server/reporter/report_manager.c
index d1485f0859f..1c1e8dcdbe6 100644
--- a/src/zabbix_server/reporter/report_manager.c
+++ b/src/zabbix_server/reporter/report_manager.c
@@ -1056,21 +1056,30 @@ static void rm_update_cache_reports(zbx_rm_t *manager, int now)
if (NULL == (report = (zbx_rm_report_t *)zbx_hashset_search(&manager->reports, &reportid)))
{
report_local.reportid = reportid;
+ ZBX_STR2UINT64(report_local.userid, row[1]);
+ ZBX_STR2UINT64(report_local.dashboardid, row[3]);
+ report_local.name = zbx_strdup(NULL, row[2]);
+ report_local.timezone = zbx_strdup(NULL, tz);
+ report_local.error = zbx_strdup(NULL, row[12]);
+ ZBX_STR2UCHAR(report_local.period, row[4]);
+ ZBX_STR2UCHAR(report_local.cycle, row[5]);
+ ZBX_STR2UCHAR(report_local.weekdays, row[6]);
+ ZBX_STR2UCHAR(report_local.status, row[14]);
+ report_local.start_time = atoi(row[7]);
+ ZBX_STR2UCHAR(report_local.state, row[11]);
+ report_local.flags = 0;
+ report_local.nextcheck = 0;
+ report_local.active_since = atoi(row[8]);
+ report_local.active_till = atoi(row[9]);
+ report_local.lastsent = atoi(row[13]);
+ zbx_vector_ptr_pair_create(&report_local.params);
+ zbx_vector_recipient_create(&report_local.usergroups);
+ zbx_vector_recipient_create(&report_local.users);
+ zbx_vector_uint64_create(&report_local.users_excl);
+
report = (zbx_rm_report_t *)zbx_hashset_insert(&manager->reports, &report_local,
sizeof(report_local));
- zbx_vector_ptr_pair_create(&report->params);
- zbx_vector_recipient_create(&report->usergroups);
- zbx_vector_recipient_create(&report->users);
- zbx_vector_uint64_create(&report->users_excl);
- report->name = zbx_strdup(NULL, row[2]);
- report->timezone = zbx_strdup(NULL, tz);
- report->nextcheck = 0;
- ZBX_STR2UCHAR(report->state, row[11]);
- report->error = zbx_strdup(NULL, row[12]);
- report->lastsent = atoi(row[13]);
- report->flags = 0;
-
reschedule = 1;
}
else
@@ -1090,17 +1099,17 @@ static void rm_update_cache_reports(zbx_rm_t *manager, int now)
report->timezone = zbx_strdup(report->timezone, tz);
reschedule = 1;
}
- }
- ZBX_STR2UINT64(report->userid, row[1]);
- ZBX_STR2UINT64(report->dashboardid, row[3]);
- ZBX_STR2UCHAR(report->period, row[4]);
- ZBX_STR2UCHAR(report->cycle, row[5]);
- ZBX_STR2UCHAR(report->weekdays, row[6]);
- report->start_time = atoi(row[7]);
- report->active_since = atoi(row[8]);
- report->active_till = atoi(row[9]);
- ZBX_STR2UCHAR(report->status, row[14]);
+ ZBX_STR2UINT64(report->userid, row[1]);
+ ZBX_STR2UINT64(report->dashboardid, row[3]);
+ ZBX_STR2UCHAR(report->period, row[4]);
+ ZBX_STR2UCHAR(report->cycle, row[5]);
+ ZBX_STR2UCHAR(report->weekdays, row[6]);
+ report->start_time = atoi(row[7]);
+ report->active_since = atoi(row[8]);
+ report->active_till = atoi(row[9]);
+ ZBX_STR2UCHAR(report->status, row[14]);
+ }
if (ZBX_REPORT_STATUS_DISABLED == report->status)
{
diff --git a/src/zabbix_server/vmware/vmware.c b/src/zabbix_server/vmware/vmware.c
index cd12e9135c4..036f007af89 100644
--- a/src/zabbix_server/vmware/vmware.c
+++ b/src/zabbix_server/vmware/vmware.c
@@ -25,7 +25,7 @@
#endif
#include "mutexs.h"
-#include "memalloc.h"
+#include "zbxshmem.h"
#include "log.h"
#include "daemon.h"
#include "zbxself.h"
@@ -69,8 +69,8 @@ extern unsigned char program_type;
extern ZBX_THREAD_LOCAL int server_num, process_num;
extern char *CONFIG_SOURCE_IP;
-#define VMWARE_VECTOR_CREATE(ref, type) zbx_vector_##type##_create_ext(ref, __vm_mem_malloc_func, \
- __vm_mem_realloc_func, __vm_mem_free_func)
+#define VMWARE_VECTOR_CREATE(ref, type) zbx_vector_##type##_create_ext(ref, __vm_shmem_malloc_func, \
+ __vm_shmem_realloc_func, __vm_shmem_free_func)
#define ZBX_VMWARE_CACHE_UPDATE_PERIOD CONFIG_VMWARE_FREQUENCY
#define ZBX_VMWARE_PERF_UPDATE_PERIOD CONFIG_VMWARE_PERF_FREQUENCY
@@ -83,9 +83,9 @@ extern char *CONFIG_SOURCE_IP;
static zbx_mutex_t vmware_lock = ZBX_MUTEX_NULL;
-static zbx_mem_info_t *vmware_mem = NULL;
+static zbx_shmem_info_t *vmware_mem = NULL;
-ZBX_MEM_FUNC_IMPL(__vm, vmware_mem)
+ZBX_SHMEM_FUNC_IMPL(__vm, vmware_mem)
static zbx_vmware_t *vmware = NULL;
@@ -506,7 +506,7 @@ static char *vmware_shared_strdup(const char *str)
strdup = vmware_strpool_strdup(str, &vmware->strpool, &len);
if (0 < len)
- vmware->strpool_sz += zbx_mem_required_chunk_size(len);
+ vmware->strpool_sz += zbx_shmem_required_chunk_size(len);
return strdup;
}
@@ -537,7 +537,7 @@ static void vmware_shared_strfree(char *str)
vmware_strpool_strfree(str, &vmware->strpool, &len);
if (0 < len)
- vmware->strpool_sz -= zbx_mem_required_chunk_size(len);
+ vmware->strpool_sz -= zbx_shmem_required_chunk_size(len);
}
static void evt_msg_strpool_strfree(char *str)
@@ -898,7 +898,7 @@ static void vmware_perf_counter_shared_free(zbx_vmware_perf_counter_t *counter)
{
vmware_vector_str_uint64_pair_shared_clean(&counter->values);
zbx_vector_str_uint64_pair_destroy(&counter->values);
- __vm_mem_free_func(counter);
+ __vm_shmem_free_func(counter);
}
/******************************************************************************
@@ -940,7 +940,7 @@ static void vmware_diskextent_shared_free(zbx_vmware_diskextent_t *diskextent)
{
vmware_shared_strfree(diskextent->diskname);
- __vm_mem_free_func(diskextent);
+ __vm_shmem_free_func(diskextent);
}
/******************************************************************************
@@ -964,7 +964,7 @@ static void vmware_datastore_shared_free(zbx_vmware_datastore_t *datastore)
zbx_vector_vmware_diskextent_clear_ext(&datastore->diskextents, vmware_diskextent_shared_free);
zbx_vector_vmware_diskextent_destroy(&datastore->diskextents);
- __vm_mem_free_func(datastore);
+ __vm_shmem_free_func(datastore);
}
/******************************************************************************
@@ -979,7 +979,7 @@ static void vmware_datacenter_shared_free(zbx_vmware_datacenter_t *datacenter)
vmware_shared_strfree(datacenter->name);
vmware_shared_strfree(datacenter->id);
- __vm_mem_free_func(datacenter);
+ __vm_shmem_free_func(datacenter);
}
/******************************************************************************
@@ -1003,7 +1003,7 @@ static void vmware_props_shared_free(char **props, int props_num)
vmware_shared_strfree(props[i]);
}
- __vm_mem_free_func(props);
+ __vm_shmem_free_func(props);
}
/******************************************************************************
@@ -1021,7 +1021,7 @@ static void vmware_dev_shared_free(zbx_vmware_dev_t *dev)
if (NULL != dev->label)
vmware_shared_strfree(dev->label);
- __vm_mem_free_func(dev);
+ __vm_shmem_free_func(dev);
}
/******************************************************************************
@@ -1036,7 +1036,7 @@ static void vmware_fs_shared_free(zbx_vmware_fs_t *fs)
if (NULL != fs->path)
vmware_shared_strfree(fs->path);
- __vm_mem_free_func(fs);
+ __vm_shmem_free_func(fs);
}
/******************************************************************************
@@ -1062,7 +1062,7 @@ static void vmware_vm_shared_free(zbx_vmware_vm_t *vm)
vmware_props_shared_free(vm->props, ZBX_VMWARE_VMPROPS_NUM);
- __vm_mem_free_func(vm);
+ __vm_shmem_free_func(vm);
}
/******************************************************************************
@@ -1077,7 +1077,7 @@ static void vmware_dsname_shared_free(zbx_vmware_dsname_t *dsname)
vmware_shared_strfree(dsname->name);
zbx_vector_vmware_hvdisk_destroy(&dsname->hvdisks);
- __vm_mem_free_func(dsname);
+ __vm_shmem_free_func(dsname);
}
/******************************************************************************
@@ -1137,7 +1137,7 @@ static void vmware_cluster_shared_free(zbx_vmware_cluster_t *cluster)
if (NULL != cluster->status)
vmware_shared_strfree(cluster->status);
- __vm_mem_free_func(cluster);
+ __vm_shmem_free_func(cluster);
}
/******************************************************************************
@@ -1152,7 +1152,7 @@ static void vmware_event_shared_free(zbx_vmware_event_t *event)
if (NULL != event->message)
vmware_shared_strfree(event->message);
- __vm_mem_free_func(event);
+ __vm_shmem_free_func(event);
}
/******************************************************************************
@@ -1191,7 +1191,7 @@ static void vmware_data_shared_free(zbx_vmware_data_t *data)
if (NULL != data->error)
vmware_shared_strfree(data->error);
- __vm_mem_free_func(data);
+ __vm_shmem_free_func(data);
}
}
@@ -1265,7 +1265,7 @@ static void vmware_service_shared_free(zbx_vmware_service_t *service)
zbx_hashset_destroy(&service->counters);
- __vm_mem_free_func(service);
+ __vm_shmem_free_func(service);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
}
@@ -1283,7 +1283,7 @@ static zbx_vmware_cluster_t *vmware_cluster_shared_dup(const zbx_vmware_cluster_
{
zbx_vmware_cluster_t *cluster;
- cluster = (zbx_vmware_cluster_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_cluster_t));
+ cluster = (zbx_vmware_cluster_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_cluster_t));
cluster->id = vmware_shared_strdup(src->id);
cluster->name = vmware_shared_strdup(src->name);
cluster->status = vmware_shared_strdup(src->status);
@@ -1304,7 +1304,7 @@ static zbx_vmware_event_t *vmware_event_shared_dup(const zbx_vmware_event_t *src
{
zbx_vmware_event_t *event;
- event = (zbx_vmware_event_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_event_t));
+ event = (zbx_vmware_event_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_event_t));
event->key = src->key;
event->message = vmware_shared_strdup(src->message);
event->timestamp = src->timestamp;
@@ -1325,7 +1325,7 @@ static zbx_vmware_diskextent_t *vmware_diskextent_shared_dup(const zbx_vmware_di
{
zbx_vmware_diskextent_t *diskextent;
- diskextent = (zbx_vmware_diskextent_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_diskextent_t));
+ diskextent = (zbx_vmware_diskextent_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_diskextent_t));
diskextent->diskname = vmware_shared_strdup(src->diskname);
diskextent->partitionid = src->partitionid;
@@ -1346,7 +1346,7 @@ static zbx_vmware_datastore_t *vmware_datastore_shared_dup(const zbx_vmware_data
int i;
zbx_vmware_datastore_t *datastore;
- datastore = (zbx_vmware_datastore_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_datastore_t));
+ datastore = (zbx_vmware_datastore_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_datastore_t));
datastore->uuid = vmware_shared_strdup(src->uuid);
datastore->name = vmware_shared_strdup(src->name);
datastore->id = vmware_shared_strdup(src->id);
@@ -1390,7 +1390,7 @@ static zbx_vmware_datacenter_t *vmware_datacenter_shared_dup(const zbx_vmware_da
{
zbx_vmware_datacenter_t *datacenter;
- datacenter = (zbx_vmware_datacenter_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_datacenter_t));
+ datacenter = (zbx_vmware_datacenter_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_datacenter_t));
datacenter->name = vmware_shared_strdup(src->name);
datacenter->id = vmware_shared_strdup(src->id);
@@ -1410,7 +1410,7 @@ static zbx_vmware_dev_t *vmware_dev_shared_dup(const zbx_vmware_dev_t *src)
{
zbx_vmware_dev_t *dev;
- dev = (zbx_vmware_dev_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_dev_t));
+ dev = (zbx_vmware_dev_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_dev_t));
dev->type = src->type;
dev->instance = vmware_shared_strdup(src->instance);
dev->label = vmware_shared_strdup(src->label);
@@ -1432,7 +1432,7 @@ static zbx_vmware_fs_t *vmware_fs_shared_dup(const zbx_vmware_fs_t *src)
{
zbx_vmware_fs_t *fs;
- fs = (zbx_vmware_fs_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_fs_t));
+ fs = (zbx_vmware_fs_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_fs_t));
fs->path = vmware_shared_strdup(src->path);
fs->capacity = src->capacity;
fs->free_space = src->free_space;
@@ -1455,7 +1455,7 @@ static char **vmware_props_shared_dup(char ** const src, int props_num)
char **props;
int i;
- props = (char **)__vm_mem_malloc_func(NULL, sizeof(char *) * props_num);
+ props = (char **)__vm_shmem_malloc_func(NULL, sizeof(char *) * props_num);
for (i = 0; i < props_num; i++)
props[i] = vmware_shared_strdup(src[i]);
@@ -1477,7 +1477,7 @@ static zbx_vmware_vm_t *vmware_vm_shared_dup(const zbx_vmware_vm_t *src)
zbx_vmware_vm_t *vm;
int i;
- vm = (zbx_vmware_vm_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_vm_t));
+ vm = (zbx_vmware_vm_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_vm_t));
VMWARE_VECTOR_CREATE(&vm->devs, ptr);
VMWARE_VECTOR_CREATE(&vm->file_systems, ptr);
@@ -1511,7 +1511,7 @@ static zbx_vmware_dsname_t *vmware_dsname_shared_dup(const zbx_vmware_dsname_t *
zbx_vmware_dsname_t *dsname;
int i;
- dsname = (zbx_vmware_dsname_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_dsname_t));
+ dsname = (zbx_vmware_dsname_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_dsname_t));
dsname->name = vmware_shared_strdup(src->name);
@@ -1576,9 +1576,9 @@ static zbx_vmware_data_t *vmware_data_shared_dup(zbx_vmware_data_t *src)
zbx_hashset_iter_t iter;
zbx_vmware_hv_t *hv, hv_local;
- data = (zbx_vmware_data_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_data_t));
- zbx_hashset_create_ext(&data->hvs, 1, vmware_hv_hash, vmware_hv_compare, NULL, __vm_mem_malloc_func,
- __vm_mem_realloc_func, __vm_mem_free_func);
+ data = (zbx_vmware_data_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_data_t));
+ zbx_hashset_create_ext(&data->hvs, 1, vmware_hv_hash, vmware_hv_compare, NULL, __vm_shmem_malloc_func,
+ __vm_shmem_realloc_func, __vm_shmem_free_func);
VMWARE_VECTOR_CREATE(&data->clusters, ptr);
VMWARE_VECTOR_CREATE(&data->events, ptr);
VMWARE_VECTOR_CREATE(&data->datastores, vmware_datastore);
@@ -1588,8 +1588,8 @@ static zbx_vmware_data_t *vmware_data_shared_dup(zbx_vmware_data_t *src)
zbx_vector_vmware_datastore_reserve(&data->datastores, src->datastores.values_num);
zbx_vector_vmware_datacenter_reserve(&data->datacenters, src->datacenters.values_num);
- zbx_hashset_create_ext(&data->vms_index, 100, vmware_vm_hash, vmware_vm_compare, NULL, __vm_mem_malloc_func,
- __vm_mem_realloc_func, __vm_mem_free_func);
+ zbx_hashset_create_ext(&data->vms_index, 100, vmware_vm_hash, vmware_vm_compare, NULL, __vm_shmem_malloc_func,
+ __vm_shmem_realloc_func, __vm_shmem_free_func);
data->error = vmware_shared_strdup(src->error);
@@ -4500,7 +4500,7 @@ static int vmware_service_put_event_data(zbx_vector_ptr_t *events, zbx_id_xmlnod
zbx_vector_ptr_append(events, event);
if (0 < sz)
- *alloc_sz += zbx_mem_required_chunk_size(sz);
+ *alloc_sz += zbx_shmem_required_chunk_size(sz);
return SUCCEED;
}
@@ -5244,12 +5244,12 @@ static void vmware_counters_add_new(zbx_vector_ptr_t *counters, zbx_uint64_t cou
{
zbx_vmware_perf_counter_t *counter;
- counter = (zbx_vmware_perf_counter_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_perf_counter_t));
+ counter = (zbx_vmware_perf_counter_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_perf_counter_t));
counter->counterid = counterid;
counter->state = ZBX_VMWARE_COUNTER_NEW;
- zbx_vector_str_uint64_pair_create_ext(&counter->values, __vm_mem_malloc_func, __vm_mem_realloc_func,
- __vm_mem_free_func);
+ zbx_vector_str_uint64_pair_create_ext(&counter->values, __vm_shmem_malloc_func, __vm_shmem_realloc_func,
+ __vm_shmem_free_func);
zbx_vector_ptr_append(counters, counter);
}
@@ -5387,8 +5387,8 @@ static void vmware_service_add_perf_entity(zbx_vmware_service_t *service, const
pentity = (zbx_vmware_perf_entity_t *)zbx_hashset_insert(&service->entities, &entity, sizeof(zbx_vmware_perf_entity_t));
- zbx_vector_ptr_create_ext(&pentity->counters, __vm_mem_malloc_func, __vm_mem_realloc_func,
- __vm_mem_free_func);
+ zbx_vector_ptr_create_ext(&pentity->counters, __vm_shmem_malloc_func, __vm_shmem_realloc_func,
+ __vm_shmem_free_func);
for (i = 0; NULL != counters[i]; i++)
{
@@ -5700,7 +5700,7 @@ out:
service->eventlog.oom = 0;
events_sz += evt_req_chunk_size * data->events.values_num +
- zbx_mem_required_chunk_size(data->events.values_alloc * sizeof(zbx_vmware_event_t*));
+ zbx_shmem_required_chunk_size(data->events.values_alloc * sizeof(zbx_vmware_event_t*));
if (0 == service->eventlog.last_key || vmware_mem->free_size < events_sz ||
SUCCEED == ZBX_CHECK_LOG_LEVEL(LOG_LEVEL_DEBUG))
@@ -5711,7 +5711,7 @@ out:
if (SUCCEED == vmware_shared_strsearch(event->message))
{
- events_sz -= zbx_mem_required_chunk_size(strlen(event->message) +
+ events_sz -= zbx_shmem_required_chunk_size(strlen(event->message) +
REFCOUNT_FIELD_SIZE + 1 + ZBX_HASHSET_ENTRY_OFFSET);
}
}
@@ -5767,7 +5767,7 @@ out:
vmware_service_update_perf_entities(service);
if (SUCCEED == ZBX_CHECK_LOG_LEVEL(LOG_LEVEL_DEBUG))
- zbx_mem_dump_stats(LOG_LEVEL_DEBUG, vmware_mem);
+ zbx_shmem_dump_stats(LOG_LEVEL_DEBUG, vmware_mem);
zbx_snprintf(msg, sizeof(msg), "Events:%d DC:%d DS:%d CL:%d HV:%d VM:%d"
" VMwareCache memory usage (free/strpool/total): " ZBX_FS_UI64 " / " ZBX_FS_UI64 " / "
@@ -6387,7 +6387,7 @@ zbx_vmware_service_t *zbx_vmware_get_service(const char* url, const char* userna
}
}
- service = (zbx_vmware_service_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_service_t));
+ service = (zbx_vmware_service_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_service_t));
memset(service, 0, sizeof(zbx_vmware_service_t));
service->url = vmware_shared_strdup(url);
@@ -6402,11 +6402,11 @@ zbx_vmware_service_t *zbx_vmware_get_service(const char* url, const char* userna
service->eventlog.oom = 0;
zbx_hashset_create_ext(&service->entities, 100, vmware_perf_entity_hash_func, vmware_perf_entity_compare_func,
- NULL, __vm_mem_malloc_func, __vm_mem_realloc_func, __vm_mem_free_func);
+ NULL, __vm_shmem_malloc_func, __vm_shmem_realloc_func, __vm_shmem_free_func);
zbx_hashset_create_ext(&service->counters, ZBX_VMWARE_COUNTERS_INIT_SIZE, vmware_counter_hash_func,
- vmware_counter_compare_func, NULL, __vm_mem_malloc_func, __vm_mem_realloc_func,
- __vm_mem_free_func);
+ vmware_counter_compare_func, NULL, __vm_shmem_malloc_func, __vm_shmem_realloc_func,
+ __vm_shmem_free_func);
zbx_vector_ptr_append(&vmware->services, service);
@@ -6493,8 +6493,8 @@ int zbx_vmware_service_add_perf_counter(zbx_vmware_service_t *service, const cha
entity.type = vmware_shared_strdup(type);
entity.id = vmware_shared_strdup(id);
entity.error = NULL;
- zbx_vector_ptr_create_ext(&entity.counters, __vm_mem_malloc_func, __vm_mem_realloc_func,
- __vm_mem_free_func);
+ zbx_vector_ptr_create_ext(&entity.counters, __vm_shmem_malloc_func, __vm_shmem_realloc_func,
+ __vm_shmem_free_func);
pentity = (zbx_vmware_perf_entity_t *)zbx_hashset_insert(&service->entities, &entity,
sizeof(zbx_vmware_perf_entity_t));
@@ -6556,26 +6556,26 @@ int zbx_vmware_init(char **error)
if (SUCCEED != zbx_mutex_create(&vmware_lock, ZBX_MUTEX_VMWARE, error))
goto out;
- size_reserved = zbx_mem_required_size(1, "vmware cache size", "VMwareCacheSize");
+ size_reserved = zbx_shmem_required_size(1, "vmware cache size", "VMwareCacheSize");
CONFIG_VMWARE_CACHE_SIZE -= size_reserved;
- if (SUCCEED != zbx_mem_create(&vmware_mem, CONFIG_VMWARE_CACHE_SIZE, "vmware cache size", "VMwareCacheSize", 0,
- error))
+ if (SUCCEED != zbx_shmem_create(&vmware_mem, CONFIG_VMWARE_CACHE_SIZE, "vmware cache size", "VMwareCacheSize",
+ 0, error))
{
goto out;
}
- vmware = (zbx_vmware_t *)__vm_mem_malloc_func(NULL, sizeof(zbx_vmware_t));
+ vmware = (zbx_vmware_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_t));
memset(vmware, 0, sizeof(zbx_vmware_t));
VMWARE_VECTOR_CREATE(&vmware->services, ptr);
#if defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL)
vmware->strpool_sz = 0;
zbx_hashset_create_ext(&vmware->strpool, 100, vmware_strpool_hash_func, vmware_strpool_compare_func, NULL,
- __vm_mem_malloc_func, __vm_mem_realloc_func, __vm_mem_free_func);
+ __vm_shmem_malloc_func, __vm_shmem_realloc_func, __vm_shmem_free_func);
zbx_hashset_create(&evt_msg_strpool, 100, vmware_strpool_hash_func, vmware_strpool_compare_func);
- evt_req_chunk_size = zbx_mem_required_chunk_size(sizeof(zbx_vmware_event_t));
+ evt_req_chunk_size = zbx_shmem_required_chunk_size(sizeof(zbx_vmware_event_t));
#endif
ret = SUCCEED;
out:
@@ -6598,7 +6598,7 @@ void zbx_vmware_destroy(void)
zbx_hashset_destroy(&vmware->strpool);
zbx_hashset_destroy(&evt_msg_strpool);
#endif
- zbx_mem_destroy(vmware_mem);
+ zbx_shmem_destroy(vmware_mem);
vmware_mem = NULL;
zbx_mutex_destroy(&vmware_lock);
}