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
diff options
context:
space:
mode:
authorVladislavs Sokurenko <vladislavs.sokurenko@zabbix.com>2020-04-22 18:18:37 +0300
committerVladislavs Sokurenko <vladislavs.sokurenko@zabbix.com>2020-04-22 18:18:37 +0300
commite8b607ec2b88f7fe55b2382a76bdfe2feef974d6 (patch)
tree14fee3d9040fa77bdc210967d69c86955a75a7c7
parent7b096e42f53721ed31910dbddab5740e34783816 (diff)
........S. [ZBXNEXT-5877] replaced gettimeofday() to existing function zbx_timespec()
-rw-r--r--include/common.h2
-rw-r--r--src/libs/zbxcommon/misc.c14
-rw-r--r--src/libs/zbxembed/embed.c6
-rw-r--r--src/libs/zbxembed/embed.h2
-rw-r--r--src/libs/zbxembed/zabbix.c2
-rw-r--r--src/zabbix_server/alerter/alerter.c8
6 files changed, 19 insertions, 15 deletions
diff --git a/include/common.h b/include/common.h
index acc5431dc70..bc07f736320 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1089,7 +1089,7 @@ void zbx_get_time(struct tm *tm, long *milliseconds, zbx_timezone_t *tz);
long zbx_get_timezone_offset(time_t t, struct tm *tm);
int zbx_utc_time(int year, int mon, int mday, int hour, int min, int sec, int *t);
int zbx_day_in_month(int year, int mon);
-zbx_uint64_t zbx_get_duration(struct timeval start_time);
+zbx_uint64_t zbx_get_duration_ms(const zbx_timespec_t *ts);
void zbx_error(const char *fmt, ...) __zbx_attr_format_printf(1, 2);
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index f6678cd2717..1fd9e6db0ac 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -487,23 +487,23 @@ int zbx_day_in_month(int year, int mon)
/******************************************************************************
* *
- * Function: zbx_get_duration *
+ * Function: zbx_get_duration_ms *
* *
- * Purpose: get duration in milliseconds since start_time till current time *
+ * Purpose: get duration in milliseconds since time stamp till current time *
* *
* Parameters: *
* start_time - [IN] time from when duration should be counted *
* *
- * Return value: duration in milliseconds since start_time till current time *
+ * Return value: duration in milliseconds since time stamp till current time *
* *
******************************************************************************/
-zbx_uint64_t zbx_get_duration(struct timeval start_time)
+zbx_uint64_t zbx_get_duration_ms(const zbx_timespec_t *ts)
{
- struct timeval current_time;
+ zbx_timespec_t now;
- gettimeofday(&current_time, NULL);
+ zbx_timespec(&now);
- return (current_time.tv_sec - start_time.tv_sec) * 1000 + (current_time.tv_usec - start_time.tv_usec) / 1000;
+ return (now.sec - ts->sec) * 1e3 + (now.ns - ts->ns) / 1e6;
}
/******************************************************************************
diff --git a/src/libs/zbxembed/embed.c b/src/libs/zbxembed/embed.c
index 69bba299a47..3aa4bfb9e76 100644
--- a/src/libs/zbxembed/embed.c
+++ b/src/libs/zbxembed/embed.c
@@ -133,7 +133,7 @@ int zbx_es_check_timeout(void *udata)
{
zbx_es_env_t *env = (zbx_es_env_t *)udata;
- if (time(NULL) - env->start_time.tv_sec > env->timeout)
+ if (time(NULL) - env->start_time.sec > env->timeout)
return 1;
return 0;
@@ -435,7 +435,7 @@ int zbx_es_execute(zbx_es_t *es, const char *script, const char *code, int size,
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
- gettimeofday(&es->env->start_time, NULL);
+ zbx_timespec(&es->env->start_time);
if (NULL != es->env->json)
{
@@ -506,7 +506,7 @@ out:
if (NULL != es->env->json)
{
zbx_json_close(es->env->json);
- zbx_json_adduint64(es->env->json, "ms", zbx_get_duration(es->env->start_time));
+ zbx_json_adduint64(es->env->json, "ms", zbx_get_duration_ms(&es->env->start_time));
}
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s %s", __func__, zbx_result_string(ret), ZBX_NULL2EMPTY_STR(*error));
diff --git a/src/libs/zbxembed/embed.h b/src/libs/zbxembed/embed.h
index 9a5423d6d45..78020d2fd2e 100644
--- a/src/libs/zbxembed/embed.h
+++ b/src/libs/zbxembed/embed.h
@@ -27,7 +27,7 @@ struct zbx_es_env
{
duk_context *ctx;
size_t total_alloc;
- struct timeval start_time;
+ zbx_timespec_t start_time;
char *error;
int rt_error_num;
diff --git a/src/libs/zbxembed/zabbix.c b/src/libs/zbxembed/zabbix.c
index 90a058ca874..61a6ba302d9 100644
--- a/src/libs/zbxembed/zabbix.c
+++ b/src/libs/zbxembed/zabbix.c
@@ -86,7 +86,7 @@ static duk_ret_t es_zabbix_log(duk_context *ctx)
zbx_json_addobject(env->json, NULL);
zbx_json_adduint64(env->json, "level", (zbx_uint64_t)level);
- zbx_json_adduint64(env->json, "ms", zbx_get_duration(env->start_time));
+ zbx_json_adduint64(env->json, "ms", zbx_get_duration_ms(&env->start_time));
zbx_json_addstring(env->json, "message", message, ZBX_JSON_TYPE_STRING);
zbx_json_close(env->json);
diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c
index fc78a107f86..c11df0e9f8c 100644
--- a/src/zabbix_server/alerter/alerter.c
+++ b/src/zabbix_server/alerter/alerter.c
@@ -226,7 +226,9 @@ static void alerter_process_webhook(zbx_ipc_socket_t *socket, zbx_ipc_message_t
if (ZBX_IPC_ALERTER_WEBHOOK_EXTERNAL == ipc_message->code)
{
zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN);
- zbx_es_set_debug(&es_engine, &json);
+
+ if (SUCCEED == zbx_es_is_env_initialized(&es_engine))
+ zbx_es_set_debug(&es_engine, &json);
}
if (SUCCEED == ret)
@@ -251,7 +253,9 @@ static void alerter_process_webhook(zbx_ipc_socket_t *socket, zbx_ipc_message_t
{
alerter_send_result(socket, output, ret, error, json.buffer);
zbx_json_free(&json);
- zbx_es_set_debug(&es_engine, NULL);
+
+ if (SUCCEED == zbx_es_is_env_initialized(&es_engine))
+ zbx_es_set_debug(&es_engine, NULL);
}
else
alerter_send_result(socket, output, ret, error, NULL);