summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/tmux.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2010-02-06 18:47:41 +0000
committernicm <nicm@openbsd.org>2010-02-06 18:47:41 +0000
commitf0437465798acf335716712ebf09ad474f11b998 (patch)
tree54328a8e6591b7c87a99bd062287a616ca3ef365 /usr.bin/tmux/tmux.c
parentClean up $TMUX parsing, from Micah Cowan, tweaked by me. (diff)
downloadwireguard-openbsd-f0437465798acf335716712ebf09ad474f11b998.tar.xz
wireguard-openbsd-f0437465798acf335716712ebf09ad474f11b998.zip
Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.
Diffstat (limited to 'usr.bin/tmux/tmux.c')
-rw-r--r--usr.bin/tmux/tmux.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 7918c8ae5f7..e79d2425e78 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.70 2010/02/06 18:29:15 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.71 2010/02/06 18:47:41 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -484,6 +484,7 @@ main(int argc, char **argv)
cmddata.pid = envdata.pid;
cmddata.idx = envdata.idx;
+ /* Prepare command for server. */
cmddata.argc = argc;
if (cmd_pack_argv(
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
@@ -499,7 +500,7 @@ main(int argc, char **argv)
if (shellcmd != NULL)
cmdflags |= CMD_STARTSERVER;
else if (argc == 0) /* new-session is the default */
- cmdflags |= CMD_STARTSERVER|CMD_SENDENVIRON;
+ cmdflags |= CMD_STARTSERVER|CMD_SENDENVIRON|CMD_CANTNEST;
else {
/*
* It sucks parsing the command string twice (in client and
@@ -516,10 +517,24 @@ main(int argc, char **argv)
cmdflags |= CMD_STARTSERVER;
if (cmd->entry->flags & CMD_SENDENVIRON)
cmdflags |= CMD_SENDENVIRON;
+ if (cmd->entry->flags & CMD_CANTNEST)
+ cmdflags |= CMD_CANTNEST;
}
cmd_list_free(cmdlist);
}
+ /*
+ * Check if this could be a nested session, if the command can't nest:
+ * if the socket path matches $TMUX, this is probably the same server.
+ */
+ if (shellcmd == NULL && envdata.path != NULL &&
+ cmdflags & CMD_CANTNEST &&
+ (path == envdata.path || strcmp(path, envdata.path) == 0)) {
+ log_warnx("sessions should be nested with care. "
+ "unset $TMUX to force.");
+ exit(1);
+ }
+
if ((main_ibuf = client_init(path, cmdflags, flags)) == NULL)
exit(1);
xfree(path);