MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sp_stdin_probe

Function sp_stdin_probe

tests/test_subprocess.c:2227–2327  ·  view source on GitHub ↗

Dispatched through the existing early native probe entry, before harness setup. */

Source from the content-addressed store, hash-verified

2225
2226/* Dispatched through the existing early native probe entry, before harness setup. */
2227static int sp_stdin_probe(int argc, char **argv) {
2228#ifdef _WIN32
2229 if (_setmode(cbm_fileno(stdin), _O_BINARY) == -1 ||
2230 _setmode(cbm_fileno(stdout), _O_BINARY) == -1 ||
2231 _setmode(cbm_fileno(stderr), _O_BINARY) == -1)
2232 return 101;
2233#endif
2234 if (argc == 8 && strcmp(argv[2], "reject") == 0) {
2235 sp_stdin_rejection_t check =
2236 sp_stdin_check_rejection(argv[0], argv[3], argv[4], argv[5], argv[6], argv[7]);
2237 if (!check.safe_cleanup)
2238 return 125; /* Parent must retain files if nested containment failed. */
2239 if (!check.prepared)
2240 return 102;
2241 if (!check.reusable)
2242 return 103;
2243 return check.rejected && check.no_handle && check.outputs_unchanged && check.no_child_marker
2244 ? 0
2245 : 104;
2246 }
2247 if (argc == 6 && strcmp(argv[2], "parent-eof") == 0) {
2248 /* Isolated process only: furnish genuinely readable parent stdin, then
2249 * verify a NULL stdin_file child still gets the null device. */
2250 FILE *file = cbm_fopen(argv[3], "rb");
2251 if (!file)
2252 return 105;
2253#ifdef _WIN32
2254 int duplicated = _dup2(cbm_fileno(file), cbm_fileno(stdin));
2255#else
2256 int duplicated = dup2(cbm_fileno(file), cbm_fileno(stdin));
2257#endif
2258 bool closed = fclose(file) == 0;
2259 if (duplicated < 0 || !closed)
2260 return 106;
2261#ifdef _WIN32
2262 if (!SetStdHandle(STD_INPUT_HANDLE, (HANDLE)_get_osfhandle(cbm_fileno(stdin))))
2263 return 106;
2264#endif
2265 /* Exercise the descriptor directly: a stdio-buffer-only rewind must not
2266 * leave the inherited OS offset at EOF and make the control vacuous. */
2267 unsigned char witness;
2268#ifdef _WIN32
2269 if (_read(cbm_fileno(stdin), &witness, 1) != 1 ||
2270 _lseek(cbm_fileno(stdin), 0, SEEK_SET) != 0)
2271 return 107;
2272#else
2273 if (read(cbm_fileno(stdin), &witness, 1) != 1 || lseek(cbm_fileno(stdin), 0, SEEK_SET) != 0)
2274 return 107;
2275#endif
2276 const char *child_argv[] = {argv[0], "__cbm_subprocess_stdin_probe", "echo", "", NULL};
2277 cbm_proc_opts_t opts = {.bin = argv[0],
2278 .argv = child_argv,
2279 .stdin_file = NULL,
2280 .stdout_file = argv[4],
2281 .log_file = argv[5],
2282 .quiet_timeout_ms = 10000};
2283 cbm_proc_result_t result = {0};
2284 int rc = cbm_subprocess_run(&opts, &result);

Callers 1

Calls 13

sp_stdin_check_rejectionFunction · 0.85
cbm_fopenFunction · 0.85
_readFunction · 0.85
cbm_subprocess_runFunction · 0.85
sp_stdin_safe_runFunction · 0.85
sp_stdin_cleanFunction · 0.85
sp_stdout_file_equalsFunction · 0.85
sp_stdin_writeFunction · 0.85
fwriteFunction · 0.85
cbm_now_msFunction · 0.85
cbm_file_existsFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected