summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/main.zig b/src/main.zig
index ada5f3b9..f9118dfc 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -44,7 +44,10 @@ fn logFn(
pub const panic = if (is_emscripten) std.debug.FullPanic(std.debug.defaultPanic) else std.debug.FullPanic(struct {
fn call(msg: []const u8, ret_addr: ?usize) noreturn {
- if (!recovering.swap(true, .seq_cst)) @import("vaxis").recover();
+ if (!recovering.swap(true, .seq_cst)) {
+ pardes.replica.dying();
+ @import("vaxis").recover();
+ }
@import("crash.zig").record(msg);
std.debug.defaultPanic(msg, ret_addr);
}
@@ -54,7 +57,10 @@ var recovering: std.atomic.Value(bool) = .init(false);
pub const debug = if (is_emscripten) struct {} else struct {
pub fn handleSegfault(addr: ?usize, name: []const u8, opt_ctx: anytype) noreturn {
- if (!recovering.swap(true, .seq_cst)) @import("vaxis").recover();
+ if (!recovering.swap(true, .seq_cst)) {
+ pardes.replica.dying();
+ @import("vaxis").recover();
+ }
return std.debug.defaultHandleSegfault(addr, name, opt_ctx);
}
};
@@ -883,6 +889,7 @@ fn nativeMain(std_init: std.process.Init) !void {
}
extern "c" fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
+extern "c" fn atexit(f: *const fn () callconv(.c) void) c_int;
/// `pardes --ps`: what the per-user daemon keeps, as a tree; `--kill=<name>`
/// and `--kill-all`: those sessions ended with their shells, a TERM and,
@@ -1050,38 +1057,42 @@ fn remoteAttach(init: std.process.Init, opts: pardes.Options, where: []const u8,
const pid = std.c.fork();
if (pid < 0) Say.no(io, "no fork for ssh", .{});
if (pid == 0) {
+ // A client killed outright takes its ssh with it.
+ daemon.hupOnStubDeath(true);
const null_fd = std.c.open("/dev/null", .{ .ACCMODE = .RDONLY }, @as(std.c.mode_t, 0));
if (null_fd >= 0) _ = std.c.dup2(null_fd, 0);
_ = execvp(argv[0].?, &argv);
std.c._exit(127);
}
+ // Ended at the client's exit, whatever path it takes there (its own
+ // words on a refused redial exit from inside it). ponytail: a client
+ // that crashes leaves its socket's file behind; its ssh goes.
const Ssh = struct {
var child: std.c.pid_t = 0;
var path: [:0]const u8 = "";
- fn end() void {
- _ = std.c.kill(child, .TERM);
- _ = std.c.waitpid(child, null, 0);
+ fn end() callconv(.c) void {
+ if (child > 0) {
+ _ = std.c.kill(child, .TERM);
+ _ = std.c.waitpid(child, null, 0);
+ }
_ = std.c.unlink(path);
}
};
Ssh.child = pid;
Ssh.path = here;
+ _ = atexit(Ssh.end);
var waited: u32 = 0;
while (std.c.access(here, std.c.F_OK) != 0) : (waited += 1) {
var status: c_int = 0;
- if (std.c.waitpid(pid, &status, std.c.W.NOHANG) == pid) Say.no(io, "ssh to {s} ended before its forward was up", .{where});
- if (waited > 3000) {
- Ssh.end();
- Say.no(io, "ssh to {s} set up no forward in 30 s", .{where});
+ if (std.c.waitpid(pid, &status, std.c.W.NOHANG) == pid) {
+ Ssh.child = 0;
+ Say.no(io, "ssh to {s} ended before its forward was up", .{where});
}
+ if (waited > 3000) Say.no(io, "ssh to {s} set up no forward in 30 s", .{where});
const ts: std.c.timespec = .{ .sec = 0, .nsec = 10 * std.time.ns_per_ms };
_ = std.c.nanosleep(&ts, null);
}
- clientOf(init, opts, here, name, true) catch |err| {
- Ssh.end();
- Say.no(io, "{t}", .{err});
- };
- Ssh.end();
+ clientOf(init, opts, here, name, true) catch |err| Say.no(io, "{t}", .{err});
std.process.exit(0);
}