From c76fb8f73cfbf5ef375f05bd75a4738cecb4ef8e Mon Sep 17 00:00:00 2001 From: Linhe Huo Date: Thu, 30 Dec 2021 22:12:17 +0800 Subject: [PATCH] [TS-1022](other): fix alpine segmentation fault in startup (#9518) --- src/os/src/detail/osTimer.c | 38 +++++++++++++++++++++++++++++++++ src/plugins/http/src/httpResp.c | 5 ++++- src/util/src/tlog.c | 3 +++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index 618df8a8ba..bc5119107a 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -20,6 +20,7 @@ #if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64)) +#ifndef _ALPINE static void taosDeleteTimer(void *tharg) { timer_t *pTimer = tharg; timer_delete(*pTimer); @@ -105,4 +106,41 @@ void taosUninitTimer() { pthread_join(timerThread, NULL); } +#else + +static timer_t timerId; + +void sig_alrm_handler(union sigval sv) { + void (*callback)(int) = sv.sival_ptr; + callback(0); +} +int taosInitTimer(void (*callback)(int), int ms) { + struct sigevent evp; + memset((void *)&evp, 0, sizeof(evp)); + evp.sigev_notify = SIGEV_THREAD; + evp.sigev_notify_function = &sig_alrm_handler; + evp.sigev_signo = SIGALRM; + evp.sigev_value.sival_ptr = (void *)callback; + + struct itimerspec ts; + ts.it_value.tv_sec = 0; + ts.it_value.tv_nsec = 1000000 * MSECONDS_PER_TICK; + ts.it_interval.tv_sec = 0; + ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK; + if (timer_create(CLOCK_REALTIME, &evp, &timerId)) { + uError("Failed to create timer"); + return -1; + } + + if (timer_settime(timerId, 0, &ts, NULL)) { + uError("Failed to init timer"); + return -1; + } + return 0; +} + +void taosUninitTimer() { + timer_delete(timerId); +} +#endif #endif diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index a2452a16b9..2c18904d2a 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -156,7 +156,10 @@ void httpSendErrorResp(HttpContext *pContext, int32_t errNo) { HttpServer *pServer = &tsHttpServer; SMonHttpStatus *httpStatus = monGetHttpStatusHashTableEntry(httpCode); - pServer->statusCodeErrs[httpStatus->index] += 1; + // FIXME(@huolinhe): I don't known why the errors index is overflowed, but fix it by index check + if (httpStatus->index < HTTP_STATUS_CODE_NUM) { + pServer->statusCodeErrs[httpStatus->index] += 1; + } pContext->error = true; diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 78986d227a..67f7042033 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -375,6 +375,9 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { fflush(stdout); return; } + if (flags == NULL || format == NULL) { + return; + } va_list argpointer; char buffer[MAX_LOGLINE_BUFFER_SIZE] = { 0 }; -- GitLab