fork() fails with EAGAIN under the same pressure posix_spawn does, and the * fallback path must not be less robust than the primary one. */
| 976 | /* fork() fails with EAGAIN under the same pressure posix_spawn does, and the |
| 977 | * fallback path must not be less robust than the primary one. */ |
| 978 | static pid_t cbm_fork_with_retry(void) { |
| 979 | /* CBM_SPAWN_RETRY_ATTEMPTS backoffs means ATTEMPTS+1 tries. Every try goes |
| 980 | * through the same branch — including the last — so the injection seam |
| 981 | * models production exactly rather than leaving a final unguarded fork() the |
| 982 | * tests could never reach. */ |
| 983 | for (int attempt = 0;; attempt++) { |
| 984 | #ifdef CBM_ENABLE_TEST_SEAMS |
| 985 | if (cbm_spawn_eagain_injected()) { |
| 986 | if (attempt >= CBM_SPAWN_RETRY_ATTEMPTS) { |
| 987 | errno = EAGAIN; |
| 988 | return -1; |
| 989 | } |
| 990 | cbm_spawn_backoff(attempt); |
| 991 | continue; |
| 992 | } |
| 993 | #endif |
| 994 | pid_t pid = fork(); |
| 995 | if (pid >= 0 || (errno != EAGAIN && errno != ENOMEM)) { |
| 996 | return pid; |
| 997 | } |
| 998 | if (attempt >= CBM_SPAWN_RETRY_ATTEMPTS) { |
| 999 | errno = EAGAIN; |
| 1000 | return -1; |
| 1001 | } |
| 1002 | cbm_spawn_backoff(attempt); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | /* Used by the fork+exec child. posix_spawn performs the same reset |
| 1007 | * declaratively via SETSIGDEF + SETSIGMASK, but Apple still forks for the |
no test coverage detected