Merge pull request #1111 from fengzeroz/main

fix(api): check return value of system
This commit is contained in:
fengzeroz
2023-03-14 15:36:51 +08:00
committed by GitHub
3 changed files with 35 additions and 23 deletions
+2 -3
View File
@@ -186,7 +186,6 @@ void handle_download_file(nng_aio *aio)
/*handle http response*/
sprintf(http_resp, "%s%s", "attachment; filename=", file_name);
rv = neu_http_response_file(aio, file_data, file_len, http_resp);
if (0 != rv) {
return;
}
free(file_data);
nlog_notice("download file %s, rv: %d", file_name, rv);
}
+33 -18
View File
@@ -46,11 +46,9 @@ UT_array *collect_log_files();
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;
NEU_VALIDATE_JWT(aio);
@@ -65,17 +63,34 @@ void handle_logs_files(nng_aio *aio)
}
/* tar the neuron directory */
rv = system("tar -zcvf neuron_debug.tar.gz ../neuron");
if (0 != rv) {
nlog_error("failed to create neuron_debug.tar.gz");
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, {
neu_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, {
neu_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, {
neu_http_response(aio, error_code.error, result_error);
});
return;
}
}
strcpy(path, "neuron_debug.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, { neu_http_response(aio, error_code.error, result_error); });
@@ -83,11 +98,11 @@ void handle_logs_files(nng_aio *aio)
}
/* handle http response */
strcpy(disp, "attachment; filename=neuron_debug.tar.gz");
rv = neu_http_response_file(aio, data, len, disp);
if (0 != rv) {
return;
}
rv = neu_http_response_file(aio, data, len,
"attachment; filename=neuron_debug.tar.gz");
free(data);
nlog_notice("download neuron_debug.tar.gz, ret: %d", rv);
}
void handle_log_level(nng_aio *aio)
@@ -122,9 +137,9 @@ void handle_log_level(nng_aio *aio)
ret = zlog_level_switch(ct, ZLOG_LEVEL_DEBUG);
if (ret != 0) {
nlog_error(
"Modify node log level fail, node_name:%s, ret: %d,",
node_name, ret);
nlog_error("Modify node log level fail, node_name:%s, "
"ret: %d,",
node_name, ret);
NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
neu_http_response(aio, error_code.error, result_error);
});
-2
View File
@@ -397,7 +397,6 @@ int neu_http_response_file(nng_aio *aio, void *data, size_t len,
"Content-Disposition")) != 0) ||
((rv = nng_http_res_copy_data(res, data, len)) != 0)) {
nng_http_res_free(res);
free(data);
nng_aio_finish(aio, rv);
return -1;
@@ -407,7 +406,6 @@ int neu_http_response_file(nng_aio *aio, void *data, size_t len,
nlog_notice("%s %s [%d]", nng_http_req_get_method(nng_req),
nng_http_req_get_uri(nng_req), NNG_HTTP_STATUS_OK);
free(data);
nng_aio_set_output(aio, 0, res);
nng_aio_finish(aio, 0);