From 3150b21d3979e0a7e816c806b9f8162e59a4597b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 28 Dec 2023 06:19:18 -0800 Subject: cygwin: run, sh: mangle termination status word. * stream.c (run): On Cygwin, the spawnvp function is returning a 16 bit termination status word where the upper 8 bits is the termination status if the termination is normal, otherwise the lower 8 bits holds a termination signal. Let's massage it so that the function returns an integer termnation status, or nil if the termination was abnormal, same as we do on POSIX platforms with fork/wait. --- stream.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stream.c b/stream.c index d1d615e9..bf90613e 100644 --- a/stream.c +++ b/stream.c @@ -4750,6 +4750,16 @@ static val run(val command, val args) status = _wspawnvp(_P_WAIT, c_str(command, self), wargv); #else status = w_spawnvp(_P_WAIT, c_str(command, self), nargs, wargv); +#endif +#ifdef __CYGWIN__ + /* Cygwin spawnvp reports regular termination status in upper 8 bits, and + * termination signal in lower 8 bits. Let's massage it so that we produce + * the same behavior as on Linux. + */ + if (status && status < 0x100) + status = -1; /* ensure nil return */ + else + status >>= 8; #endif } -- cgit v1.2.3