mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
Merge pull request #1454 from hxy7yx/v2.4
(file):add error code for reading empty files
This commit is contained in:
@@ -137,6 +137,7 @@ typedef enum {
|
||||
NEU_ERR_FILE_OPEN_FAILURE = 4101,
|
||||
NEU_ERR_FILE_READ_FAILURE = 4102,
|
||||
NEU_ERR_FILE_WRITE_FAILURE = 4103,
|
||||
NEU_ERR_FILE_READ_NULL = 4104,
|
||||
|
||||
NEU_ERR_PLUGIN_ERROR_START = 10000,
|
||||
NEU_ERR_PLUGIN_ERROR_END = 20000,
|
||||
|
||||
+10
-4
@@ -84,10 +84,16 @@ int file_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
fseek(f, 0, SEEK_SET);
|
||||
int ret = fread(buf, sizeof(char), length, f);
|
||||
if (ret == 0) {
|
||||
nlog_warn("read file failed:%s", tag->address);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_READ_FAILURE;
|
||||
|
||||
if (feof(f)) {
|
||||
nlog_warn("file is empty:%s", tag->address);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_READ_NULL;
|
||||
} else if (ferror(f)) {
|
||||
nlog_warn("read file failed: %s", tag->address);
|
||||
clearerr(f);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_READ_FAILURE;
|
||||
}
|
||||
fclose(f);
|
||||
goto dvalue_result;
|
||||
} else if (ret >= NEU_VALUE_SIZE) {
|
||||
|
||||
Reference in New Issue
Block a user