summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorhar7an <99636919+har7an@users.noreply.github.com>2022-10-13 08:17:54 +0000
committerGitHub <noreply@github.com>2022-10-13 08:17:54 +0000
commit8d56def4fc3441b7231eda8c2ca944445af43920 (patch)
tree7e2a9d769bacb240ad136a4dddbc9cb472ffb8a6 /src
parente07dfcde7870becac19fcb609dcb0681ce181c4c (diff)
zellij/commands: Prevent recursive sessions (#1766)
* zellij/commands: Prevent recursive sessions with session names specified in layout files. A "recursive session" is created when, while running inside some zellij session, a user attempts to spawn zellij and make it attach to that same session. When attaching via CLI (`zellij attach`) we explicitly check for this condition and error out when needed. However, besides `zellij attach` it is also possible to declare the session to attach to in layout files like so: ```yaml session: name: "foo" ``` This takes a different codepath when starting zellij, and hence bypases the checks we already have in place to avoid recursive sessions. Hence, we implement the check in the other codepath, too, and prevent recursive sessions from happening for good. Fixes: #1735 * changelog: fix recursive zellij sessions
Diffstat (limited to 'src')
-rw-r--r--src/commands.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/commands.rs b/src/commands.rs
index b4e2e1da2..1acaf12f4 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -275,10 +275,10 @@ fn attach_with_session_name(
) -> ClientInfo {
match &session_name {
Some(session) if create => {
- if !session_exists(session).unwrap() {
- ClientInfo::New(session_name.unwrap())
- } else {
+ if session_exists(session).unwrap() {
ClientInfo::Attach(session_name.unwrap(), config_options)
+ } else {
+ ClientInfo::New(session_name.unwrap())
}
},
Some(prefix) => match match_session_name(prefix).unwrap() {
@@ -351,7 +351,7 @@ pub(crate) fn start_client(opts: CliArgs) {
if let Ok(val) = std::env::var(envs::SESSION_NAME_ENV_KEY) {
if val == *client.get_session_name() {
- eprintln!("You are trying to attach to the current session(\"{}\"). Zellij does not support nesting a session in itself.", val);
+ eprintln!("You are trying to attach to the current session (\"{}\"). Zellij does not support nesting a session in itself.", val);
process::exit(1);
}
}
@@ -391,6 +391,19 @@ pub(crate) fn start_client(opts: CliArgs) {
);
} else {
if let Some(session_name) = config_options.session_name.as_ref() {
+ if let Ok(val) = envs::get_session_name() {
+ // This prevents the same type of recursion as above, only that here we
+ // don't get the command to "attach", but to start a new session instead.
+ // This occurs for example when declaring the session name inside a layout
+ // file and then, from within this session, trying to open a new zellij
+ // session with the same layout. This causes an infinite recursion in the
+ // `zellij_server::terminal_bytes::listen` task, flooding the server and
+ // clients with infinite `Render` requests.
+ if *session_name == val {
+ eprintln!("You are trying to attach to the current session (\"{}\"). Zellij does not support nesting a session in itself.", session_name);
+ process::exit(1);
+ }
+ }
match config_options.attach_to_session {
Some(true) => {
let client = attach_with_session_name(