Run shell-backed query helpers inside the same process-tree containment used * by indexing. A plain popen owns only its shell stream: on disconnect there is * no safe handle with which to stop a blocked git child or its descendants. */
| 10201 | * by indexing. A plain popen owns only its shell stream: on disconnect there is |
| 10202 | * no safe handle with which to stop a blocked git child or its descendants. */ |
| 10203 | static bool mcp_command_output_path(char out[CBM_SZ_2K]) { |
| 10204 | char directory[CBM_SZ_1K]; |
| 10205 | const char *cache = cbm_resolve_cache_dir(); |
| 10206 | int written; |
| 10207 | if (cache && cache[0]) { |
| 10208 | written = snprintf(directory, sizeof(directory), "%s/logs", cache); |
| 10209 | if (written <= 0 || written >= (int)sizeof(directory) || !cbm_mkdir_p(directory, 0700)) { |
| 10210 | return false; |
| 10211 | } |
| 10212 | } else { |
| 10213 | written = snprintf(directory, sizeof(directory), "%s", cbm_tmpdir()); |
| 10214 | if (written <= 0 || written >= (int)sizeof(directory)) { |
| 10215 | return false; |
| 10216 | } |
| 10217 | } |
| 10218 | written = snprintf(out, CBM_SZ_2K, "%s/.mcp-command-XXXXXX", directory); |
| 10219 | if (written <= 0 || written >= CBM_SZ_2K) { |
| 10220 | out[0] = '\0'; |
| 10221 | return false; |
| 10222 | } |
| 10223 | int descriptor = cbm_mkstemp(out); |
| 10224 | if (descriptor < 0) { |
| 10225 | out[0] = '\0'; |
| 10226 | return false; |
| 10227 | } |
| 10228 | #ifdef _WIN32 |
| 10229 | (void)_close(descriptor); |
| 10230 | #else |
| 10231 | (void)close(descriptor); |
| 10232 | #endif |
| 10233 | return true; |
| 10234 | } |
| 10235 | |
| 10236 | #ifdef _WIN32 |
| 10237 | /* Resolve the OS-owned command processor without consulting PATH or mutable |
no test coverage detected