fork() fails with EAGAIN under the same pressure posix_spawn does, and the * fallback path must not be less robust than the primary one. */
| 929 | /* fork() fails with EAGAIN under the same pressure posix_spawn does, and the |
| 930 | * fallback path must not be less robust than the primary one. */ |
| 931 | static pid_t cbm_fork_with_retry(void) { |
| 932 | /* CBM_SPAWN_RETRY_ATTEMPTS backoffs means ATTEMPTS+1 tries. Every try goes |
| 933 | * through the same branch — including the last — so the injection seam |
| 934 | * models production exactly rather than leaving a final unguarded fork() the |
| 935 | * tests could never reach. */ |
| 936 | for (int attempt = 0;; attempt++) { |
| 937 | #ifdef CBM_ENABLE_TEST_SEAMS |
| 938 | if (cbm_spawn_eagain_injected()) { |
| 939 | if (attempt >= CBM_SPAWN_RETRY_ATTEMPTS) { |
| 940 | errno = EAGAIN; |
| 941 | return -1; |
| 942 | } |
| 943 | cbm_spawn_backoff(attempt); |
| 944 | continue; |
| 945 | } |
| 946 | #endif |
| 947 | pid_t pid = fork(); |
| 948 | if (pid >= 0 || (errno != EAGAIN && errno != ENOMEM)) { |
| 949 | return pid; |
| 950 | } |
| 951 | if (attempt >= CBM_SPAWN_RETRY_ATTEMPTS) { |
| 952 | errno = EAGAIN; |
| 953 | return -1; |
| 954 | } |
| 955 | cbm_spawn_backoff(attempt); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /* Used by the fork+exec child. posix_spawn performs the same reset |
| 960 | * declaratively via SETSIGDEF + SETSIGMASK, but Apple still forks for the |
no test coverage detected