Compare commits

...
58 Commits
Author SHA1 Message Date
fengzeroz 0d1794ac24 Merge pull request #1292 from fengzeroz/v2.3
version: 2.3.13
2023-05-26 18:07:18 +08:00
fengzero 67fcdaf693 version: 2.3.13 2023-05-26 10:06:52 +00:00
fengzeroz 50ccd73f67 Merge pull request #1232 from fengzeroz/v2.3
version: 2.3.12
2023-04-28 13:55:28 +08:00
fengzero 021dfffa61 version: 2.3.12 2023-04-28 05:53:49 +00:00
fengzeroz 9bf0bba2ab Merge pull request #1231 from lixiumei123/v2.3
fix(file plugin):fix delay
2023-04-28 13:52:13 +08:00
liyuxi e4d1aea07b fix(file plugin):fix delay 2023-04-28 02:59:34 +00:00
fengzeroz e70417689d Merge pull request #1187 from eeff/eeff/2.3
Pick to 2.3: data race when close mqtt client
2023-04-13 14:19:11 +08:00
eeff 9bf3b580d7 fix: data race when close mqtt client 2023-04-12 17:44:42 +08:00
fengzeroz 0adb022042 Merge pull request #1169 from gc87/spb-float-fix-v2.3
[v2.3]fix: determined f32 type data is treated as d64
2023-04-07 09:59:19 +08:00
gc87 b52e394fa1 fix: determined f32 type data is treated as d64 2023-04-06 18:39:34 +08:00
fengzeroz 90a1eae13f Merge pull request #1148 from fengzeroz/v2.3
version: 2.3.11
2023-03-31 14:34:01 +08:00
fengzero a64449bc8a version: 2.3.11 2023-03-31 06:33:26 +00:00
fengzeroz a0ee5346f9 Merge pull request #1146 from fengzeroz/v2.3
fix: check tar result
2023-03-31 14:31:57 +08:00
fengzero 8d166fb159 fix: check tar result 2023-03-31 06:21:05 +00:00
fengzeroz 191e69ec3e Update ci.yml 2023-03-24 17:11:21 +08:00
fengzeroz 6af32bd9fc Merge pull request #1141 from fengzeroz/v2.3
chore(log): log result of rm tar
2023-03-24 16:26:57 +08:00
fengzero 13becdd6af chore(log): log result of rm tar 2023-03-24 08:24:49 +00:00
fengzeroz 5c2ed5f1a3 Merge pull request #1139 from fengzeroz/v2.3
version: 2.3.10
2023-03-24 15:44:48 +08:00
fengzero a0bb29c100 version: 2.3.10 2023-03-24 07:44:08 +00:00
fengzeroz fb6e92665a Merge pull request #1129 from fengzeroz/v2.3
version: 2.3.9
2023-03-17 17:07:28 +08:00
fengzero d7929b5553 version: 2.3.9 2023-03-17 09:05:54 +00:00
fengzeroz a11d622fa6 Merge pull request #1128 from fengzeroz/v2.3
chore(persist): get persist db
2023-03-17 17:04:36 +08:00
fengzero c3ed9cc69d chore(persist): get persist db 2023-03-17 09:02:09 +00:00
fengzeroz 54dfc3709e Merge pull request #1126 from eeff/eeff/2.3
Pick to v2.3: move persister to neuron base
2023-03-17 15:45:22 +08:00
eeff 253f254bd3 feat: move persister to neuron base 2023-03-17 15:17:16 +08:00
eeff 214c82b508 feat: remove persister dependency on g_config_dir 2023-03-17 15:17:16 +08:00
fengzeroz fdfc819c25 Merge pull request #1114 from fengzeroz/v2.3
fix(log): format
2023-03-14 15:43:23 +08:00
fengzero 2ba608f9fe fix(log): format 2023-03-14 07:42:40 +00:00
fengzeroz 89069da064 Merge pull request #1113 from fengzeroz/v2.3
fix(api): compile fail
2023-03-14 15:36:28 +08:00
fengzero aec03ecaf9 fix(api): compile fail 2023-03-14 07:36:00 +00:00
fengzeroz 40fdc17b57 Merge pull request #1112 from fengzeroz/v2.3
fix(api): check return value of system
2023-03-14 15:31:26 +08:00
fengzero dda1007c50 fix(api): check return value of system 2023-03-14 07:30:58 +00:00
fengzeroz da4295aec9 Merge pull request #1110 from fengzeroz/v2.3
fix(main): manager destroy when recv SIGINT or SIGTERM
2023-03-14 13:54:07 +08:00
fengzero cfb3d073c5 fix(main): manager destroy when recv SIGINT or SIGTERM 2023-03-14 05:48:53 +00:00
fengzeroz cc86ffd497 Merge pull request #1105 from fengzeroz/v2.3
version: 2.3.8
2023-03-10 10:26:29 +08:00
fengzero f32188e3c1 version: 2.3.8 2023-03-10 02:25:44 +00:00
fengzeroz 93af6bfe76 Merge pull request #1104 from fengzeroz/v2.3
fix(event): handle EINTR
2023-03-10 10:23:31 +08:00
fengzero 5c543e0077 fix(event): handle EINTR 2023-03-10 02:17:54 +00:00
fengzeroz f6c591e951 Merge pull request #1101 from lixiumei123/v2.3
fix download log file
2023-03-08 14:47:09 +08:00
liyuxi eb332bd745 fix download log file 2023-03-08 05:55:03 +00:00
fengzeroz d026d1f754 Merge pull request #1096 from fengzeroz/v2.3
chore(main): handle SIGSEGV signal
2023-03-07 13:24:43 +08:00
fengzero fd6c3aca96 chore(main): handle SIGSEGV signal 2023-03-07 05:20:55 +00:00
fengzeroz faee3ab68c Merge pull request #1093 from fengzeroz/v2.3
fix(connection): disconnect if recv return 0
2023-03-07 11:42:14 +08:00
fengzero 68587420e0 fix(connection): disconnect if recv return 0 2023-03-07 03:23:30 +00:00
fengzeroz af5195cfb9 Merge pull request #1070 from fengzeroz/v2.3
version: 2.3.7
2023-02-16 17:56:47 +08:00
fengzero 157dd2521a version: 2.3.7 2023-02-16 09:56:03 +00:00
fengzeroz a84aff8f3e Merge pull request #1064 from fengzeroz/v2.3
version: 2.3.6
2023-02-10 14:33:55 +08:00
fengzero 08a132b2f9 version: 2.3.6 2023-02-10 06:33:16 +00:00
fengzeroz bc48b324dd Merge pull request #1050 from fengzeroz/v2.3
version: 2.3.5
2023-02-03 15:58:40 +08:00
fengzeroz b46a319b26 Merge pull request #1049 from lixiumei123/v2.3
fix download log coredump
2023-02-03 15:53:29 +08:00
fengzero 3fb6b3409a version: 2.3.5 2023-02-03 07:52:40 +00:00
liyuxi 5d195d5cb1 fix download log coredump 2023-02-02 06:49:49 +00:00
fengzeroz 9833af02da Merge pull request #1039 from fengzeroz/v2.3
fix(connection): tcp server accept assert
2023-01-30 10:42:50 +08:00
fengzero 5d2cff0aef fix(connection): tcp server accept assert 2023-01-30 02:26:25 +00:00
fengzeroz 4be97991fe Merge pull request #1034 from fengzeroz/v2.3
plugin: file
2023-01-16 15:24:38 +08:00
fengzero 943cc82caa plugin: file 2023-01-16 07:24:03 +00:00
fengzeroz e0d932e2e3 Merge pull request #1032 from fengzeroz/v2.3
type: string limit 512byte
2023-01-16 14:53:41 +08:00
fengzero e7fc946ae6 type: string limit 512byte 2023-01-16 06:39:47 +00:00
23 changed files with 468 additions and 178 deletions
+4 -4
View File
@@ -8,8 +8,8 @@ on:
- published
env:
VERSION: 2.3.4
UI_VERSION: 2.3.2
VERSION: 2.3.13
UI_VERSION: 2.3.9
BRANCH: v2.3
jobs:
@@ -96,7 +96,7 @@ jobs:
steps:
- name: delete old daily-pre-release
uses: dev-drprasad/delete-tag-and-release@v0.2.0
uses: dev-drprasad/delete-tag-and-release@v0.2.1
with:
delete_release: true
tag_name: ${{ env.BRANCH }}-daily
@@ -258,4 +258,4 @@ jobs:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ steps.package.outputs.name}}
asset_name: ${{ matrix.type }}-${{ env.VERSION }}-linux-${{ matrix.arch }}.${{ matrix.package }}
asset_content_type: application/octet-stream
asset_content_type: application/octet-stream
+8 -6
View File
@@ -59,6 +59,9 @@ else()
link_directories(/usr/local/lib)
endif()
set(PERSIST_SOURCES
src/persist/persist.c
src/persist/json/persist_json_plugin.c)
aux_source_directory(src/parser NEURON_SRC_PARSE)
set(NEURON_BASE_SOURCES
src/base/tag.c
@@ -74,7 +77,8 @@ set(NEURON_BASE_SOURCES
src/utils/neu_jwt.c
src/utils/base64.c
src/utils/async_queue.c
src/utils/mem_cache.c)
src/utils/mem_cache.c
${PERSIST_SOURCES})
add_library(neuron-base SHARED)
target_sources(neuron-base PRIVATE ${NEURON_BASE_SOURCES} ${NEURON_SRC_PARSE})
@@ -89,9 +93,6 @@ add_dependencies(neuron-base neuron-version)
#find_package(MbedTLS)
target_link_libraries(neuron-base mbedtls mbedx509 mbedcrypto)
set(PERSIST_SOURCES
src/persist/persist.c
src/persist/json/persist_json_plugin.c)
set(NEURON_SOURCES
src/main.c
src/argparse.c
@@ -123,8 +124,7 @@ set(NEURON_SOURCES
plugins/restful/proxy.c
plugins/restful/websocket.c
plugins/monitor/monitor.c
plugins/monitor/metric_handle.c
${PERSIST_SOURCES})
plugins/monitor/metric_handle.c)
set(CMAKE_BUILD_RPATH ./)
add_executable(neuron)
@@ -147,6 +147,8 @@ file(COPY ${CMAKE_SOURCE_DIR}/default_plugins.json DESTINATION ${CMAKE_BINARY_DI
add_subdirectory(plugins/modbus)
add_subdirectory(plugins/mqtt)
add_subdirectory(plugins/ekuiper)
add_subdirectory(plugins/file)
add_subdirectory(simulator)
+3
View File
@@ -106,6 +106,9 @@ typedef enum {
NEU_ERR_PLUGIN_TAG_NOT_READY = 3011,
NEU_ERR_PLUGIN_PACKET_OUT_OF_ORDER = 3012,
NEU_ERR_FILE_OPEN_FAILURE = 4101,
NEU_ERR_FILE_READ_FAILURE = 4102,
NEU_ERR_MQTT_FAILURE = 4000,
NEU_ERR_MQTT_NO_CERTFILESET = 4001,
NEU_ERR_MQTT_CERTFILE_LOAD_FAILURE = 4002,
@@ -24,7 +24,9 @@
extern "C" {
#endif
#include "adapter/adapter_info.h"
#include <sqlite3.h>
#include "adapter_info.h"
#include "persist/json/persist_json_plugin.h"
typedef neu_json_plugin_req_plugin_t neu_persist_plugin_info_t;
@@ -84,12 +86,14 @@ static inline void neu_persist_user_info_fini(neu_persist_user_info_t *info)
* Create persister.
* @return 0 on success, -1 otherwise.
*/
int neu_persister_create();
int neu_persister_create(const char *schema_dir);
/**
* Destroy perister.
*/
void neu_persister_destroy();
sqlite3 *neu_persister_get_db();
/**
* Persist nodes.
* @param node_info neu_persist_node_info_t.
@@ -306,4 +310,4 @@ int neu_persister_delete_user(const char *user_name);
}
#endif
#endif
#endif
+1 -1
View File
@@ -94,7 +94,7 @@ inline static const char *neu_type_string(neu_type_e type)
return "";
}
#define NEU_VALUE_SIZE 128
#define NEU_VALUE_SIZE 512
typedef union {
bool boolean;
int8_t i8;
+11
View File
@@ -0,0 +1,11 @@
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/plugins")
set(CMAKE_BUILD_RPATH ./)
file(COPY ${CMAKE_SOURCE_DIR}/plugins/file/file.json DESTINATION ${CMAKE_BINARY_DIR}/plugins/schema/)
set(PLUGIN_NAME plugin-file)
set(PLUGIN_SOURCES file_plugin.c file_req.c)
add_library(${PLUGIN_NAME} SHARED)
target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
target_link_libraries(${PLUGIN_NAME} neuron-base)
+18
View File
@@ -0,0 +1,18 @@
{
"tag_regex": [
{
"type": 13,
"regex": ""
}
],
"file_length": {
"name": "file_length",
"description": "",
"attribute": "required",
"type": "int",
"default": 512,
"valid": {
"min": 1
}
}
}
+155
View File
@@ -0,0 +1,155 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
**/
#include "file_req.h"
static neu_plugin_t *driver_open(void);
static int driver_close(neu_plugin_t *plugin);
static int driver_init(neu_plugin_t *plugin);
static int driver_uninit(neu_plugin_t *plugin);
static int driver_start(neu_plugin_t *plugin);
static int driver_stop(neu_plugin_t *plugin);
static int driver_config(neu_plugin_t *plugin, const char *config);
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
void *data);
static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group);
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag);
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
neu_value_u value);
static const neu_plugin_intf_funs_t plugin_intf_funs = {
.open = driver_open,
.close = driver_close,
.init = driver_init,
.uninit = driver_uninit,
.start = driver_start,
.stop = driver_stop,
.setting = driver_config,
.request = driver_request,
.driver.validate_tag = driver_validate_tag,
.driver.group_timer = driver_group_timer,
.driver.write_tag = driver_write,
};
const neu_plugin_module_t neu_plugin_module = {
.version = NEURON_PLUGIN_VER_1_0,
.module_name = "file",
.module_descr = "The plugin is used to read and write files.",
.module_descr_zh = "该插件用于读写文件。",
.intf_funs = &plugin_intf_funs,
.kind = NEU_PLUGIN_KIND_SYSTEM,
.type = NEU_NA_TYPE_DRIVER,
.display = true,
.single = false,
};
static neu_plugin_t *driver_open(void)
{
neu_plugin_t *plugin = calloc(1, sizeof(neu_plugin_t));
neu_plugin_common_init(&plugin->common);
return plugin;
}
static int driver_close(neu_plugin_t *plugin)
{
free(plugin);
return 0;
}
static int driver_init(neu_plugin_t *plugin)
{
plugin->events = neu_event_new();
plugin->common.link_state = NEU_NODE_LINK_STATE_CONNECTED;
return 0;
}
static int driver_uninit(neu_plugin_t *plugin)
{
neu_event_close(plugin->events);
plog_info(plugin, "node; file uininit ok");
return 0;
}
static int driver_start(neu_plugin_t *plugin)
{
(void) plugin;
return 0;
}
static int driver_stop(neu_plugin_t *plugin)
{
(void) plugin;
return 0;
}
static int driver_config(neu_plugin_t *plugin, const char *config)
{
char * err_param = NULL;
neu_json_elem_t file_length = { .name = "file_length", .t = NEU_JSON_INT };
int ret = neu_parse_param((char *) config, &err_param, 1, &file_length);
if (ret != 0) {
plog_warn(plugin, "config:%s, decode error: %s", config, err_param);
free(err_param);
return -1;
}
plugin->file_length = file_length.v.val_int;
return 0;
}
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
void *data)
{
(void) plugin;
(void) head;
(void) data;
return 0;
}
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag)
{
plog_debug(plugin, "validate tag success, name:%s, address:%s,type:%d ",
tag->name, tag->address, tag->type);
return 0;
}
static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
{
return file_group_timer(plugin, group);
}
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
neu_value_u value)
{
return file_write(plugin, req, tag, value);
}
+136
View File
@@ -0,0 +1,136 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
**/
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include "file_req.h"
struct file_group_data {
UT_array *tags;
char * group;
};
static void plugin_group_free(neu_plugin_group_t *pgp);
int file_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
{
neu_adapter_update_metric_cb_t update_metric =
plugin->common.adapter_callbacks->update_metric;
int64_t rtt = NEU_METRIC_LAST_RTT_MS_MAX;
struct file_group_data *gd = NULL;
int length = plugin->file_length;
if (group->user_data == NULL) {
gd = calloc(1, sizeof(struct file_group_data));
group->user_data = gd;
group->group_free = plugin_group_free;
utarray_new(gd->tags, &ut_ptr_icd);
gd->group = strdup(group->group_name);
}
utarray_foreach(group->tags, neu_datatag_t *, tag)
{
FILE * f = NULL;
struct stat st = { 0 };
char * buf = calloc(1, length);
neu_dvalue_t dvalue = { 0 };
if (stat(tag->address, &st) != 0) {
dvalue.type = NEU_TYPE_ERROR;
dvalue.value.i32 = NEU_ERR_FILE_NOT_EXIST;
goto dvalue_result;
}
if ((f = fopen(tag->address, "rb+")) == NULL) {
nlog_error("open file:%s", tag->address);
dvalue.type = NEU_TYPE_ERROR;
dvalue.value.i32 = NEU_ERR_PLUGIN_READ_FAILURE;
goto dvalue_result;
}
int ret = fread(buf, sizeof(char), length, f);
if (ret == 0) {
nlog_error("read file failed:%s", tag->address);
dvalue.type = NEU_TYPE_ERROR;
dvalue.value.i32 = NEU_ERR_PLUGIN_READ_FAILURE;
goto dvalue_result;
}
fseek(f, 0, SEEK_END);
int size = ftell(f);
if (size > length) {
dvalue.type = NEU_TYPE_ERROR;
dvalue.value.i32 = NEU_ERR_PLUGIN_READ_FAILURE;
goto dvalue_result;
}
dvalue.type = NEU_TYPE_STRING;
strncpy(dvalue.value.str, buf, strlen(buf));
fclose(f);
rtt = 1;
dvalue_result:
plugin->common.adapter_callbacks->driver.update(
plugin->common.adapter, group->group_name, tag->name, dvalue);
free(buf);
}
update_metric(plugin->common.adapter, NEU_METRIC_LAST_RTT_MS, rtt, NULL);
return 0;
}
static void plugin_group_free(neu_plugin_group_t *pgp)
{
struct file_group_data *gd = (struct file_group_data *) pgp->user_data;
utarray_foreach(gd->tags, neu_datatag_t **, tag) { free(*tag); }
utarray_free(gd->tags);
free(gd->group);
free(gd);
}
int file_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
neu_value_u value)
{
FILE *fp = fopen(tag->address, "w");
int ret = 0;
if (0 == fwrite(value.str, sizeof(char), strlen(value.str), fp)) {
nlog_error("write file failed:%s", tag->address);
ret = NEU_ERR_PLUGIN_WRITE_FAILURE;
goto dvalue_result;
}
neu_datatag_string_ltoh(value.str, strlen(value.str));
dvalue_result:
fclose(fp);
plugin->common.adapter_callbacks->driver.write_response(
plugin->common.adapter, req, ret);
return 0;
}
+37
View File
@@ -0,0 +1,37 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 _NEU_M_PLUGIN_file_REQ_H_
#define _NEU_M_PLUGIN_file_REQ_H_
#include <neuron.h>
struct neu_plugin {
neu_plugin_common_t common;
neu_events_t *events;
int file_length;
};
int file_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group);
int file_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
neu_value_u value);
#endif
+2
View File
@@ -327,6 +327,8 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content)
status = NNG_HTTP_STATUS_BAD_REQUEST;
break;
case NEU_ERR_FILE_NOT_EXIST:
case NEU_ERR_FILE_OPEN_FAILURE:
case NEU_ERR_FILE_READ_FAILURE:
case NEU_ERR_LIBRARY_NOT_FOUND:
case NEU_ERR_NODE_NOT_EXIST:
case NEU_ERR_TAG_NOT_EXIST:
+42 -153
View File
@@ -44,32 +44,51 @@
UT_array *collect_log_files();
// void handle_get_log_files(nng_aio *aio);
int read_file(const char *file_name, void **datap, size_t *lenp);
static int http_resp_files(nng_aio *aio, void *data, size_t len,
const char *disposition);
void handle_logs_files(nng_aio *aio)
{
char path[128] = { 0 };
char disp[128] = { 0 };
void * data = NULL;
size_t len = 0;
int rv = 0;
void * data = NULL;
size_t len = 0;
int rv = 0;
VALIDATE_JWT(aio);
rv = mkdir("neuron_logs", S_IRWXU);
if (0 != rv && EEXIST == errno) {
rv = 0;
/* check whether the neuron directory exists */
rv = access("../neuron", F_OK);
if (0 != rv) {
nlog_error("The neuron directory does not exists");
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_NOT_EXIST, {
http_response(aio, error_code.error, result_error);
});
return;
}
// check if coredump exists
rv = access("./core", F_OK);
if (0 == rv) {
rv = system("cp -r ./core neuron_logs");
if (0 != rv) {
nlog_error("failed to copy coredump file");
rv = system("rm -rf /tmp/neuron_debug.tar.gz");
nlog_warn("remove old neuron_debug.tar.gz, rv: %d", rv);
/* tar the neuron directory */
rv = system("tar -zcvf /tmp/neuron_debug.tar.gz ../neuron");
if (rv == -1) {
nlog_error("failed to create neuron_debug.tar.gz, rv: %d", rv);
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
http_response(aio, error_code.error, result_error);
});
return;
} else {
if (WIFEXITED(rv)) {
if (WEXITSTATUS(rv) < 0) {
nlog_error("failed to create neuron_debug.tar.gz, rv: %d",
WEXITSTATUS(rv));
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
http_response(aio, error_code.error, result_error);
});
return;
}
} else {
nlog_error("failed to create neuron_debug.tar.gz, rv: %d",
WEXITSTATUS(rv));
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
http_response(aio, error_code.error, result_error);
});
@@ -77,48 +96,18 @@ void handle_logs_files(nng_aio *aio)
}
}
rv = system("cp -r ./logs neuron_logs");
if (0 != rv) {
nlog_error("failed to copy logs file");
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
http_response(aio, error_code.error, result_error);
});
return;
}
rv = system("tar -zcvf neuron_logs.tar.gz neuron_logs");
if (0 != rv) {
nlog_error("failed to create neuron_logs.tar.gz");
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
http_response(aio, error_code.error, result_error);
});
return;
}
strcpy(path, "neuron_logs.tar.gz");
rv = read_file(path, &data, &len);
rv = read_file("/tmp/neuron_debug.tar.gz", &data, &len);
if (0 != rv) {
NEU_JSON_RESPONSE_ERROR(
rv, { http_response(aio, error_code.error, result_error); });
return;
}
// delete neuron_logs folder from build
rv = system("rm -rf neuron_logs.tar.gz neuron_logs");
if (0 != rv) {
nlog_error("failed to delete neuron_logs folder");
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
http_response(aio, error_code.error, result_error);
});
return;
}
/* handle http response */
rv = http_resp_files(aio, data, len,
"attachment; filename=neuron_debug.tar.gz");
// handle http response
strcpy(disp, "attachment; filename=neuron_logs.tar.gz");
rv = http_resp_files(aio, data, len, disp);
if (0 != rv) {
return;
}
nlog_notice("download neuron_debug.tar.gz, ret: %d", rv);
}
void handle_log_level(nng_aio *aio)
@@ -185,106 +174,6 @@ void handle_log_level(nng_aio *aio)
})
}
// void handle_get_log(nng_aio *aio)
// {
// int rv = 0;
// char log_file[NEU_NODE_NAME_LEN + 32] = { 0 };
// VALIDATE_JWT(aio);
// // optional params
// rv = http_get_param_str(aio, "log_file", log_file, sizeof(log_file));
// if (-1 == rv) {
// nlog_error("parse query param `log_file` fail");
// NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, {
// http_response(aio, error_code.error, result_error);
// });
// return;
// } else if (-2 == rv) {
// // handle no param
// handle_get_log_files(aio);
// return;
// } else if ((size_t) rv >= sizeof(log_file)) {
// nlog_error("query param overflow, `log_file`:%s", log_file);
// NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
// http_response(aio, error_code.error, result_error);
// });
// return;
// }
// void * data = NULL;
// size_t len = 0;
// nng_http_res *res = NULL;
// rv = read_log_file(log_file, &data, &len);
// if (0 != rv) {
// NEU_JSON_RESPONSE_ERROR(
// rv, { http_response(aio, error_code.error, result_error); });
// return;
// }
// if (((rv = nng_http_res_alloc(&res)) != 0) ||
// ((rv = nng_http_res_set_status(res, NNG_HTTP_STATUS_OK)) != 0) ||
// ((rv = nng_http_res_set_header(res, "Content-Type",
// "application/octet-stream")) != 0) ||
// ((rv = nng_http_res_set_header(res, "Access-Control-Allow-Origin",
// "*")) != 0) ||
// ((rv = nng_http_res_set_header(res, "Access-Control-Allow-Methods",
// "POST,GET,PUT,DELETE,OPTIONS")) != 0)
// ||
// ((rv = nng_http_res_set_header(res, "Access-Control-Allow-Headers",
// "*")) != 0) ||
// ((rv = nng_http_res_copy_data(res, data, len)) != 0)) {
// nng_http_res_free(res);
// free(data);
// nng_aio_finish(aio, rv);
// return;
// }
// free(data);
// nng_aio_set_output(aio, 0, res);
// nng_aio_finish(aio, 0);
// }
// void handle_get_log_files(nng_aio *aio)
// {
// UT_array *log_files = collect_log_files();
// if (NULL == log_files) {
// NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
// http_response(aio, error_code.error, result_error);
// });
// return;
// }
// size_t len = 1 + strlen("{log_files:[ ]}");
// utarray_foreach(log_files, char **, log_file)
// {
// // one byte for the comma,
// // the last one will be for the terminating NULL byte
// len += strlen(*log_file) + 1;
// }
// char *res = malloc(len);
// if (NULL == res) {
// NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
// http_response(aio, error_code.error, result_error);
// });
// utarray_free(log_files);
// return;
// }
// // with the space char to simplify code
// int i = snprintf(res, len, "{log_files:[ ");
// utarray_foreach(log_files, char **, log_file)
// {
// i += snprintf(res + i, len - i, "%s,", *log_file);
// }
// // will write over the last comma/space
// snprintf(res + i - 1, len, "]}");
// http_ok(aio, res);
// free(res);
// utarray_free(log_files);
// }
static int http_resp_files(nng_aio *aio, void *data, size_t len,
const char *disposition)
{
@@ -365,7 +254,7 @@ int read_file(const char *file_name, void **datap, size_t *lenp)
if ((f = fopen(file_name, "rb")) == NULL) {
nlog_error("open fail: %s", file_name);
return NEU_ERR_EINTERNAL;
return NEU_ERR_FILE_OPEN_FAILURE;
}
len = st.st_size;
@@ -375,8 +264,8 @@ int read_file(const char *file_name, void **datap, size_t *lenp)
goto done;
}
if (fread(data, 1, len, f) != len) {
rv = errno;
nlog_info("rv = %d", rv);
nlog_error("file read failued, errno = %d", errno);
rv = NEU_ERR_FILE_READ_FAILURE;
free(data);
goto done;
}
+7 -2
View File
@@ -299,6 +299,8 @@ void neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
(double) (cmd->value.value.d64 / tag->decimal);
} else if (cmd->value.type == NEU_TYPE_DOUBLE) {
cmd->value.value.d64 = cmd->value.value.d64 / tag->decimal;
} else if (cmd->value.type == NEU_TYPE_FLOAT) {
cmd->value.value.f32 = cmd->value.value.f32 / tag->decimal;
}
break;
default:
@@ -357,8 +359,11 @@ void neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
}
break;
case NEU_TYPE_FLOAT:
cmd->value.type = NEU_TYPE_FLOAT;
cmd->value.value.f32 = (float) cmd->value.value.d64;
if (NEU_TYPE_FLOAT != cmd->value.type) {
cmd->value.value.f32 = (float) cmd->value.value.d64;
cmd->value.type = NEU_TYPE_FLOAT;
}
switch (tag->option.value32.endian) {
case NEU_DATATAG_ENDIAN_LB32:
neu_ntohs_p((uint16_t *) cmd->value.value.bytes);
+1 -1
View File
@@ -94,7 +94,7 @@ static inline int reset_password()
"$5$PwFeXpBBIBZuZdZl$fP8fFPWCLoaWcnVXVSR.3Xi8TEqCvX92gjhowNNn6S4",
};
int rv = neu_persister_create();
int rv = neu_persister_create(g_config_dir);
if (0 != rv) {
return rv;
}
+2 -2
View File
@@ -389,7 +389,7 @@ ssize_t neu_conn_recv(neu_conn_t *conn, uint8_t *buf, ssize_t len)
conn->fd, len, ret, strerror(errno), errno);
}
if (errno == EPIPE || ret == -1) {
if (errno == EPIPE || ret == -1 || ret == 0) {
conn_disconnect(conn);
}
@@ -842,7 +842,7 @@ static void conn_tcp_server_add_client(neu_conn_t *conn, int fd,
static void conn_tcp_server_del_client(neu_conn_t *conn, int fd)
{
for (int i = 0; i < conn->param.params.tcp_server.max_link; i++) {
if (conn->tcp_server.clients[i].fd == fd) {
if (fd > 0 && conn->tcp_server.clients[i].fd == fd) {
close(fd);
conn->tcp_server.clients[i].fd = 0;
conn->tcp_server.n_client -= 1;
+17
View File
@@ -150,6 +150,7 @@ static void connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg);
static inline task_t *client_alloc_task(neu_mqtt_client_t *client);
static inline void client_free_task(neu_mqtt_client_t *client, task_t *task);
static inline size_t client_task_free_list_len(neu_mqtt_client_t *client);
static inline void client_add_subscription(neu_mqtt_client_t *client,
subscription_t * sub);
static int client_send_sub_msg(neu_mqtt_client_t *client,
@@ -545,6 +546,16 @@ static inline void client_free_task(neu_mqtt_client_t *client, task_t *task)
DL_PREPEND(client->task_free_list, task);
}
static inline size_t client_task_free_list_len(neu_mqtt_client_t *client)
{
size_t count = 0;
task_t *elt = NULL;
// count by iterating the list,
// this won't be a problem as a short free list is expected
DL_COUNT(client->task_free_list, elt, count);
return count;
}
static inline void client_add_subscription(neu_mqtt_client_t *client,
subscription_t * sub)
{
@@ -1149,6 +1160,12 @@ int neu_mqtt_client_close(neu_mqtt_client_t *client)
}
nng_mtx_lock(client->mtx);
// wait for all tasks
while (client_task_free_list_len(client) != client->task_count) {
nng_mtx_unlock(client->mtx);
nng_msleep(100);
nng_mtx_lock(client->mtx);
}
client->open = false;
nng_mtx_unlock(client->mtx);
+5
View File
@@ -88,6 +88,11 @@ static void *event_loop(void *arg)
if (ret == 0) {
continue;
}
if (ret == -1 && errno == EINTR) {
continue;
}
if (ret == -1 || events->stop) {
zlog_warn(neuron, "event loop exit, errno: %s(%d), stop: %d",
strerror(errno), errno, events->stop);
+3 -2
View File
@@ -42,7 +42,7 @@ static void sig_handler(int sig)
{
nlog_warn("recv sig: %d", sig);
if (sig != SIGABRT) {
if (sig == SIGINT || sig == SIGTERM) {
neu_manager_destroy(g_manager);
neu_persister_destroy();
}
@@ -58,6 +58,7 @@ static int neuron_run(const neu_cli_args_t *args)
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
signal(SIGABRT, sig_handler);
signal(SIGSEGV, sig_handler);
// try to enable core dump
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
@@ -65,7 +66,7 @@ static int neuron_run(const neu_cli_args_t *args)
nlog_warn("neuron process failed enable core dump, ignore");
}
rv = neu_persister_create();
rv = neu_persister_create(args->config_dir);
assert(rv == 0);
zlog_notice(neuron, "neuron process, daemon: %d, version: %s (%s %s)",
+1 -1
View File
@@ -27,7 +27,7 @@
#include "json/json.h"
#include "persist_json_plugin.h"
#include "persist/json/persist_json_plugin.h"
int neu_json_decode_plugin_req(char *buf, neu_json_plugin_req_t **result)
{
+7 -2
View File
@@ -430,7 +430,7 @@ static int apply_schemas(sqlite3 *db, const char *dir)
return rv;
}
int neu_persister_create()
int neu_persister_create(const char *schema_dir)
{
int rv = sqlite3_open(db_file, &global_db);
@@ -455,7 +455,7 @@ int neu_persister_create()
return -1;
}
rv = apply_schemas(global_db, g_config_dir);
rv = apply_schemas(global_db, schema_dir);
if (rv != 0) {
nlog_fatal("db apply schemas fail");
sqlite3_close(global_db);
@@ -465,6 +465,11 @@ int neu_persister_create()
return 0;
}
sqlite3 *neu_persister_get_db()
{
return global_db;
}
void neu_persister_destroy()
{
sqlite3_close(global_db);
+1 -1
View File
@@ -1 +1 @@
2.3.4
2.3.13