• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4952

06 Feb 2026 07:29AM UTC coverage: 66.869% (-0.02%) from 66.887%
#4952

push

travis-ci

web-flow
merge: from main to 3.0 #34521

758 of 1081 new or added lines in 28 files covered. (70.12%)

6496 existing lines in 142 files now uncovered.

205752 of 307696 relevant lines covered (66.87%)

126028909.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.29
/source/libs/txnode/src/txnodeMgmt.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
// clang-format off
17
#include "uv.h"
18
#include "os.h"
19
#include "tarray.h"
20
#include "tglobal.h"
21
#include "txnode.h"
22
#include "txnodeInt.h"
23
#include "osString.h"
24

25
// clang-format on
26

27
extern char **environ;
28

29
#ifdef WINDOWS
30
#define XNODED_DEFAULT_PATH_1    "C:\\TDengine"
31
#define XNODED_DEFAULT_PATH_2    "C:\\TDengine"
32
#define XNODED_DEFAULT_EXEC_NAME "xnoded"
33
#define XNODED_DEFAULT_EXEC      "\\xnoded.exe"
34
#else
35
#define XNODED_DEFAULT_PATH_1    "/usr/bin"
36
#define XNODED_DEFAULT_PATH_2    "/usr/local/taos/bin"
37
#define XNODED_DEFAULT_EXEC_NAME "xnoded"
38
#define XNODED_DEFAULT_EXEC      "/xnoded"
39
#endif
40

41
#define XNODED_XNODED_PID_NAME ".xnoded.pid"
42

43
typedef struct {
44
  bool         isStarted;
45
  bool         needCleanUp;
46
  uv_loop_t    loop;
47
  uv_thread_t  thread;
48
  uv_barrier_t barrier;
49
  uv_process_t process;
50
  int32_t      spawnErr;
51
  uv_pipe_t    ctrlPipe;
52
  uv_async_t   stopAsync;
53
  int32_t      isStopped;
54
  int32_t      dnodeId;
55
  int64_t      clusterId;
56
  char         userPass[XNODE_USER_PASS_LEN];
57
  char         token[TSDB_TOKEN_LEN + 1];
58
  SEp          leaderEp;
59
} SXnodedData;
60

61
SXnodedData xnodedGlobal = {0};
62

63
static int32_t xnodeMgmtSpawnXnoded(SXnodedData *pData);
64

65
static void getXnodedPidPath(char *pipeName, int32_t size) {
408✔
66
#ifdef _WIN32
67
  snprintf(pipeName, size, "%s%s", tsDataDir, XNODED_XNODED_PID_NAME);
68
#else
69
  int32_t len = strlen(tsDataDir);
408✔
70
  if (len > 0 && tsDataDir[len - 1] != '/') {
408✔
71
    snprintf(pipeName, size, "%s/%s", tsDataDir, XNODED_XNODED_PID_NAME);
408✔
72
  } else {
NEW
73
    snprintf(pipeName, size, "%s%s", tsDataDir, XNODED_XNODED_PID_NAME);
×
74
  }
75
#endif
76
  xndDebug("xnode get xnoded pid path:%s", pipeName);
408✔
77
}
408✔
78

79
static void    xnodeMgmtXnodedExit(uv_process_t *process, int64_t exitStatus, int32_t termSignal) {
×
UNCOV
80
  TAOS_XNODED_MGMT_CHECK_PTR_RVOID(process);
×
UNCOV
81
  SXnodedData *pData = process->data;
×
NEW
82
  xndInfo("process xnoded exit with status %" PRId64 ", signal %d, isStopped:%d", exitStatus, termSignal,
×
83
          pData->isStopped);
UNCOV
84
  if (pData == NULL) {
×
UNCOV
85
    xndError("xnoded process data is NULL");
×
86
    return;
×
87
  }
NEW
88
  if ((exitStatus == 0 && (termSignal == 0 || termSignal == SIGINT || termSignal == SIGTERM)) ||
×
NEW
89
      atomic_load_32(&pData->isStopped)) {
×
90
    if (uv_async_send(&pData->stopAsync) != 0) {
×
91
      xndError("stop xnoded: failed to send stop async");
×
92
    }
93
    char xnodedPipeSocket[PATH_MAX] = {0};
×
UNCOV
94
    getXnodedPipeName(xnodedPipeSocket, PATH_MAX);
×
95
    if (0 != unlink(xnodedPipeSocket)) {
×
NEW
96
      xndWarn("txnode failed to unlink, socket: %s, err:%s", xnodedPipeSocket, terrstr());
×
97
    }
98

UNCOV
99
    char *pidPath = xnodedPipeSocket;
×
100
    memset(pidPath, 0, PATH_MAX);
×
101
    getXnodedPidPath(pidPath, PATH_MAX);
×
102
    (void)taosRemoveFile(pidPath);
×
NEW
103
    xndInfo("xnoded process exit success");
×
104
  } else {
UNCOV
105
    xndInfo("xnoded process restart, exit status %" PRId64 ", signal %d", exitStatus, termSignal);
×
UNCOV
106
    int32_t code = xnodeMgmtSpawnXnoded(pData);
×
107
    if (code != 0) {
×
108
      xndError("xnoded process restart failed with code:%d", code);
×
109
    }
NEW
110
    uv_sleep(500);
×
111
  }
112
}
113
void killPreXnoded() {
408✔
114
  char buf[PATH_MAX] = {0};
408✔
115
  getXnodedPidPath(buf, sizeof(buf));
408✔
116

117
  TdFilePtr pFile = NULL;
408✔
118
  pFile = taosOpenFile(buf, TD_FILE_READ);
408✔
119
  if (pFile == NULL) {
408✔
120
    xndWarn("xnode failed to open xnoded pid file:%s, file may not exist", buf);
408✔
121
    return;
408✔
122
  }
UNCOV
123
  int64_t readSize = taosReadFile(pFile, buf, sizeof(buf));
×
UNCOV
124
  if (readSize <= 0) {
×
UNCOV
125
    if (readSize < 0) {
×
UNCOV
126
      xndError("xnode failed to read len from file:%p since %s", pFile, terrstr());
×
127
    }
UNCOV
128
    (void)taosCloseFile(&pFile);
×
UNCOV
129
    return;
×
130
  }
131
  (void)taosCloseFile(&pFile);
×
132

133
  int32_t pid = taosStr2Int32(buf, NULL, 10);
×
134
  int result = uv_kill((uv_pid_t)pid, SIGTERM);
×
UNCOV
135
  if (result != 0) {
×
136
    if (result != UV_ESRCH) {
×
137
      xndError("xnode failed to kill process %d: %s", pid, uv_strerror(result));
×
138
    }
139
    return;
×
140
  }
141
}
142

143
void saveXnodedPid(int32_t pid) {
×
144
  char buf[PATH_MAX] = {0};
×
145
  getXnodedPidPath(buf, sizeof(buf));
×
UNCOV
146
  TdFilePtr testFilePtr = taosCreateFile(buf, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC);
×
147
  snprintf(buf, PATH_MAX, "%d", pid);
×
UNCOV
148
  (void)taosWriteFile(testFilePtr, buf, strlen(buf));
×
UNCOV
149
  (void)taosCloseFile(&testFilePtr);
×
UNCOV
150
}
×
151

152
static void locateXnodedExecFile(char *path) {
408✔
153
  if (tsProcPath == NULL) {
408✔
154
    path[0] = '.';
×
155
#ifdef WINDOWS
156
    GetModuleFileName(NULL, path, PATH_MAX);
157
#elif defined(_TD_DARWIN_64)
158
    uint32_t pathSize = sizeof(path);
159
    _NSGetExecutablePath(path, &pathSize);
160
#endif
161
  } else {
162
    TAOS_STRNCPY(path, tsProcPath, PATH_MAX);
408✔
163
  }
164

165
  TAOS_DIRNAME(path);
408✔
166
  if (strlen(path) != 0) {
408✔
167
    TAOS_STRCAT(path, XNODED_DEFAULT_EXEC);
408✔
168
    if (taosCheckExistFile(path)) {
408✔
UNCOV
169
      goto _ok;
×
170
    }
171
    xndDebug("can't find xnoded exec file:%s", path);
408✔
172
    path[0] = '\0';
408✔
173
  }
174

175
  TAOS_STRCAT(path, XNODED_DEFAULT_PATH_1);
408✔
176
  TAOS_STRCAT(path, XNODED_DEFAULT_EXEC);
408✔
177
  if (taosCheckExistFile(path)) {
408✔
UNCOV
178
    goto _ok;
×
179
  }
180
  xndDebug("can't find xnoded exec file:%s", path);
408✔
181
  path[0] = '\0';
408✔
182

183
  TAOS_STRCAT(path, XNODED_DEFAULT_PATH_2);
408✔
184
  TAOS_STRCAT(path, XNODED_DEFAULT_EXEC);
408✔
185
  if (taosCheckExistFile(path)) {
408✔
186
    goto _ok;
×
187
  }
188
  xndDebug("can't find xnoded exec file:%s", path);
408✔
189
  path[0] = '\0';
408✔
190

191
  path[0] = '.';
408✔
192
  path[1] = '\0';
408✔
193
  TAOS_STRCAT(path, XNODED_DEFAULT_EXEC);
408✔
194
  if (taosCheckExistFile(path)) {
408✔
UNCOV
195
    goto _ok;
×
196
  }
197
  xndDebug("can't find xnoded exec file:%s", path);
408✔
198
  path[0] = '\0';
408✔
199

200
  TAOS_STRNCPY(path, XNODED_DEFAULT_EXEC_NAME, PATH_MAX);
408✔
201
  xndInfo("can't find xnoded exec file, use default: %s", path);
408✔
202
  return;
408✔
203

UNCOV
204
_ok:
×
UNCOV
205
  xndInfo("find xnoded exec file:%s", path);
×
UNCOV
206
  return;
×
207
}
208

209
static int32_t xnodeMgmtSpawnXnoded(SXnodedData *pData) {
408✔
210
  xndDebug("start to init xnoded");
408✔
211
  TAOS_XNODED_MGMT_CHECK_PTR_RCODE(pData);
816✔
212

213
  int32_t              err = 0;
408✔
214
  uv_process_options_t options = {0};
408✔
215

216
  char path[PATH_MAX] = {0};
408✔
217
  locateXnodedExecFile(path);
408✔
218

219
  xndInfo("xnode mgmt spawn xnoded path: %s", path);
408✔
220
  // char *argsXnoded[] = {path, "-c", configDir, "-d", dnodeId, NULL};
221
  char *argsXnoded[] = {path, NULL};
408✔
222
  options.args = argsXnoded;
408✔
223
  options.file = path;
408✔
224

225
  options.exit_cb = xnodeMgmtXnodedExit;
408✔
226

227
  killPreXnoded();
408✔
228

229
  char xnodedPipeSocket[PATH_MAX] = {0};
408✔
230
  getXnodedPipeName(xnodedPipeSocket, PATH_MAX);
408✔
231
  if (0 != unlink(xnodedPipeSocket)) {
408✔
232
    xndWarn("txnode failed to unlink, ignore if first time, socket: %s, detail:%s", xnodedPipeSocket, terrstr());
408✔
233
  }
234

235
  TAOS_UV_LIB_ERROR_RET(uv_pipe_init(&pData->loop, &pData->ctrlPipe, 1));
408✔
236

237
  uv_stdio_container_t child_stdio[3];
408✔
238
  child_stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
408✔
239
  child_stdio[0].data.stream = (uv_stream_t *)&pData->ctrlPipe;
408✔
240
  child_stdio[1].flags = UV_IGNORE;
408✔
241
  child_stdio[2].flags = UV_INHERIT_FD;
408✔
242
  child_stdio[2].data.fd = 2;
408✔
243
  options.stdio_count = 3;
408✔
244
  options.stdio = child_stdio;
408✔
245

246
  options.flags = UV_PROCESS_DETACHED;
408✔
247

248
  char xnodedCfgDir[PATH_MAX + 32] = {0};
408✔
249
  snprintf(xnodedCfgDir, PATH_MAX + 32, "%s=%s", "XNODED_CFG_DIR", configDir);
408✔
250
  char xnodedLogDir[PATH_MAX + 32] = {0};
408✔
251
  snprintf(xnodedLogDir, PATH_MAX + 32, "%s=%s", "XNODED_LOG_DIR", tsLogDir);
408✔
252
  char dnodeIdEnvItem[128] = {0};
408✔
253
  snprintf(dnodeIdEnvItem, 128, "%s=%s:%d", "XNODED_LEADER_EP", pData->leaderEp.fqdn, pData->leaderEp.port);
408✔
254
  char xnodedUserPass[XNODE_USER_PASS_LEN + 32] = {0};
408✔
255
  if (pData->userPass[0] != '\0') {
408✔
256
    snprintf(xnodedUserPass, XNODE_USER_PASS_LEN + 32, "%s=%s", "XNODED_USER_PASS", pData->userPass);
252✔
257
  }
258
  char xnodedToken[TSDB_TOKEN_LEN + 32] = {0};
408✔
259
  if (pData->token[0] != '\0') {
408✔
260
    snprintf(xnodedToken, TSDB_TOKEN_LEN + 32, "%s=%s", "XNODED_TOKEN", pData->token);
156✔
261
  }
262
  char xnodeClusterId[64] = {0};
408✔
263
  snprintf(xnodeClusterId, 64, "%s=%" PRIu64, "XNODED_CLUSTER_ID", pData->clusterId);
408✔
264
  char xnodePipeSocket[PATH_MAX + 32] = {0};
408✔
265
  snprintf(xnodePipeSocket, PATH_MAX + 32, "%s=%s", "XNODED_LISTEN", xnodedPipeSocket);
408✔
266

267
  char xnodedLogLevel[32] = {0};
408✔
268
  if (xndDebugFlag & DEBUG_INFO) {
408✔
269
    snprintf(xnodedLogLevel, 32, "%s=%s", "XNODED_LOG_LEVEL", "info");
408✔
270
  }
271
  if (xndDebugFlag & DEBUG_DEBUG) {
408✔
UNCOV
272
    snprintf(xnodedLogLevel, 32, "%s=%s", "XNODED_LOG_LEVEL", "debug");
×
273
  }
274
  if (xndDebugFlag & DEBUG_TRACE) {
408✔
UNCOV
275
    snprintf(xnodedLogLevel, 32, "%s=%s", "XNODED_LOG_LEVEL", "trace");
×
276
  }
277

278
  xndDebug("txnode env: leader ep: %s, pipe socket:%s, log level:%s, cluster_id: %s", dnodeIdEnvItem, xnodePipeSocket,
408✔
279
           xnodedLogLevel, xnodeClusterId);
280

281
  char *envXnoded[] = {xnodedCfgDir,    xnodedLogDir,   dnodeIdEnvItem,
408✔
282
                       xnodedUserPass,  xnodedToken,    xnodeClusterId,
283
                       xnodePipeSocket, xnodedLogLevel, NULL};
284

285
  char **envXnodedWithPEnv = NULL;
408✔
286
  if (environ != NULL) {
408✔
287
    int32_t lenEnvXnoded = ARRAY_SIZE(envXnoded);
408✔
288
    int32_t numEnviron = 0;
408✔
289
    while (environ[numEnviron] != NULL) {
12,648✔
290
      numEnviron++;
12,240✔
291
    }
292

293
    envXnodedWithPEnv = (char **)taosMemoryCalloc(numEnviron + lenEnvXnoded, sizeof(char *));
408✔
294
    if (envXnodedWithPEnv == NULL) {
408✔
UNCOV
295
      err = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
296
      goto _OVER;
×
297
    }
298

299
    for (int32_t i = 0; i < numEnviron; i++) {
12,648✔
300
      int32_t len = strlen(environ[i]) + 1;
12,240✔
301
      xndDebug("xnoded exec env: %s", environ[i]);
12,240✔
302
      envXnodedWithPEnv[i] = (char *)taosMemoryCalloc(len, 1);
12,240✔
303
      if (envXnodedWithPEnv[i] == NULL) {
12,240✔
UNCOV
304
        err = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
305
        goto _OVER;
×
306
      }
307

308
      tstrncpy(envXnodedWithPEnv[i], environ[i], len);
12,240✔
309
    }
310

311
    for (int32_t i = 0, j = 0; i < lenEnvXnoded; i++) {
4,080✔
312
      if (envXnoded[i] != NULL && envXnoded[i][0] != '\0') {
3,672✔
313
        int32_t len = strlen(envXnoded[i]) + 1;
2,856✔
314
        envXnodedWithPEnv[numEnviron + j] = (char *)taosMemoryCalloc(len, 1);
2,856✔
315
        if (envXnodedWithPEnv[numEnviron + j] == NULL) {
2,856✔
UNCOV
316
          err = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
317
          goto _OVER;
×
318
        }
319
        tstrncpy(envXnodedWithPEnv[numEnviron + j], envXnoded[i], len);
2,856✔
320
        j++;
2,856✔
321
      } 
322
    }
323
    envXnodedWithPEnv[numEnviron + lenEnvXnoded - 1] = NULL;
408✔
324

325
    options.env = envXnodedWithPEnv;
408✔
326
  } else {
UNCOV
327
    options.env = envXnoded;
×
328
  }
329

330
  err = uv_spawn(&pData->loop, &pData->process, &options);
408✔
331
  pData->process.data = (void *)pData;
408✔
332
  if (err != 0) {
408✔
333
    xndError("can not spawn xnoded. path: %s, error: %s", path, uv_strerror(err));
408✔
334
  } else {
UNCOV
335
    xndInfo("xnoded is initialized, xnoded pid: %d", pData->process.pid);
×
UNCOV
336
    saveXnodedPid(pData->process.pid);
×
337
  }
338

339
_OVER:
408✔
340
  if (envXnodedWithPEnv != NULL) {
408✔
341
    int32_t i = 0;
408✔
342
    while (envXnodedWithPEnv[i] != NULL) {
15,504✔
343
      taosMemoryFree(envXnodedWithPEnv[i]);
15,096✔
344
      i++;
15,096✔
345
    }
346
    taosMemoryFree(envXnodedWithPEnv);
408✔
347
  }
348

349
  return err;
408✔
350
}
351

UNCOV
352
static void xnodeMgmtXnodedCloseWalkCb(uv_handle_t *handle, void *arg) {
×
UNCOV
353
  TAOS_XNODED_MGMT_CHECK_PTR_RVOID(handle);
×
UNCOV
354
  if (!uv_is_closing(handle)) {
×
NEW
355
    xndDebug("xnoded closing handle type:%d, ptr:%p", handle->type, handle);
×
UNCOV
356
    uv_close(handle, NULL);
×
357
  }
358
}
359

UNCOV
360
static void xnodeMgmtXnodedStopAsyncCb(uv_async_t *async) {
×
UNCOV
361
  TAOS_XNODED_MGMT_CHECK_PTR_RVOID(async);
×
UNCOV
362
  SXnodedData *pData = async->data;
×
UNCOV
363
  uv_stop(&pData->loop);
×
364
}
365

366
static void xnodeMgmtWatchXnoded(void *args) {
204✔
367
  TAOS_XNODED_MGMT_CHECK_PTR_RVOID(args);
408✔
368
  SXnodedData *pData = args;
204✔
369
  TAOS_UV_CHECK_ERRNO(uv_loop_init(&pData->loop));
204✔
370
  TAOS_UV_CHECK_ERRNO(uv_async_init(&pData->loop, &pData->stopAsync, xnodeMgmtXnodedStopAsyncCb));
204✔
371
  pData->stopAsync.data = pData;
204✔
372
  TAOS_UV_CHECK_ERRNO(xnodeMgmtSpawnXnoded(pData));
204✔
373
  atomic_store_32(&pData->spawnErr, 0);
×
374
  (void)uv_barrier_wait(&pData->barrier);
×
375
  int32_t num = uv_run(&pData->loop, UV_RUN_DEFAULT);
×
UNCOV
376
  xndInfo("xnoded loop exit with %d active handles, line:%d", num, __LINE__);
×
377

UNCOV
378
  uv_walk(&pData->loop, xnodeMgmtXnodedCloseWalkCb, NULL);
×
UNCOV
379
  num = uv_run(&pData->loop, UV_RUN_DEFAULT);
×
UNCOV
380
  xndInfo("xnoded loop exit with %d active handles, line:%d", num, __LINE__);
×
UNCOV
381
  if (uv_loop_close(&pData->loop) != 0) {
×
UNCOV
382
    xndError("xnoded loop close failed, lino:%d", __LINE__);
×
383
  }
UNCOV
384
  return;
×
385

386
_exit:
204✔
387
  if (terrno != 0) {
204✔
388
    (void)uv_barrier_wait(&pData->barrier);
204✔
389
    atomic_store_32(&pData->spawnErr, terrno);
204✔
390
    if (uv_loop_close(&pData->loop) != 0) {
204✔
391
      xndError("xnoded loop close failed, lino:%d", __LINE__);
204✔
392
    }
393

394
    xndError("xnoded thread exit with code:%d lino:%d", terrno, __LINE__);
204✔
395
    terrno = TSDB_CODE_XNODE_UV_EXEC_FAILURE;
204✔
396
  }
397
}
398

399
/**
400
 * start xnoded that serves xnode function invocation under dnode startDnodeId
401
 * @param startDnodeId
402
 * @return
403
 */
404
int32_t xnodeMgmtStartXnoded(SXnode *pXnode) {
672✔
405
  int32_t code = 0, lino = 0;
672✔
406

407
  SXnodedData *pData = &xnodedGlobal;
672✔
408
  pData->leaderEp = pXnode->ep;
672✔
409
  if (pData->isStarted) {
672✔
410
    xndInfo("dnode start xnoded already called");
468✔
411
    return 0;
468✔
412
  }
413
  pData->isStarted = true;
204✔
414
  char dnodeId[8] = {0};
204✔
415
  snprintf(dnodeId, sizeof(dnodeId), "%d", pXnode->dnodeId);
204✔
416
  TAOS_CHECK_GOTO(uv_os_setenv("DNODE_ID", dnodeId), &lino, _exit);
204✔
417
  pData->dnodeId = pXnode->dnodeId;
204✔
418
  pData->clusterId = pXnode->clusterId;
204✔
419
  memset(pData->userPass, 0, sizeof(pData->userPass));
204✔
420
  memcpy(pData->userPass, pXnode->userPass, pXnode->upLen);
204✔
421
  memset(pData->token, 0, sizeof(pData->token));
204✔
422
  memcpy(pData->token, pXnode->token, TSDB_TOKEN_LEN);
204✔
423

424
  TAOS_CHECK_GOTO(uv_barrier_init(&pData->barrier, 2), &lino, _exit);
204✔
425
  TAOS_CHECK_GOTO(uv_thread_create(&pData->thread, xnodeMgmtWatchXnoded, pData), &lino, _exit);
204✔
426
  (void)uv_barrier_wait(&pData->barrier);
204✔
427
  uv_sleep(100);
204✔
428
  int32_t err = atomic_load_32(&pData->spawnErr);
204✔
429
  if (err != 0) {
204✔
430
    uv_barrier_destroy(&pData->barrier);
204✔
431
    if (uv_async_send(&pData->stopAsync) != 0) {
204✔
UNCOV
432
      xndError("start xnoded: failed to send stop async");
×
433
    }
434
    if (uv_thread_join(&pData->thread) != 0) {
204✔
UNCOV
435
      xndError("start xnoded: failed to join xnoded thread");
×
436
    }
437
    pData->needCleanUp = false;
204✔
438
    xndInfo("xnoded is cleaned up after spawn err");
204✔
439
    TAOS_CHECK_GOTO(err, &lino, _exit);
204✔
440
  } else {
UNCOV
441
    pData->needCleanUp = true;
×
UNCOV
442
    atomic_store_32(&pData->isStopped, 0);
×
443
  }
444
_exit:
204✔
445
  if (code != 0) {
204✔
446
    xndError("xnoded start failed with lino:%d, code:%d, error: %s", code, lino, uv_strerror(code));
204✔
447
  }
448
  return code;
204✔
449
}
450
/**
451
 * stop xnoded
452
 * @return
453
 */
454
void xnodeMgmtStopXnoded(void) {
644,461✔
455
  SXnodedData *pData = &xnodedGlobal;
644,461✔
456
  xndInfo("stopping xnoded, need cleanup:%d, spawn err:%d, isStopped:%d", pData->needCleanUp, pData->spawnErr, atomic_load_32(&pData->isStopped));
644,461✔
457
  if (!pData->needCleanUp || atomic_load_32(&pData->isStopped)) {
644,461✔
458
    return;
644,461✔
459
  }
UNCOV
460
  atomic_store_32(&pData->isStopped, 1);
×
UNCOV
461
  pData->needCleanUp = false;
×
UNCOV
462
  (void)uv_process_kill(&pData->process, SIGTERM);
×
NEW
463
  uv_sleep(1000);
×
UNCOV
464
  uv_barrier_destroy(&pData->barrier);
×
465

NEW
466
  xndInfo("xnoded waiting to clean up");
×
UNCOV
467
  if (uv_thread_join(&pData->thread) != 0) {
×
UNCOV
468
    xndError("stop xnoded: failed to join xnoded thread");
×
469
  }
UNCOV
470
  xndInfo("xnoded is cleaned up");
×
471

UNCOV
472
  pData->isStarted = false;
×
473

UNCOV
474
  return;
×
475
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc