!1478 gstrace start时候,校验下数据库进程是否存在

Merge pull request !1478 from zhangxubo/bug3
This commit is contained in:
opengauss-bot
2022-02-24 08:54:36 +00:00
committed by Gitee
3 changed files with 32 additions and 0 deletions

View File

@ -94,6 +94,7 @@ typedef enum trace_msg_code {
TRACE_SEQ_ERR,
TRACE_VERSION_ERR,
TRACE_CONFIG_SIZE_ERR,
TRACE_PROCESS_NOT_EXIST,
TRACE_MSG_MAX,
} trace_msg_code;

View File

@ -368,6 +368,31 @@ static void detachTraceBufferIfDisabled()
pTrcCxt->pTrcCfg->bEnabled = false;
}
static bool checkProcess(int port)
{
int ret;
bool procexist = false;
char checkcmd[MAX_PATH_LEN] = {0};
char buf[MAX_PATH_LEN];
FILE* fp = NULL;
ret = snprintf_s(checkcmd, MAX_PATH_LEN, MAX_PATH_LEN - 1, "lsof -i:%d", port);
securec_check_ss_c(ret, "\0", "\0");
fp = popen(checkcmd, "r");
if (fp == NULL) {
printf("popen failed. could not query database process.\n");
return procexist;
}
while (fgets(buf, sizeof(buf), fp) != NULL) {
procexist = true;
break;
}
pclose(fp);
return procexist;
}
void gstrace_destory(int code, void *arg)
{
trace_context* pTrcCxt = getTraceContext();
@ -549,6 +574,11 @@ trace_msg_code gstrace_start(int key, const char* mask, uint64_t bufferSize, con
return TRACE_ALREADY_START;
}
/* check if database process exist. */
if (!checkProcess(key)) {
return TRACE_PROCESS_NOT_EXIST;
}
/* set the mask if it's passed in */
if (mask != NULL) {
trace_mask st_mask = {0};

View File

@ -1468,6 +1468,7 @@ trace_msg_t trace_message[] = {
{TRACE_SEQ_ERR, "Trace sequence check failed."},
{TRACE_VERSION_ERR, "trace version not match."},
{TRACE_CONFIG_SIZE_ERR, "invalid config size in trace file."},
{TRACE_PROCESS_NOT_EXIST, "The database process is not exist."},
{TRACE_MSG_MAX, "Failed!"},
};