aboutsummaryrefslogtreecommitdiff
path: root/cmd-new-session.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-new-session.c')
-rw-r--r--cmd-new-session.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 9c767489..1533e5f0 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -37,11 +37,11 @@ enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
- "Ac:dDF:n:Ps:t:x:y:", 0, -1,
- "[-AdDP] [-c start-directory] [-F format] [-n window-name] "
+ "Ac:dDEF:n:Ps:t:x:y:", 0, -1,
+ "[-AdDEP] [-c start-directory] [-F format] [-n window-name] "
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
- CMD_STARTSERVER|CMD_CANTNEST,
+ CMD_STARTSERVER,
cmd_new_session_exec
};
@@ -91,7 +91,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if (session_find(newname) != NULL) {
if (args_has(args, 'A')) {
return (cmd_attach_session(cmdq, newname,
- args_has(args, 'D'), 0, NULL));
+ args_has(args, 'D'), 0, NULL,
+ args_has(args, 'E')));
}
cmdq_error(cmdq, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
@@ -145,15 +146,20 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
}
/*
- * Save the termios settings, part of which is used for new windows in
- * this session.
+ * If this is a new client, check for nesting and save the termios
+ * settings (part of which is used for new windows in this session).
*
- * This is read again with tcgetattr() rather than using tty.tio as if
- * detached, tty_open won't be called. Because of this, it must be done
- * before opening the terminal as that calls tcsetattr() to prepare for
- * tmux taking over.
+ * tcgetattr() is used rather than using tty.tio since if the client is
+ * detached, tty_open won't be called. It must be done before opening
+ * the terminal as that calls tcsetattr() to prepare for tmux taking
+ * over.
*/
if (!detached && !already_attached && c->tty.fd != -1) {
+ if (server_client_check_nested(cmdq->client)) {
+ cmdq_error(cmdq, "sessions should be nested with care, "
+ "unset $TMUX to force");
+ return (CMD_RETURN_ERROR);
+ }
if (tcgetattr(c->tty.fd, &tio) != 0)
fatal("tcgetattr failed");
tiop = &tio;
@@ -225,9 +231,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Construct the environment. */
environ_init(&env);
- update = options_get_string(&global_s_options, "update-environment");
- if (c != NULL)
+ if (c != NULL && !args_has(args, 'E')) {
+ update = options_get_string(&global_s_options,
+ "update-environment");
environ_update(update, &c->environ, &env);
+ }
/* Create the new session. */
idx = -1 - options_get_number(&global_s_options, "base-index");