aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-22 18:30:19 +0200
committeruser <user@clank>2026-08-22 18:30:19 +0200
commit063d43f7702fa74071e8555c6e9dabba1a914c74 (patch)
tree08703e3200f9e4977726c09fc2f22a023dad52cd /src/main.c
parentslosh: paint the padding ring, so a float cannot be seen through (diff)
downloadslosh-063d43f7702fa74071e8555c6e9dabba1a914c74.tar.gz
slosh-063d43f7702fa74071e8555c6e9dabba1a914c74.tar.xz
slosh-063d43f7702fa74071e8555c6e9dabba1a914c74.zip
slosh: refuse to attach to the session this pane is inside
A new client displaces the current display, so `slosh` typed into a pane of "main" displaced the very client showing that pane -- you watched your own session detach, from inside it. SLOSH_SESSION names the pane's own session; that one name is refused with the way out spelled in the message. Any other name is deliberate nesting, and cmd/ls are untouched: they are how a program in a pane is supposed to reach its own session.
Diffstat (limited to '')
-rw-r--r--src/main.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index b488e56..e3e621e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -249,6 +249,26 @@ int main(int argc, char **argv) {
if (isatty(STDOUT_FILENO)) term_size(&cols, &rows);
if (server) return server_run(name, cmd_argv, cols, rows, layout, watch);
+ /* Not to the session this process is already inside. A new client
+ * displaces the current display (EXIT_REPLACED), so `slosh` typed into a
+ * pane of "main" attaches to main, displaces the very client showing that
+ * pane, and the user watches their own session detach from inside it.
+ * SLOSH_SESSION names the pane's own session; asking for any *other* name
+ * is deliberate nesting and none of our business. The one legitimate shape
+ * this refuses — a fresh terminal launched from a pane, inheriting the
+ * variables, attaching to take over as the display — gets its escape hatch
+ * named in the message rather than a flag: it is exactly what unsetting
+ * the variable means. */
+ const char *inside = getenv("SLOSH") ? getenv("SLOSH_SESSION") : NULL;
+ if (inside && *inside && strcmp(inside, name) == 0) {
+ fprintf(stderr,
+ "slosh: this pane is already inside session %s\n"
+ " (C-a d detaches; `slosh -s NAME` nests another session;\n"
+ " unset SLOSH_SESSION to attach anyway, displacing this view)\n",
+ name);
+ return 1;
+ }
+
/* attach, creating the session if nobody is home */
int fd = server_connect(name);
if (fd < 0) fd = server_spawn(name, cmd_argv, cols, rows, layout, watch);