fork() fails with EAGAIN under the same pressure posix_spawn does, and the * fallback path must not be less robust than the primary one. */
| 1361 | /* fork() fails with EAGAIN under the same pressure posix_spawn does, and the |
| 1362 | * fallback path must not be less robust than the primary one. */ |
| 1363 | static pid_t cbm_fork_with_retry(void) { |
| 1364 | /* CBM_SPAWN_RETRY_ATTEMPTS backoffs means ATTEMPTS+1 tries. Every try goes |
| 1365 | * through the same branch — including the last — so the injection seam |
| 1366 | * models production exactly rather than leaving a final unguarded fork() the |
| 1367 | * tests could never reach. */ |
| 1368 | for (int attempt = 0;; attempt++) { |
| 1369 | #ifdef CBM_ENABLE_TEST_SEAMS |
| 1370 | if (cbm_spawn_eagain_injected()) { |
| 1371 | if (attempt >= CBM_SPAWN_RETRY_ATTEMPTS) { |
| 1372 | errno = EAGAIN; |
| 1373 | return -1; |
| 1374 | } |
| 1375 | cbm_spawn_backoff(attempt); |
| 1376 | continue; |
| 1377 | } |
| 1378 | #endif |
| 1379 | pid_t pid = fork(); |
| 1380 | if (pid >= 0 || (errno != EAGAIN && errno != ENOMEM)) { |
| 1381 | return pid; |
| 1382 | } |
| 1383 | if (attempt >= CBM_SPAWN_RETRY_ATTEMPTS) { |
| 1384 | errno = EAGAIN; |
| 1385 | return -1; |
| 1386 | } |
| 1387 | cbm_spawn_backoff(attempt); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | /* Used by the fork+exec child. posix_spawn performs the same reset |
| 1392 | * declaratively via SETSIGDEF + SETSIGMASK, but Apple still forks for the |
no test coverage detected