|
1 | 1 | /* SPDX-License-Identifier: MIT */
|
2 | 2 |
|
3 |
| -// For `execProg` (Windows is its special little snowflake again) |
4 |
| -#if !defined(_MSC_VER) && !defined(__MINGW32__) |
5 |
| - #include <sys/stat.h> |
6 |
| - #include <sys/wait.h> |
7 |
| - |
8 |
| - #include <signal.h> |
9 |
| - #include <spawn.h> |
10 |
| - #include <unistd.h> |
11 |
| -#else |
12 |
| - #define WIN32_LEAN_AND_MEAN // Include less from `windows.h` to avoid conflicts |
13 |
| - #include <windows.h> |
14 |
| - #include <errhandlingapi.h> |
15 |
| - #include <processthreadsapi.h> |
16 |
| - #undef max // This macro conflicts with `std::numeric_limits<...>::max()` |
17 |
| -#endif |
18 |
| - |
19 | 3 | #include <algorithm>
|
20 | 4 | #include <array>
|
21 | 5 | #include <cassert>
|
|
34 | 18 |
|
35 | 19 | #include "gfx/rgba.hpp" // Reused from RGBGFX
|
36 | 20 |
|
| 21 | +// For `execProg` (Windows and POSIX spawn child processes differently) |
| 22 | +#if !defined(_MSC_VER) && !defined(__MINGW32__) |
| 23 | + #include <sys/stat.h> |
| 24 | + #include <sys/wait.h> |
| 25 | + |
| 26 | + #include <signal.h> |
| 27 | + #include <spawn.h> |
| 28 | + #include <unistd.h> |
| 29 | +#else |
| 30 | + #define WIN32_LEAN_AND_MEAN // Include less from `windows.h` to avoid conflicts |
| 31 | + #include <windows.h> |
| 32 | + #include <errhandlingapi.h> |
| 33 | + #include <processthreadsapi.h> |
| 34 | + #undef max // This macro conflicts with `std::numeric_limits<...>::max()` |
| 35 | +#endif |
| 36 | + |
37 | 37 | static uintmax_t nbErrors;
|
38 | 38 |
|
39 | 39 | static void warning(char const *fmt, ...) {
|
@@ -308,23 +308,13 @@ static char *execProg(char const *name, char * const *argv) {
|
308 | 308 | return strerror(err);
|
309 | 309 | }
|
310 | 310 |
|
311 |
| - siginfo_t info; |
312 |
| - if (waitid(P_PID, pid, &info, WEXITED) != 0) { |
| 311 | + if (int info; waitpid(pid, &info, 0) == -1 || !WIFEXITED(info)) { |
313 | 312 | fatal("Error waiting for %s: %s", name, strerror(errno));
|
314 |
| - } else if (info.si_code != CLD_EXITED) { |
315 |
| - assert(info.si_code == CLD_KILLED || info.si_code == CLD_DUMPED); |
316 |
| - fatal( |
317 |
| - "%s was terminated by signal %s%s\n\tThe command was: [%s]", |
318 |
| - name, |
319 |
| - strsignal(info.si_status), |
320 |
| - info.si_code == CLD_DUMPED ? " (core dumped)" : "", |
321 |
| - formatArgv() |
322 |
| - ); |
323 |
| - } else if (info.si_status != 0) { |
| 313 | + } else if (int status = WEXITSTATUS(info); status != 0) { |
324 | 314 | fatal(
|
325 | 315 | "%s returned with status %d\n\tThe command was: [%s]",
|
326 | 316 | name,
|
327 |
| - info.si_status, |
| 317 | + status, |
328 | 318 | formatArgv()
|
329 | 319 | );
|
330 | 320 | }
|
@@ -359,26 +349,7 @@ static char *execProg(char const *name, char * const *argv) {
|
359 | 349 |
|
360 | 350 | STARTUPINFOA startupInfo;
|
361 | 351 | GetStartupInfoA(&startupInfo);
|
362 |
| - STARTUPINFOA childStartupInfo{ |
363 |
| - sizeof(startupInfo), |
364 |
| - nullptr, |
365 |
| - nullptr, |
366 |
| - nullptr, |
367 |
| - 0, |
368 |
| - 0, |
369 |
| - 0, |
370 |
| - 0, |
371 |
| - 0, |
372 |
| - 0, |
373 |
| - 0, |
374 |
| - 0, |
375 |
| - 0, |
376 |
| - 0, |
377 |
| - nullptr, |
378 |
| - 0, |
379 |
| - 0, |
380 |
| - 0, |
381 |
| - }; |
| 352 | + STARTUPINFOA childStartupInfo = {sizeof(startupInfo)}; |
382 | 353 |
|
383 | 354 | PROCESS_INFORMATION child;
|
384 | 355 | if (CreateProcessA(
|
|
0 commit comments