* Fixes #6929

* TIL macOS symbols are case insensitive

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-11-14 11:14:11 +01:00
committed by GitHub
parent 24b4b2c16d
commit d4628992d8
5 changed files with 43 additions and 4 deletions

View File

@@ -72,9 +72,27 @@ pub fn setThreadName(name: StringTypes.stringZ) void {
}
}
const ExitFn = *const fn () callconv(.C) void;
var on_exit_callbacks = std.ArrayListUnmanaged(ExitFn){};
export fn Bun__atexit(function: ExitFn) void {
if (std.mem.indexOfScalar(ExitFn, on_exit_callbacks.items, function) == null) {
on_exit_callbacks.append(bun.default_allocator, function) catch {};
}
}
pub fn runExitCallbacks() void {
for (on_exit_callbacks.items) |callback| {
callback();
}
on_exit_callbacks.items.len = 0;
}
/// Flushes stdout and stderr and exits with the given code.
pub fn exit(code: u8) noreturn {
runExitCallbacks();
Output.flush();
std.mem.doNotOptimizeAway(&Bun__atexit);
std.c._exit(code);
}

View File

@@ -94,6 +94,8 @@ static void uv__tty_make_raw(struct termios* tio)
#endif
extern "C" void Bun__atexit(void (*func)(void));
extern "C" int Bun__ttySetMode(int fd, int mode)
{
#if !OS(WINDOWS)
@@ -138,7 +140,7 @@ extern "C" int Bun__ttySetMode(int fd, int mode)
tmp.c_cc[VTIME] = 0;
std::call_once(reset_once_flag, [] {
atexit([] {
Bun__atexit([] {
uv_tty_reset_mode();
});
});
@@ -147,7 +149,7 @@ extern "C" int Bun__ttySetMode(int fd, int mode)
uv__tty_make_raw(&tmp);
std::call_once(reset_once_flag, [] {
atexit([] {
Bun__atexit([] {
uv_tty_reset_mode();
});
});

View File

@@ -407,8 +407,9 @@ pub const ExitHandler = struct {
JSC.markBinding(@src());
var vm = @fieldParentPtr(VirtualMachine, "exit_handler", this);
Process__dispatchOnExit(vm.global, this.exit_code);
if (vm.isMainThread())
if (vm.isMainThread()) {
Bun__closeAllSQLiteDatabasesForTermination();
}
}
pub fn dispatchOnBeforeExit(this: *ExitHandler) void {

View File

@@ -312,7 +312,7 @@ pub noinline fn handleCrash(signal: i32, addr: usize) void {
if (error_return_trace) |trace| {
std.debug.dumpStackTrace(trace.*);
}
Global.runExitCallbacks();
std.c._exit(128 + @as(u8, @truncate(@as(u8, @intCast(@max(signal, 0))))));
}

View File

@@ -0,0 +1,18 @@
const onlyCheck = process.env.ONLY_CHECK_TTY === "0";
import { dlopen, ptr } from "bun:ffi";
const suffix = process.platform === "darwin" ? "dylib" : "so.6";
const { tcgetattr, tcsetattr } = dlopen(`libc.${suffix}`, {
"tcgetattr": {
"args": ["int", "pointer"],
"result": "int",
},
}).symbols;
var termios = new Buffer(256);
var dataView = new DataView(termios.buffer);
const rc = tcgetattr(0, dataView);
if (rc === 0) {
throw new Error("tcgetattr failed");
}
await Bun.write(1, termios.toString("hex"));