fix download log coredump

This commit is contained in:
liyuxi
2023-02-01 10:13:18 +00:00
parent 98de412105
commit ba2f425bf3
2 changed files with 5 additions and 104 deletions
+3 -104
View File
@@ -44,7 +44,6 @@
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);
@@ -185,106 +184,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 +264,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 +274,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;
}
+2
View File
@@ -328,6 +328,8 @@ int neu_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: