fix coredump error

This commit is contained in:
lnk
2025-12-23 15:09:28 +08:00
parent 1014aeafbc
commit dd01a31a77
5 changed files with 32 additions and 15 deletions

View File

@@ -49,11 +49,11 @@ fi
# 判断是否为 debug 版本
if [[ "$1" == "debug" ]]; then
CXXFLAGS="-std=c++11 -g -O0"
CXXFLAGS="-std=c++11 -g -O0 -Wformat -Wformat-security -Werror=format"
TARGET="${TARGET}d"
echo "🟢 编译调试版本 (-g -O0)"
else
CXXFLAGS="-std=c++11 -O2 -static-libstdc++ -static-libgcc"
CXXFLAGS="-std=c++11 -O2 -static-libstdc++ -static-libgcc -Wformat -Wformat-security -Werror=format"
echo "🔵 编译正式版本 (-O2 -static)"
fi

View File

@@ -5806,7 +5806,7 @@ void on_device_response_minimal(int response_code,
<< " rc=" << response_code << " recall_status=" << front.recall_status << std::endl; //错误响应码
//记录日志
DIY_ERRORLOG_CODE(matched_monitor->monitor_id.c_str(),2,static_cast<int>(LogCode::LOG_CODE_RECALL),"【ERROR】监测点:%s 补招数据失败 - 失败时间点:%lld 至 %lld",matched_monitor->monitor_id.c_str(),front.StartTime,front.EndTime);
DIY_ERRORLOG_CODE(matched_monitor->monitor_id.c_str(),2,static_cast<int>(LogCode::LOG_CODE_RECALL),"【ERROR】监测点:%s 补招数据失败 - 失败时间点:%s 至 %s",matched_monitor->monitor_id.c_str(),front.StartTime.c_str(),front.EndTime.c_str());
}
else { //补招失败
front.recall_status = static_cast<int>(RecallStatus::FAILED);
@@ -5816,7 +5816,7 @@ void on_device_response_minimal(int response_code,
<< " rc=" << response_code << " recall_status=" << front.recall_status<< std::endl; //错误响应码
//记录日志
DIY_ERRORLOG_CODE(matched_monitor->monitor_id.c_str(),2,static_cast<int>(LogCode::LOG_CODE_RECALL),"【ERROR】监测点:%s 补招数据失败 - 失败时间点:%lld 至 %lld",matched_monitor->monitor_id.c_str(),front.StartTime,front.EndTime);
DIY_ERRORLOG_CODE(matched_monitor->monitor_id.c_str(),2,static_cast<int>(LogCode::LOG_CODE_RECALL),"【ERROR】监测点:%s 补招数据失败 - 失败时间点:%s 至 %s",matched_monitor->monitor_id.c_str(),front.StartTime.c_str(),front.EndTime.c_str());
}
updated = true;
} else { //首条不是 RUNNING 状态,不应该收到这条响应

View File

@@ -271,7 +271,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const
if (res != CURLE_OK) {
const char* em = errbuf[0] ? errbuf : curl_easy_strerror(res);
std::cerr << "http web failed: " << em << std::endl;
DIY_ERRORLOG("process","【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath);
DIY_ERRORLOG("process","【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath.c_str());
} else {
std::cout << "http web success, response: " << resPost0 << std::endl;
handleUploadResponse(resPost0, wavepath); // 处理响应
@@ -389,7 +389,7 @@ void download_xml_for_icd(const std::string& MODEL_ID,
std::cout << "remote file name:" << remote_file_name << "local save name:" << save_name << std::endl;
// mq日志
DIY_WARNLOG("process","【WARN】前置获取到终端类型%s,该终端类型对应的映射文件为%s,映射文件将下载并保存在本地为%s",TMNL_TYPE,FILE_PATH,save_name);
DIY_WARNLOG("process","【WARN】前置获取到终端类型%s,该终端类型对应的映射文件为%s,映射文件将下载并保存在本地为%s",TMNL_TYPE.c_str(),FILE_PATH.c_str(),save_name.c_str());
std::string fileContent;
std::string fullPath = std::string("filePath=") + filepath; //填写远端路径作为入参
@@ -409,14 +409,14 @@ void download_xml_for_icd(const std::string& MODEL_ID,
outFile.close();
std::cout << "File saved successfully!" << std::endl;
DIY_WARNLOG("process","【WARN】前置下载映射文件%s成功",save_name);
DIY_WARNLOG("process","【WARN】前置下载映射文件%s成功",save_name.c_str());
} else {
std::cerr << "Error: Unable to open file for writing." << std::endl;
DIY_ERRORLOG("process","【ERROR】前置写入本地映射文件%s失败",save_name);
DIY_ERRORLOG("process","【ERROR】前置写入本地映射文件%s失败",save_name.c_str());
}
} else {
std::cerr << "Error: Unable to download file." << std::endl;
DIY_ERRORLOG("process","【ERROR】前置调用文件下载接口下载远端文件文件%s失败",FILE_PATH);
DIY_ERRORLOG("process","【ERROR】前置调用文件下载接口下载远端文件文件%s失败",FILE_PATH.c_str());
}
}
@@ -1244,10 +1244,18 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
root["eventType"] = dis_kind;
// 时间处理
time_t start_sec = start_tm / 1000; //毫秒级取秒
/*time_t start_sec = start_tm / 1000; //毫秒级取秒
struct tm* time_info = localtime(&start_sec);
char time_buf[32];
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", time_info);
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", time_info);*/
time_t start_sec = start_tm / 1000;
struct tm tm_info;
localtime_r(&start_sec, &tm_info);
char time_buf[32];
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", &tm_info);
std::ostringstream start_time_stream;
start_time_stream << time_buf << "." << std::setfill('0') << std::setw(3) << (start_tm % 1000);//构造成年月日时分秒.毫秒
std::string start_time_str = start_time_stream.str();
@@ -1271,7 +1279,7 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
// 有效响应,略过
} catch (...) {
// 响应异常,保存 json
DIY_ERRORLOG(mpid.c_str(), "【ERROR】暂态接口响应异常,无法上送装置%s监测点%s的暂态事件",dev_id, monitor_id);
DIY_ERRORLOG(mpid.c_str(), "【ERROR】暂态接口响应异常,无法上送装置%s监测点%u的暂态事件",dev_id.c_str(), (unsigned)monitor_id);
std::cout << "qvvr send fail ,store in local" << std::endl;
std::string qvvrDir = FRONT_PATH + "/dat/qvvr/";
@@ -1281,7 +1289,7 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
}
} else {
// 无响应,保存 json
DIY_ERRORLOG(mpid.c_str(), "【ERROR】暂态接口无响应,无法上送装置%s监测点%s的暂态事件",dev_id, monitor_id);
DIY_ERRORLOG(mpid.c_str(), "【ERROR】暂态接口无响应,无法上送装置%s监测点%u的暂态事件",dev_id.c_str(), (unsigned)monitor_id);
std::cout << "qvvr send fail ,store in local" << std::endl;
std::string qvvrDir = FRONT_PATH + "/dat/qvvr/";

View File

@@ -484,6 +484,7 @@ extern "C" {
//标准化日志接口
// #define LOGMSG_WITH_TS // 需要时间时再打开
//已在头文件添加编译校验
void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...) {
if (!buf || buf_size == 0) return;
buf[0] = '\0';

View File

@@ -34,7 +34,13 @@ extern LOG_TLS_SPEC int g_log_code_tls;
#define LOGTYPE_COM 1
#define LOGTYPE_DATA 2
/////////////////////////////////////////////入参验证
#if defined(__GNUC__) || defined(__clang__)
# define PRINTF_LIKE(fmt_index, first_arg) __attribute__((format(printf, fmt_index, first_arg)))
#else
# define PRINTF_LIKE(fmt_index, first_arg)
#endif
/////////////////////////////////////////
struct TypedLogger {
log4cplus::Logger logger;
int logtype;
@@ -94,7 +100,9 @@ void log_debug(const char* key, const char* msg);
void log_info(const char* key, const char* msg);
void log_warn(const char* key, const char* msg);
void log_error(const char* key, const char* msg);
void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...);
//void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...);
//带验证
void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...) PRINTF_LIKE(3,4);
// ====================== ★新增:线程局部变量透传 code ======================
// 说明:使用编译器的 TLS__thread保存当前日志的 code 值。