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