Fast real-process probes for the async index-supervisor contract. They run * only in a child admitted by the exact build-bound worker grammar. */
| 182 | /* Fast real-process probes for the async index-supervisor contract. They run |
| 183 | * only in a child admitted by the exact build-bound worker grammar. */ |
| 184 | static void tf_index_worker_probe(const char *args_json, const char *response_out) { |
| 185 | if (!args_json || !strstr(args_json, "\"__cbm_test_worker\"")) { |
| 186 | return; |
| 187 | } |
| 188 | if (strstr(args_json, "\"clean\"")) { |
| 189 | FILE *response = response_out ? cbm_fopen(response_out, "wb") : NULL; |
| 190 | if (response) { |
| 191 | (void)fputs("{\"probe\":\"clean\"}", response); |
| 192 | (void)fclose(response); |
| 193 | } |
| 194 | (void)fprintf(stderr, "async worker clean probe\n"); |
| 195 | fflush(NULL); |
| 196 | _Exit(response ? 0 : 1); |
| 197 | } |
| 198 | if (strstr(args_json, "\"crash\"")) { |
| 199 | (void)fprintf(stderr, "async worker crash probe\n"); |
| 200 | fflush(NULL); |
| 201 | abort(); |
| 202 | } |
| 203 | if (strstr(args_json, "\"oversize\"")) { |
| 204 | FILE *response = response_out ? cbm_fopen(response_out, "wb") : NULL; |
| 205 | bool written = false; |
| 206 | if (response) { |
| 207 | written = |
| 208 | fseek(response, (long)CBM_DAEMON_RUNTIME_APPLICATION_PAYLOAD_MAX, SEEK_SET) == 0 && |
| 209 | fputc('x', response) != EOF; |
| 210 | written = fclose(response) == 0 && written; |
| 211 | } |
| 212 | (void)fprintf(stderr, "async worker oversized response probe\n"); |
| 213 | fflush(NULL); |
| 214 | _Exit(written ? 0 : 1); |
| 215 | } |
| 216 | if (strstr(args_json, "\"hang-tree\"")) { |
| 217 | (void)signal(SIGTERM, SIG_IGN); |
| 218 | long descendant = 0; |
| 219 | #ifndef _WIN32 |
| 220 | pid_t child = fork(); |
| 221 | if (child == 0) { |
| 222 | for (;;) { |
| 223 | cbm_usleep(100000); |
| 224 | } |
| 225 | } |
| 226 | if (child > 0) { |
| 227 | descendant = (long)child; |
| 228 | } |
| 229 | #endif |
| 230 | const char *marker = getenv("CBM_INDEX_MARKER_FILE"); |
| 231 | FILE *ready = marker ? cbm_fopen(marker, "wb") : NULL; |
| 232 | if (ready) { |
| 233 | (void)fprintf( |
| 234 | ready, "single=%s\nmarker=%s\nquarantine=%s\nbudget=%zu\ndescendant=%ld\n", |
| 235 | getenv("CBM_INDEX_SINGLE_THREAD") ? getenv("CBM_INDEX_SINGLE_THREAD") : "", marker, |
| 236 | getenv("CBM_INDEX_QUARANTINE_FILE") ? getenv("CBM_INDEX_QUARANTINE_FILE") : "", |
| 237 | cbm_mem_budget(), descendant); |
| 238 | (void)fclose(ready); |
| 239 | } |
| 240 | (void)fprintf(stderr, "async worker hang-tree probe\n"); |
| 241 | fflush(NULL); |
no test coverage detected