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

Function subprocess_park_high_fds

tests/test_subprocess.c:1350–1378  ·  view source on GitHub ↗

Park two non-CLOEXEC descriptors near the top of the table; returns the lower * of the two and hands back the original (low) descriptor in *keep_low. The * kernel may cap the table below _SC_OPEN_MAX (macOS: kern.maxfilesperproc), * so the start point halves until F_DUPFD accepts it. */

Source from the content-addressed store, hash-verified

1348 * kernel may cap the table below _SC_OPEN_MAX (macOS: kern.maxfilesperproc),
1349 * so the start point halves until F_DUPFD accepts it. */
1350static int subprocess_park_high_fds(int *keep_low) {
1351 char path[] = "/tmp/cbm-subprocess-highfd-XXXXXX";
1352 int low = cbm_mkstemp(path);
1353 if (low < 0) {
1354 return -1;
1355 }
1356 (void)unlink(path);
1357 long top = sysconf(_SC_OPEN_MAX);
1358 if (top <= 0 || top > 1048576L) {
1359 top = 1048576L;
1360 }
1361 int high = -1;
1362 for (long base = top - 4; high < 0 && base > 64; base /= 2) {
1363 high = fcntl(low, F_DUPFD, (int)base);
1364 }
1365 int higher = high >= 0 ? fcntl(low, F_DUPFD, high + 1) : -1;
1366 if (higher != high + 1) {
1367 (void)close(low);
1368 if (high >= 0) {
1369 (void)close(high);
1370 }
1371 if (higher >= 0) {
1372 (void)close(higher);
1373 }
1374 return -1;
1375 }
1376 *keep_low = low;
1377 return high;
1378}
1379#endif
1380
1381TEST(subprocess_child_close_fds_uses_one_syscall_not_rlimit_loop) {

Callers 1

test_subprocess.cFile · 0.85

Calls 2

cbm_mkstempFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected