diff options
author | 2022-11-03 23:38:07 -0700 | |
---|---|---|
committer | 2022-11-03 23:38:07 -0700 | |
commit | 30e1fe1035b0e18c16401f447b446f2fc94c167b (patch) | |
tree | 21a87169737f4b6758021d73e85f5871065c258b | |
parent | 562595fa02bf68b437505c0a547a6a9d14eb78d4 (diff) | |
download | bun-30e1fe1035b0e18c16401f447b446f2fc94c167b.tar.gz bun-30e1fe1035b0e18c16401f447b446f2fc94c167b.tar.zst bun-30e1fe1035b0e18c16401f447b446f2fc94c167b.zip |
Fix incorrect exit code
-rw-r--r-- | src/bun.js/api/bun/subprocess.zig | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 0a7a83ae0..e9c679bd6 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1201,15 +1201,21 @@ pub const Subprocess = struct { .err => |err| { this.waitpid_err = err; }, - .result => |status| { - this.exit_code = @truncate(u8, status.status); - // Do WEXITSTATUS macro check: https://linux.die.net/man/3/waitpid - // https://code.woboq.org/gtk/include/bits/waitstatus.h.html - const w_if_exited = (status.status & 0x7f) == 0; - if (w_if_exited) { - const w_exit_status = (status.status & 0xff00) >> 8; - this.exit_code = @truncate(u8, w_exit_status); - } + .result => |result| { + this.exit_code = @truncate( + u8, + brk: { + if (std.os.W.IFEXITED(result.status)) { + break :brk std.os.W.EXITSTATUS(result.status); + } else if (std.os.W.IFSIGNALED(result.status)) { + break :brk std.os.W.TERMSIG(result.status); + } else if (std.os.W.IFSTOPPED(result.status)) { + break :brk std.os.W.STOPSIG(result.status); + } else { + break :brk 1; + } + }, + ); }, } |