-/* $OpenBSD: client.c,v 1.88 2015/04/24 20:58:44 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.89 2015/06/04 23:27:51 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
cmdflags = CMD_STARTSERVER;
} else if (argc == 0) {
msg = MSG_COMMAND;
- cmdflags = CMD_STARTSERVER|CMD_CANTNEST;
+ cmdflags = CMD_STARTSERVER;
} else {
msg = MSG_COMMAND;
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
if (cmd->entry->flags & CMD_STARTSERVER)
cmdflags |= CMD_STARTSERVER;
- 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 (shell_cmd == NULL && environ_path != NULL &&
- (cmdflags & CMD_CANTNEST) &&
- strcmp(socket_path, environ_path) == 0) {
- fprintf(stderr, "sessions should be nested with care, "
- "unset $TMUX to force\n");
- return (1);
- }
-
/* Set process title, log and signals now this is the client. */
setproctitle("client (%s)", socket_path);
logfile("client");
-/* $OpenBSD: cmd-attach-session.c,v 1.34 2015/04/25 18:09:28 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.35 2015/06/04 23:27:51 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
"attach-session", "attach",
"c:drt:", 0, 0,
"[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
- CMD_CANTNEST|CMD_STARTSERVER,
+ CMD_STARTSERVER,
cmd_attach_session_exec
};
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
+ 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 (wl != NULL) {
if (wp != NULL)
-/* $OpenBSD: cmd-new-session.c,v 1.66 2015/05/29 23:02:27 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.67 2015/06/04 23:27:51 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
"[-AdDP] [-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
};
}
/*
- * 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;
-/* $OpenBSD: server-client.c,v 1.139 2015/05/27 13:28:04 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.140 2015/06/04 23:27:51 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
void server_client_msg_identify(struct client *, struct imsg *);
void server_client_msg_shell(struct client *);
+/* Check if this client is inside this server. */
+int
+server_client_check_nested(struct client *c)
+{
+ struct environ_entry *envent;
+ struct window_pane *wp;
+
+ if (c->tty.path == NULL)
+ return (0);
+
+ envent = environ_find(&c->environ, "TMUX");
+ if (envent == NULL || *envent->value == '\0')
+ return (0);
+
+ RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
+ if (strcmp(wp->tty, c->tty.path) == 0)
+ return (1);
+ }
+ return (0);
+}
+
/* Set client key table. */
void
server_client_key_table(struct client *c, const char *name)
-/* $OpenBSD: tmux.h,v 1.516 2015/06/04 11:43:51 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.517 2015/06/04 23:27:51 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
const char *usage;
#define CMD_STARTSERVER 0x1
-#define CMD_CANTNEST 0x2
-#define CMD_READONLY 0x4
+#define CMD_READONLY 0x2
int flags;
enum cmd_retval (*exec)(struct cmd *, struct cmd_q *);
void server_add_accept(int);
/* server-client.c */
+int server_client_check_nested(struct client *);
void server_client_handle_key(struct client *, int);
void server_client_create(int);
int server_client_open(struct client *, char **);