| 3033 | /* ── Kill other MCP server instances ──────────────────────────── */ |
| 3034 | |
| 3035 | static int cbm_kill_other_instances(void) { |
| 3036 | #ifdef _WIN32 |
| 3037 | /* taskkill /IM kills ALL matching processes INCLUDING self. |
| 3038 | * Use /FI filter to exclude our own PID. */ |
| 3039 | char pid_filter[CBM_SZ_64]; |
| 3040 | snprintf(pid_filter, sizeof(pid_filter), "PID ne %lu", (unsigned long)GetCurrentProcessId()); |
| 3041 | const char *argv[] = {"taskkill", "/F", "/FI", "IMAGENAME eq codebase-memory-mcp.exe", |
| 3042 | "/FI", pid_filter, NULL}; |
| 3043 | (void)cbm_exec_no_shell(argv); |
| 3044 | return 0; |
| 3045 | #else |
| 3046 | int killed = 0; |
| 3047 | pid_t self = getpid(); |
| 3048 | FILE *fp = cbm_popen("pgrep -x codebase-memory-mcp", "r"); |
| 3049 | if (!fp) { |
| 3050 | return 0; |
| 3051 | } |
| 3052 | char line[CLI_BUF_32]; |
| 3053 | while (fgets(line, sizeof(line), fp)) { |
| 3054 | pid_t pid = (pid_t)strtol(line, NULL, CLI_STRTOL_BASE); |
| 3055 | if (pid > 0 && pid != self) { |
| 3056 | if (kill(pid, SIGTERM) == 0) { |
| 3057 | killed++; |
| 3058 | } |
| 3059 | } |
| 3060 | } |
| 3061 | cbm_pclose(fp); |
| 3062 | return killed; |
| 3063 | #endif |
| 3064 | } |
| 3065 | |
| 3066 | /* Download checksums.txt and verify the archive integrity. |
| 3067 | * Returns: 0 = verified OK, 1 = mismatch (FAIL), -1 = could not verify (warning). */ |
no test coverage detected