diff --git a/include/neuron/errcodes.h b/include/neuron/errcodes.h index e80068bb..9bc72d49 100644 --- a/include/neuron/errcodes.h +++ b/include/neuron/errcodes.h @@ -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, diff --git a/plugins/file/file_req.c b/plugins/file/file_req.c index 925d95b5..257a08ef 100644 --- a/plugins/file/file_req.c +++ b/plugins/file/file_req.c @@ -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) {