From 1df5385fc94381eda0053844dd31c838b0780876 Mon Sep 17 00:00:00 2001 From: lnk Date: Tue, 4 Mar 2025 17:29:04 +0800 Subject: [PATCH] fix bug in log upload --- .vscode/settings.json | 3 +- cfg_parse/cfg_parser.cpp | 88 ++++++++++-- cfg_parse/custom_printf.h | 293 +++++++++++++++++++++++++++++++++----- json/save2json.cpp | 9 ++ json/save2json.h | 21 ++- misc/my_encrypt.cpp | 2 +- mms/db_interface.h | 1 - mms/main.c | 71 +++++++-- mms/mms_process.c | 1 + mms/mmscli_log.c | 1 + mms/mmscli_rpt.c | 1 + mms/mmsclient.c | 5 +- mms/mvl_acse.c | 2 +- mms/parse_xml.c | 2 +- mms/rdb_client.c | 13 +- mms/rdb_ext_utils.c | 1 + 16 files changed, 434 insertions(+), 80 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ee40160..049df12 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -137,6 +137,7 @@ "stdbool.h": "c", "node.h": "c", "save2json.h": "c", - "custom_printf.h": "c" + "custom_printf.h": "c", + "suicacse.h": "c" } } \ No newline at end of file diff --git a/cfg_parse/cfg_parser.cpp b/cfg_parse/cfg_parser.cpp index 96d7332..481d0c7 100644 --- a/cfg_parse/cfg_parser.cpp +++ b/cfg_parse/cfg_parser.cpp @@ -203,6 +203,7 @@ const int MAX_CPUNO = 10; //lnk20250121终端台账数量配置 int IED_COUNT = 300; //默认300 +extern int INITFLAG; //WW 2-23-08-20 add start otl_connect db; //OTL数据库连接对象 WW 2023-08-20 @@ -11789,7 +11790,7 @@ void ledger(const char* terminal_id, QIODevice* outputDevice) { if(ied != NULL){ ied_usr = (ied_usr_t*)ied->usr_ext; if (ied_usr != NULL && (terminal_id == NULL || strcmp(ied_usr->terminal_id, terminal_id) == 0)) { - printLedgerinshell(*ied_usr, outputDevice); // 使用 QIODevice 输出 + //printLedgerinshell(*ied_usr, outputDevice); // 使用 QIODevice 输出 //std::cout << "!!! print to log !!!"<< std::endl; //printLedger(*ied_usr); found = true; @@ -11829,6 +11830,9 @@ void value_print(const char *variableName, QTcpSocket *clientSocket) { } else if (strcmp(variableName, "log") == 0) { sprintf(buffer, "showinshellflag = %d,debugOutputEnabled = %d,normalOutputEnabled = %d,warnOutputEnabled = %d,errorOutputEnabled = %d", showinshellflag,debugOutputEnabled,normalOutputEnabled,warnOutputEnabled,errorOutputEnabled); clientSocket->write(buffer); + }else if (strcmp(variableName, "init") == 0) { + sprintf(buffer, "INITFLAG = %d",INITFLAG); + clientSocket->write(buffer); }else { clientSocket->write("Unknown variable name\n> "); } @@ -15496,31 +15500,39 @@ void myQtMsgHandler(QtMsgType type, const char *msg) // 不论消息类型如何,都写入 debugList if (debugOutputEnabled) { pthread_mutex_lock(&debugListMutex); - debugList.push_back(msg); // 将 const char* 转换为 std::string 自动完成 + debugList.push_back(msg); pthread_mutex_unlock(&debugListMutex); } - // 同时将消息输出到 stderr(可选) + // 根据消息类型选择输出流 + FILE* output = nullptr; const char* typeStr = ""; switch (type) { case QtDebugMsg: typeStr = "Debug"; + output = stdout; // Debug 走标准输出 break; case QtWarningMsg: typeStr = "Warning"; + output = stderr; // Warning 走标准错误 break; case QtCriticalMsg: typeStr = "Critical"; + output = stderr; // Critical 走标准错误 break; case QtFatalMsg: typeStr = "Fatal"; + output = stderr; // Fatal 走标准错误 break; } - fprintf(stderr, "[%s] %s\n", typeStr, msg); - fflush(stderr); - if (type == QtFatalMsg) + fprintf(output, "[%s] %s\n", typeStr, msg); + fflush(output); + + // Fatal 时进程退出 + if (type == QtFatalMsg) { abort(); + } } // ------------------ 自定义 printf 输出 ------------------ @@ -15545,16 +15557,62 @@ int customPrintf(const char* format, ...) return written; } -// **原始 `echo_msgX()` 的实现** -void real_echo_msg(const char *format, ...) { - char buffer[1024]; - va_list args; - va_start(args, format); - vsnprintf(buffer, sizeof(buffer), format, args); - va_end(args); +/////////////////////////////////////////////////////////////////////////////// +void echo_msg_errexy(const char *file_name, int line_no, int rv, const char *fmt, ...) { + char __buf[1024]; + va_list __ap; + va_start(__ap, fmt); + vsnprintf(__buf, sizeof(__buf), fmt, __ap); + va_end(__ap); - printf("%s", buffer); - fflush(stdout); // ? 确保标准输出立即刷新 + // 终端输出 + printf("[ERROR] rv=%d %s:%d => %s", rv, file_name, line_no, __buf); + fflush(stdout); + + // 写入 errorList + if (errorOutputEnabled) { + pthread_mutex_lock(&errorListMutex); + errorList.push_back(std::string(__buf)); + pthread_mutex_unlock(&errorListMutex); + } +} + +void echo_msg_warnexy(const char *file_name, int line_no, const char *fmt, ...) { + char __buf[1024]; + va_list __ap; + va_start(__ap, fmt); + vsnprintf(__buf, sizeof(__buf), fmt, __ap); + va_end(__ap); + + // 终端输出 + printf("[WARN ] %s:%d => %s", file_name, line_no, __buf); + fflush(stdout); + + // 写入 warnList + if (warnOutputEnabled) { + pthread_mutex_lock(&warnListMutex); + warnList.push_back(std::string(__buf)); + pthread_mutex_unlock(&warnListMutex); + } +} + +void echo_msg_debugexy(const char *file_name, int line_no, const char *fmt, ...) { + char __buf[1024]; + va_list __ap; + va_start(__ap, fmt); + vsnprintf(__buf, sizeof(__buf), fmt, __ap); + va_end(__ap); + + // 终端输出 + printf("[DEBUG] %s:%d => %s", file_name, line_no, __buf); + fflush(stdout); + + // 写入 normalList + if (normalOutputEnabled) { + pthread_mutex_lock(&normalListMutex); + normalList.push_back(std::string(__buf)); + pthread_mutex_unlock(&normalListMutex); + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/cfg_parse/custom_printf.h b/cfg_parse/custom_printf.h index 8299e33..8d1fc43 100644 --- a/cfg_parse/custom_printf.h +++ b/cfg_parse/custom_printf.h @@ -36,45 +36,266 @@ extern pthread_mutex_t warnListMutex; extern pthread_mutex_t normalListMutex; extern pthread_mutex_t debugListMutex; -// **澹版槑鍘熷 echo_msgX()锛岃缂栬瘧鍣ㄧ煡閬撳畠浠瓨鍦** -void real_echo_msg(const char *format, ...); - -// **鎷︽埅鎵鏈 `echo_msgX()`锛岃瀹冨悓鏃跺瓨鍏 `normalList`** -#define echo_msgX(format, ...) \ - do { \ - char buffer[1024]; \ - snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \ - \ - /* 鉁 鍏堟墦鍗板埌 Shell锛岀‘淇濅笉浼氬崱姝 */ \ - printf("%s", buffer); \ - fflush(stdout); /* 鉁 绔嬪嵆鍒锋柊锛岄槻姝㈡爣鍑嗚緭鍑虹紦瀛 */ \ - \ - /* 鉁 鍏堝垱寤烘棩蹇楀壇鏈紝閬垮厤閿佷綇 `normalList` 杩囦箙 */ \ - std::string logEntry(buffer); \ - \ - /* 鉁 浠呭湪 `normalList` 鎿嶄綔鏃跺姞閿侊紝閬垮厤姝婚攣 */ \ - pthread_mutex_lock(&normalListMutex); \ - normalList.push_back(logEntry); \ - pthread_mutex_unlock(&normalListMutex); \ - } while (0) - -// **瀹忚嚜鍔ㄥ睍寮涓嶅悓鐨 `echo_msg` 鍙樹綋** -#define echo_msg1 echo_msgX -#define echo_msg2 echo_msgX -#define echo_msg3 echo_msgX -#define echo_msg4 echo_msgX -#define echo_msg5 echo_msgX -#define echo_msg6 echo_msgX -#define echo_msg7 echo_msgX -#define echo_msg8 echo_msgX -#define echo_msg9 echo_msgX -#define echo_msg10 echo_msgX -#define echo_msg11 echo_msgX -// **濡傛灉鏈夋洿澶氱殑 `echo_msgX()`锛岀户缁畾涔** - extern "C" { #endif +void echo_msg_debugexy(const char *file_name, int line_no, const char *fmt, ...); +void echo_msg_warnexy(const char *file_name, int line_no, const char *fmt, ...); +void echo_msg_errexy(const char *file_name, int line_no, int rv, const char *fmt, ...); + + +#define echo_msg_debugexy(file_name, line_no, ...) \ + echo_msg_debugexy(file_name, line_no, __VA_ARGS__) + +#define echo_msg_warnexy(file_name, line_no, ...) \ + echo_msg_warnexy(file_name, line_no, __VA_ARGS__) + +#define echo_msg_errexy(file_name, line_no, rv, ...) \ + echo_msg_errexy(file_name, line_no, rv, __VA_ARGS__) + +// ======================= echo_warnX ======================= +#ifdef echo_warn +#undef echo_warn +#endif +#define echo_warn(s) \ + echo_msg_warnexy(__FILE__, __LINE__, ("%s"), s) + +#ifdef echo_warn1 +#undef echo_warn1 +#endif +#define echo_warn1(fmt, s0) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0)) + +#ifdef echo_warn2 +#undef echo_warn2 +#endif +#define echo_warn2(fmt, s0, s1) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1)) + +#ifdef echo_warn3 +#undef echo_warn3 +#endif +#define echo_warn3(fmt, s0, s1, s2) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2)) + +#ifdef echo_warn4 +#undef echo_warn4 +#endif +#define echo_warn4(fmt, s0, s1, s2, s3) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3)) + +#ifdef echo_warn5 +#undef echo_warn5 +#endif +#define echo_warn5(fmt, s0, s1, s2, s3, s4) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4)) + +#ifdef echo_warn6 +#undef echo_warn6 +#endif +#define echo_warn6(fmt, s0, s1, s2, s3, s4, s5) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5)) + +#ifdef echo_warn7 +#undef echo_warn7 +#endif +#define echo_warn7(fmt, s0, s1, s2, s3, s4, s5, s6) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6)) + +#ifdef echo_warn8 +#undef echo_warn8 +#endif +#define echo_warn8(fmt, s0, s1, s2, s3, s4, s5, s6, s7) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7)) + +#ifdef echo_warn9 +#undef echo_warn9 +#endif +#define echo_warn9(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8)) + +#ifdef echo_warn10 +#undef echo_warn10 +#endif +#define echo_warn10(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9)) + +#ifdef echo_warn11 +#undef echo_warn11 +#endif +#define echo_warn11(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10)) + +#ifdef echo_warn12 +#undef echo_warn12 +#endif +#define echo_warn12(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \ + echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11)) + +// ======================= echo_errX ======================= +#ifdef echo_err +#undef echo_err +#endif +#define echo_err(s, rv) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), ("%s"), (s)) + +#ifdef echo_errg +#undef echo_errg +#endif +#define echo_errg(s) \ + echo_msg_errexy(__FILE__, __LINE__, (APR_EGENERAL), ("%s"), (s)) + +#ifdef echo_err1 +#undef echo_err1 +#endif +#define echo_err1(fmt, rv, s1) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1)) + +#ifdef echo_err2 +#undef echo_err2 +#endif +#define echo_err2(fmt, rv, s1, s2) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2)) + +#ifdef echo_err3 +#undef echo_err3 +#endif +#define echo_err3(fmt, rv, s1, s2, s3) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3)) + +#ifdef echo_err4 +#undef echo_err4 +#endif +#define echo_err4(fmt, rv, s1, s2, s3, s4) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4)) + +#ifdef echo_err5 +#undef echo_err5 +#endif +#define echo_err5(fmt, rv, s1, s2, s3, s4, s5) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5)) + +#ifdef echo_err6 +#undef echo_err6 +#endif +#define echo_err6(fmt, rv, s1, s2, s3, s4, s5, s6) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6)) + +#ifdef echo_err7 +#undef echo_err7 +#endif +#define echo_err7(fmt, rv, s1, s2, s3, s4, s5, s6, s7) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7)) + +#ifdef echo_err8 +#undef echo_err8 +#endif +#define echo_err8(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8)) + +#ifdef echo_err9 +#undef echo_err9 +#endif +#define echo_err9(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9)) + +#ifdef echo_err10 +#undef echo_err10 +#endif +#define echo_err10(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10)) + +#ifdef echo_err11 +#undef echo_err11 +#endif +#define echo_err11(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11)) + +#ifdef echo_err12 +#undef echo_err12 +#endif +#define echo_err12(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12) \ + echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11), (s12)) + +// ======================= echo_msgX ======================= +#ifdef echo_msg +#undef echo_msg +#endif +#define echo_msg(s) \ + echo_msg_debugexy(__FILE__, __LINE__, ("%s"), (s)) + +#ifdef echo_msg1 +#undef echo_msg1 +#endif +#define echo_msg1(fmt, s1) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1)) + +#ifdef echo_msg2 +#undef echo_msg2 +#endif +#define echo_msg2(fmt, s1, s2) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2)) + +#ifdef echo_msg3 +#undef echo_msg3 +#endif +#define echo_msg3(fmt, s1, s2, s3) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3)) + +#ifdef echo_msg4 +#undef echo_msg4 +#endif +#define echo_msg4(fmt, s1, s2, s3, s4) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4)) + +#ifdef echo_msg5 +#undef echo_msg5 +#endif +#define echo_msg5(fmt, s1, s2, s3, s4, s5) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5)) + +#ifdef echo_msg6 +#undef echo_msg6 +#endif +#define echo_msg6(fmt, s1, s2, s3, s4, s5, s6) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6)) + +#ifdef echo_msg7 +#undef echo_msg7 +#endif +#define echo_msg7(fmt, s1, s2, s3, s4, s5, s6, s7) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7)) + +#ifdef echo_msg8 +#undef echo_msg8 +#endif +#define echo_msg8(fmt, s1, s2, s3, s4, s5, s6, s7, s8) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8)) + +#ifdef echo_msg9 +#undef echo_msg9 +#endif +#define echo_msg9(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9)) + +#ifdef echo_msg10 +#undef echo_msg10 +#endif +#define echo_msg10(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10)) + +#ifdef echo_msg11 +#undef echo_msg11 +#endif +#define echo_msg11(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11)) + +#ifdef echo_msg12 +#undef echo_msg12 +#endif +#define echo_msg12(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12) \ + echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11), (s12)) + // 鑷畾涔夌殑 printf 鍑芥暟 int customPrintf(const char* format, ...); #ifdef __cplusplus diff --git a/json/save2json.cpp b/json/save2json.cpp index 94026b5..e861576 100644 --- a/json/save2json.cpp +++ b/json/save2json.cpp @@ -68,6 +68,8 @@ extern "C" { #define nullptr NULL #endif +extern int INITFLAG; + extern QMutex kafka_data_list_mutex; extern QList kafka_data_list; @@ -1888,6 +1890,8 @@ int find_mp_index_from_mp_id(std::string line) int myMessageCallbackrtdata(CPushConsumer* consumer, CMessageExt* msg) { + if(INITFLAG != 1)return 1;//防止崩溃 + if (msg == NULL) { std::cerr << "Received null message." << std::endl; return E_RECONSUME_LATER; @@ -1947,6 +1951,8 @@ int myMessageCallbackrtdata(CPushConsumer* consumer, CMessageExt* msg) int myMessageCallbackupdate(CPushConsumer* consumer, CMessageExt* msg) { + if(INITFLAG != 1)return 1;//防止崩溃 + if (msg == NULL) { std::cerr << "Received null message." << std::endl; return E_RECONSUME_LATER; @@ -1982,6 +1988,7 @@ int myMessageCallbackupdate(CPushConsumer* consumer, CMessageExt* msg) int myMessageCallbackset(CPushConsumer* consumer, CMessageExt* msg) { + if(INITFLAG != 1)return 1;//防止崩溃 if (msg == NULL) { std::cerr << "Received null message." << std::endl; return E_RECONSUME_LATER; @@ -2016,6 +2023,7 @@ int myMessageCallbackset(CPushConsumer* consumer, CMessageExt* msg) int myMessageCallbacklog(CPushConsumer* consumer, CMessageExt* msg) { + if(INITFLAG != 1)return 1;//防止崩溃 if (msg == NULL) { std::cerr << "Received null message." << std::endl; return E_RECONSUME_LATER; @@ -2050,6 +2058,7 @@ int myMessageCallbacklog(CPushConsumer* consumer, CMessageExt* msg) int myMessageCallbackrecall(CPushConsumer* consumer, CMessageExt* msg) { + if(INITFLAG != 1)return 1;//防止崩溃 //调试 std::cout << "myMessageCallbackrecall"<< std::endl; diff --git a/json/save2json.h b/json/save2json.h index 1d0b734..40d52b1 100644 --- a/json/save2json.h +++ b/json/save2json.h @@ -110,6 +110,16 @@ protected: //lnk20250106 extern bool showinshellflag; +#ifdef __cplusplus +extern "C" { +#endif + +void doMonitorTaskmain(void); + +#ifdef __cplusplus +} +#endif + class Worker : public QObject { Q_OBJECT @@ -162,6 +172,11 @@ public slots: connect(timer, SIGNAL(timeout()), this, SLOT(doPeriodicTask())); timer->start(60000); // 每60秒触发一次 + //开启另一个周期函数用来替换主线程的监控 + QTimer *monitorTimer = new QTimer(this); + connect(monitorTimer, SIGNAL(timeout()), this, SLOT(doMonitorTask())); + monitorTimer->start(1000); // 每1秒触发一次 + std::cout << "Timer started, event loop running in thread: " << QThread::currentThreadId() << std::endl; qDebug() << "Timer started, event loop running in thread:" << QThread::currentThreadId(); } @@ -202,6 +217,10 @@ private slots: } } + void doMonitorTask() { + doMonitorTaskmain(); + } + void onNewConnection() { if (!server) return; @@ -336,7 +355,7 @@ private: helpText += "log - Execute rocketmq_test_log\n"; helpText += "ledger - Execute ledger with optional terminal_id\n"; helpText += "viewlog - View logs (ERROR, WARN, NORMAL, DEBUG)\n"; - helpText += "value - Execute value print with valuename : iedcount frontfun frontindex remtable log\n"; + helpText += "value - Execute value print with valuename : iedcount frontfun frontindex remtable log init\n"; helpText += "exit - Exit the shell\n"; helpText += "help - Show this help message\n"; clientSocket->write(helpText.toUtf8()); diff --git a/misc/my_encrypt.cpp b/misc/my_encrypt.cpp index f28b140..3810fb8 100644 --- a/misc/my_encrypt.cpp +++ b/misc/my_encrypt.cpp @@ -51,7 +51,7 @@ using namespace std; SM4 sm4Encode; sm4Encode.sm4_enc((char*)input,seriseLen+4,(char*)output,szKey); - printf("%lld || %s || %x %x %x %x\n", now_secs, output, pTime[3], pTime[2], pTime[1], pTime[0]); + printf("now_secs:%lld ||series: %s ||ptime: %x %x %x %x\n", now_secs, output, pTime[3], pTime[2], pTime[1], pTime[0]);//lnk20250304 } void MyGetSM4Code(char* input,unsigned char* szKey,char* output) diff --git a/mms/db_interface.h b/mms/db_interface.h index 2d8f924..03acb0e 100644 --- a/mms/db_interface.h +++ b/mms/db_interface.h @@ -17,7 +17,6 @@ #include "apr_time.h" #include //lnk20241022 -#include "../cfg_parse/custom_printf.h"//lnk20250225 #define LOG_IDX (0) #define RPT_IDX (1) diff --git a/mms/main.c b/mms/main.c index 5c34770..32de7a0 100644 --- a/mms/main.c +++ b/mms/main.c @@ -17,6 +17,9 @@ /*lnk10-10 */ #include "../include/rocketmq/SimpleProducer.h" + +#include "../cfg_parse/custom_printf.h"//lnk20250225 + extern G_TEST_FLAG; extern pthread_mutex_t mtx; @@ -35,6 +38,8 @@ uint32_t g_node_id = 0; uint32_t g_min_free_size = 1024; int g_need_password = 0; +int INITFLAG = 0; //lnk20250304 + char subdir[128] = "cfg_stat_data" ; int usage(); @@ -276,26 +281,34 @@ int main(int argc, const char **argv) } //lnk20241024去除数据库连接 - //OTLConnect(); - + //OTLConnect(); rv = run_protocol(); if (rv!=APR_SUCCESS){ return rv; } + //初始化完成标志,防止还未准备完全就接收消息处理导致崩溃 + INITFLAG = 1; + //调试用 + printf("INITFLAG=%d\n",INITFLAG); + + if (1 == G_TEST_FLAG) { + //lnk添加mq模拟测试,这个只能放在主线程 + printf("try_start_mqtest_thread \n"); + int ret = try_start_mqtest_thread(0,NULL); + // 等待线程退出 + echo_warn1("%-60s","System shutdown now......"); + apr_pool_destroy(g_root_pool); + echo_msg("OK\n"); + return ret; + } while(1) { /* sleep 1s, just like 1s timer */ apr_sleep(apr_time_from_sec(1)); /* 每30秒钟检查一次状态 */ - /*添加mq测试lnk10-10 */ - //rocketmq_test_rt(); - //rocketmq_test_ud(); - //rocketmq_test_rc(); - /*lnk20241029recall接口测试*/ - //curltest(); /*202411-1lnk添加文件上传测试 */ //SOEFileWeb_test(); //添加上传测试 @@ -327,14 +340,14 @@ int main(int argc, const char **argv) } //lnk20241211 添加测试开关 - pthread_mutex_lock(&mtx); printf("main thread hold lock !!!!!!!!!!!"); + pthread_mutex_lock(&mtx); if (!G_TEST_FLAG && g_front_num_count >= 30 && g_onlyIP[0] == 0 && g_node->n_clients>10) {//30分钟连接数量过低且不是单连且台账大于十个终端 MVL_LOG_ACSE0("MYLOG: g_front_num_count>=20, so exit to restart "); apr_sleep(apr_time_from_sec(10)); exit(-1039); } - pthread_mutex_unlock(&mtx); printf("main thread free lock !!!!!!!!!!!"); + pthread_mutex_unlock(&mtx); } @@ -455,3 +468,41 @@ int parse_param(int argc, const char **argv) } +///////////////////////////////////////////////////////////////添加测试进程的监控函数lnk20250304 +void doMonitorTaskmain(void) { + static int stimer = 0; + stimer++; + + if( !(stimer++ % 60) ) {//分钟 + if (g_dead_lock_counter++ >=3) {//三分钟 + g_thread_blocked_times++; + g_dead_lock_counter = 0; + } + MVL_LOG_ACSE1 ("MYLOG: current g_thread_blocked_times = %u ", g_thread_blocked_times); + + if (FRONT_MP_NUM <= 1) {//监测点数 + g_front_num_count++; + } + else { + g_front_num_count = 0; + } + } + + //work线程死了3*13分钟,退出进程 + if (g_thread_blocked_times>=13) { + MVL_LOG_ACSE0 ("MYLOG: g_thread_blocked_times>=3, so exit to restart "); + apr_sleep(apr_time_from_sec(10)); + exit(-1039); + } + + //lnk20241211 添加测试开关 + pthread_mutex_lock(&mtx); + if (!G_TEST_FLAG && g_front_num_count >= 30 && g_onlyIP[0] == 0 && g_node->n_clients>10) {//30分钟连接数量过低且不是单连且台账大于十个终端 + MVL_LOG_ACSE0("MYLOG: g_front_num_count>=20, so exit to restart "); + + apr_sleep(apr_time_from_sec(10)); + exit(-1039); + } + pthread_mutex_unlock(&mtx); +} + diff --git a/mms/mms_process.c b/mms/mms_process.c index b70833a..6e3e7c4 100644 --- a/mms/mms_process.c +++ b/mms/mms_process.c @@ -21,6 +21,7 @@ #include "ied.h" #include "../json/mms_json_inter.h" +#include "../cfg_parse/custom_printf.h"//lnk20250225 void clear_rpt_counter_by_trigger(trigger_t *trigger); diff --git a/mms/mmscli_log.c b/mms/mmscli_log.c index 3b023ee..ff21a43 100644 --- a/mms/mmscli_log.c +++ b/mms/mmscli_log.c @@ -38,6 +38,7 @@ #include "tp4.h" #include "db_interface.h" +#include "../cfg_parse/custom_printf.h"//lnk20250225 /************************************************************************/ /* For debug version, use a static pointer to avoid duplication of */ /* __FILE__ strings. */ diff --git a/mms/mmscli_rpt.c b/mms/mmscli_rpt.c index 2cabf85..f58d6e9 100644 --- a/mms/mmscli_rpt.c +++ b/mms/mmscli_rpt.c @@ -56,6 +56,7 @@ #include "rdb_client.h" #include "db_interface.h" #include "../json/mms_json_inter.h" +#include "../cfg_parse/custom_printf.h"//lnk20250225 /************************************************************************/ /* For debug version, use a static pointer to avoid duplication of */ /* __FILE__ strings. */ diff --git a/mms/mmsclient.c b/mms/mmsclient.c index 1995e96..f116603 100644 --- a/mms/mmsclient.c +++ b/mms/mmsclient.c @@ -79,7 +79,7 @@ #include "../mms/db_interface.h" #include //lnk20241119 - +#include "../cfg_parse/custom_printf.h"//lnk20250225 extern uint32_t g_node_id; extern char subdir[128]; unsigned int g_no_auth = 0; @@ -1176,8 +1176,7 @@ S_SEC_ENCRYPT_CTRL *encryptCtrl = NULL; /* conn enctryption info */ //lnk20241119添加判断和打印,确保识别码秘钥为空时不调用加密 if (!is_empty_or_whitespace(dev_series) || !is_empty_or_whitespace(dev_key)) { - printf("dev_series= %s\n", dev_series); - printf("dev_key= %s\n", dev_key); + printf("dev_series= %s,dev_key= %s\n", dev_series,dev_key); /* Fill out an authentication structure */ authInfo = &authInfoStr; authInfo->auth_pres = SD_TRUE; diff --git a/mms/mvl_acse.c b/mms/mvl_acse.c index 29c54bb..ca7eadb 100644 --- a/mms/mvl_acse.c +++ b/mms/mvl_acse.c @@ -195,7 +195,7 @@ #include "mvl_log.h" #include "mloguser.h" #include "mmsop_en.h" - +#include "../cfg_parse/custom_printf.h"//lnk20250225 #if defined(MAP30_ACSE) #include "suicacse.h" diff --git a/mms/parse_xml.c b/mms/parse_xml.c index 43b5e03..5d89f5b 100644 --- a/mms/parse_xml.c +++ b/mms/parse_xml.c @@ -12,7 +12,7 @@ #include #include "rdb_client.h" #include "xmltools.h" - +#include "../cfg_parse/custom_printf.h"//lnk20250225 //int comtrade_remain_file_num = 2147483647; int comtrade_remain_file_num = 0; diff --git a/mms/rdb_client.c b/mms/rdb_client.c index 5f6eec7..2bb97c7 100644 --- a/mms/rdb_client.c +++ b/mms/rdb_client.c @@ -24,6 +24,7 @@ extern int g_front_seg_index; extern int g_front_seg_num; #include "../include/rocketmq/SimpleProducer.h" +#include "../cfg_parse/custom_printf.h"//lnk20250225 //////////////////////////////////////////// #ifdef DEBUG_SISCO SD_CONST static ST_CHAR* SD_CONST thisFileName = __FILE__; @@ -289,7 +290,7 @@ apr_status_t run_protocol() { printf("g_onlyIP[0] != 0!\n\a"); - //单连进程不打开socket、http、测试线程 + //单连进程不打开socket、http线程 } else //socket、http、测试线程的开启 @@ -362,11 +363,7 @@ apr_status_t run_protocol() //lnk20241029增加http线程/////////////////////////////////////////////////////////////////////////////////////////////////// } - if (1 == G_TEST_FLAG) { - //lnk添加mq模拟测试 - printf("try_start_mqtest_thread \n"); - try_start_mqtest_thread(0,NULL); - } + } //lnk删除数据库线程 @@ -382,10 +379,6 @@ apr_status_t run_protocol() printf("try_start_ontimer_thread \n"); try_start_ontimer_thread(); - //OTLTestSelect();//测试数据库连接 - - ///////////////////WW end - return APR_SUCCESS; } diff --git a/mms/rdb_ext_utils.c b/mms/rdb_ext_utils.c index eb8788d..e1d6ff8 100644 --- a/mms/rdb_ext_utils.c +++ b/mms/rdb_ext_utils.c @@ -13,6 +13,7 @@ #include "rdb_client.h" #include "xmltools.h" #include "db_interface.h" +#include "../cfg_parse/custom_printf.h"//lnk20250225 //extern rdb_t* g_rdb ; extern node_t* g_node ; extern char g_my_conf_fname[256];