|
1 | 1 | import |
2 | | - std/[strformat, strutils, osproc, posix, posix_utils], |
3 | | - ../../common/[start_utils, types, trace_index], |
| 2 | + std/[strformat, strutils, osproc, posix, posix_utils, os, options], |
| 3 | + ../../common/[start_utils, types, trace_index, paths, config], |
4 | 4 | ../utilities/[env], |
5 | 5 | ../cli/[logging], |
6 | 6 | cleanup |
7 | 7 |
|
8 | 8 | var coreProcessId* = -1 |
9 | 9 |
|
| 10 | +proc startBackend*(backendKind: string, isStdio: bool, socketPath: Option[string]) = |
| 11 | + let backendExe = |
| 12 | + if backendKind == "db": |
| 13 | + dbBackendExe |
| 14 | + elif backendKind == "rr": |
| 15 | + let ctConfig = loadConfig(folder=getCurrentDir(), inTest=false) |
| 16 | + if ctConfig.rrBackend.enabled: |
| 17 | + ctConfig.rrBackend.path |
| 18 | + else: |
| 19 | + echo "ERROR: rr backend not enabled!" |
| 20 | + quit(1) |
| 21 | + else: |
| 22 | + echo "ERROR: Backend kind not recognized, needs to be 'rr' or 'db'" |
| 23 | + quit(1) |
| 24 | + |
| 25 | + let args = |
| 26 | + if isStdio: |
| 27 | + @["--stdio"] |
| 28 | + elif socketPath.isSome: |
| 29 | + @[socketPath.get()] |
| 30 | + else: |
| 31 | + echo "ERRROR: Needs to have either --stdio or a valid socket path" |
| 32 | + quit(1) |
| 33 | + |
| 34 | + let process = startProcess( |
| 35 | + backendExe, |
| 36 | + args = args, |
| 37 | + options = { poParentStreams } |
| 38 | + ) |
| 39 | + |
| 40 | + coreProcessId = process.processId |
| 41 | + onSignal(SIGTERM): |
| 42 | + if coreProcessId != -1: |
| 43 | + echo "ct: stopping core process" |
| 44 | + sendSignal(coreProcessId.Pid, SIGTERM) |
| 45 | + |
| 46 | + let code = waitForExit(process) |
| 47 | + quit(code) |
| 48 | + |
10 | 49 | proc startCore*(traceArg: string, callerPid: int, test: bool) = |
11 | 50 | # start_core <trace-program-pattern> <caller-pid> [--test] |
12 | 51 | let recordCore = envLoadRecordCore() |
|
0 commit comments