summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/main.zig b/src/main.zig
index 2934aba9..864e2485 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -268,10 +268,11 @@ const cmds = std.EnumArray(Cmd, Doc).init(.{
.group = .Sessions,
.line = "the daemon's sessions, their clients and shells",
.doc =
- \\What the per-user daemon keeps: each session with its name, pid, kind
- \\(tty or gui) and whether one is attached; under it its clients and its
- \\shells; then the shells no session holds, which Adopt takes. /sessions
- \\is the same list, read from inside a session.
+ \\What the per-user daemon lists: each session with its name, pid, kind
+ \\(tty or gui) and whether it has a frontend of its own or is detached;
+ \\under it its clients and its shells; then the shells no session holds,
+ \\which Adopt takes. /sessions is the same list, read from inside a
+ \\session (where a session with a frontend says attached).
,
.examples = &.{.{ "pardes ps", "every session, client and shell" }},
.see = "attach, kill, /sessions",
@@ -283,8 +284,8 @@ const cmds = std.EnumArray(Cmd, Doc).init(.{
.doc =
\\Show a detached session here: in this terminal for pardes, a window
\\for pardes-gui. Bare, the one detached session (with none, the one
- \\session). One attached already, or of the other kind, is joined as a
- \\client. HOST:NAME is a client of session NAME on another machine,
+ \\session). One with a frontend already, or of the other kind, is joined
+ \\as a client. HOST:NAME is a client of session NAME on another machine,
\\over `ssh -L` to its pardes-replica.sock ($PARDES_SSH: the ssh
\\command, default ssh; $PARDES_REMOTE_RUNTIME: its runtime directory,
\\if not this one's path); SOCK:NAME goes through a socket forwarded
@@ -467,7 +468,7 @@ const flags = std.EnumArray(Flag, FlagDoc).init(.{
.@"--9p-tcp" = .{ .arg = "=tcp!IP!PORT", .takes = .eq, .doc = "also serve 9P there, a numeric address" },
.@"--mount" = .{ .arg = "=NAME=DIAL", .takes = .eq, .doc = "a 9P session or Unix/TCP endpoint under /n/NAME; repeat for more; os and self are reserved" },
.@"--geometry" = .{ .arg = "=WxH[+X+Y]", .takes = .eq, .doc = "the window's size in points, and where it goes where the display lets a window say (X11)" },
- .@"--detach" = .{ .arg = "[=NAME]", .takes = .maybe, .doc = "no terminal (no window) until one attaches; panes, shells and files stay; NAME (one path component) rather than the pid. One pardes --daemon per user keeps sessions (PARDES_DAEMON=off: none)" },
+ .@"--detach" = .{ .arg = "[=NAME]", .takes = .maybe, .doc = "no terminal (no window) until one attaches; panes, shells and files stay; NAME (one path component) rather than the pid. One pardes --daemon per user lists them, for attach (PARDES_DAEMON=off: none)" },
.@"-w" = .{ .group = .open },
.@"--wait" = .{ .group = .open, .doc = "in a pane, hand FILE to its session and return once its pane is deleted: 0, or 1 if the session goes (EDITOR='pardes --wait')" },
.@"--" = .{ .group = .open, .doc = "the end of the flags: pardes -- -name opens -name" },
@@ -1496,7 +1497,7 @@ fn nativeMain(std_init: std.process.Init) !void {
opts.recent_import = oldRecentDir(arena, init.environ_map);
if (found.dir) |d| @import("crash.zig").setDir(d);
if (attach) |name| if (std.mem.lastIndexOfScalar(u8, name, ':')) |colon| {
- remoteAttach(init, opts, name[0..colon], name[colon + 1 ..]);
+ attachClient(init, opts, name[0..colon], name[colon + 1 ..]);
};
if (attach) |name| if (!resuming) attachTo(init, opts, name);
if (detach) |name| {
@@ -1519,19 +1520,19 @@ fn nativeMain(std_init: std.process.Init) !void {
opts.rows = 50;
}
const kind: daemon.Kind = if (pardes.platform == .gui) .gui else .tty;
- var term: @import("tui/tui.zig").Term = if (detach != null) .none else .open;
- var headless = detach != null;
+ var term: @import("tui/tui.zig").Term = if (detach != null) .detached else .open;
+ var detached = detach != null;
upgrade.remember(args);
if (upgrade.resumed) |*rec| {
// Close-on-exec again: a shell forked from here inherits none.
rec.closeOnExec(true);
opts.load_path = rec.dump;
- term = .none;
+ term = .detached;
for (rec.ttys[0..rec.nttys]) |t| if (t.primary) {
term = .{ .fd = .{ .fd = t.fd, .termios = t.termios } };
};
- headless = if (pardes.platform == .gui) !rec.window else rec.nttys == 0;
- daemon.resumeLink(rec.link, rec.stub, kind, opts.ninep_name, headless);
+ detached = if (pardes.platform == .gui) !rec.window else rec.nttys == 0;
+ daemon.resumeLink(rec.link, rec.stub, kind, opts.ninep_name, detached);
} else if (daemon.wanted()) {
if (detach != null or pardes.platform == .gui) {
_ = daemon.register(null, kind, opts.ninep_name, detach != null);
@@ -1574,7 +1575,7 @@ fn nativeMain(std_init: std.process.Init) !void {
},
else => return err,
},
- .gui => try @import("gui/gui.zig").run(init, opts, headless),
+ .gui => try @import("gui/gui.zig").run(init, opts, detached),
.macos => unreachable,
}
daemon.tellStubExit(0);
@@ -1612,7 +1613,7 @@ fn manage(io: std.Io, verb: enum { list, kill, killall }, name: []const u8) nore
.session => {
const kind = it.next() orelse "";
const state = it.next() orelse "";
- w.print(" session {s} {s} ({s}, {s})\n", .{ std.mem.trim(u8, it.rest(), " "), pid, kind, state }) catch break;
+ w.print(" session {s} {s} ({s}, {s})\n", .{ std.mem.trim(u8, it.rest(), " "), pid, kind, if (std.mem.eql(u8, state, "attached")) "has a frontend" else state }) catch break;
},
.client => w.print(" client {s} {s}\n", .{ pid, comm }) catch break,
.shell => w.print(" shell {s} {s}\n", .{ pid, comm }) catch break,
@@ -1674,17 +1675,17 @@ fn commOf(io: std.Io, pid: []const u8, buf: *[64]u8) []const u8 {
/// window's (gui.zig).
fn clientOf(init: std.process.Init, opts: pardes.Options, path: []const u8, name: []const u8, far: bool) !void {
switch (pardes.platform) {
- .tui => try @import("tui/tui.zig").remote(init, opts, path, name, far),
- .gui => try @import("gui/gui.zig").remote(init, opts, path, name, far),
+ .tui => try @import("tui/tui.zig").runClient(init, opts, path, name, far),
+ .gui => try @import("gui/gui.zig").runClient(init, opts, path, name, far),
else => unreachable,
}
}
/// `pardes --attach=<where>:<name>` (`pardes-gui` too): a replica client
-/// (tui.zig and gui.zig `remote`), through the socket `where` names, or
+/// (tui.zig and gui.zig `runClient`), through the socket `where` names, or
/// through `ssh -L` of host `where`'s replica socket to one of this
/// process's.
-fn remoteAttach(init: std.process.Init, opts: pardes.Options, where: []const u8, name: []const u8) noreturn {
+fn attachClient(init: std.process.Init, opts: pardes.Options, where: []const u8, name: []const u8) noreturn {
const io = init.io;
if (comptime pardes.platform != .tui and pardes.platform != .gui) unreachable;
if (std.mem.indexOfScalar(u8, where, '/') != null) {
@@ -1697,7 +1698,7 @@ fn remoteAttach(init: std.process.Init, opts: pardes.Options, where: []const u8,
const here = std.fmt.bufPrintSentinel(&here_buf, "{s}/pardes-ssh-{d}.sock", .{ tmp, std.c.getpid() }, 0) catch die(io, "--attach: TMPDIR is too long for a socket's path", .{});
var there_buf: [ninep_io.sun_path_len + 64:0]u8 = undefined;
var dir_buf: [ninep_io.sun_path_len:0]u8 = undefined;
- const dir = if (std.c.getenv("PARDES_REMOTE_RUNTIME")) |d| std.mem.span(d) else ninep_io.socketDir(&dir_buf) orelse die(io, "--attach: no runtime directory to name the remote socket by: set PARDES_REMOTE_RUNTIME", .{});
+ const dir = if (std.c.getenv("PARDES_REMOTE_RUNTIME")) |d| std.mem.span(d) else ninep_io.socketDir(&dir_buf) orelse die(io, "--attach: no runtime directory to name the far socket by: set PARDES_REMOTE_RUNTIME", .{});
var forward_buf: [2 * ninep_io.sun_path_len + 64]u8 = undefined;
const there = std.fmt.bufPrintSentinel(&there_buf, "{s}/pardes-replica.sock", .{dir}, 0) catch unreachable;
const forward = std.fmt.bufPrintSentinel(&forward_buf, "{s}:{s}", .{ here, there }, 0) catch unreachable;
@@ -1814,7 +1815,7 @@ fn attachTo(init: std.process.Init, opts: pardes.Options, name: []const u8) nore
fn crossAttach(init: std.process.Init, opts: pardes.Options, name: []const u8) noreturn {
var sock_buf: [ninep_io.sun_path_len:0]u8 = undefined;
const sock = daemon.replicaSocket(&sock_buf) orelse die(init.io, "--attach: no runtime directory for the replica socket", .{});
- remoteAttach(init, opts, sock, name);
+ attachClient(init, opts, sock, name);
}
/// Where Recent's file (0.24) and the store before it were kept: