aboutsummaryrefslogtreecommitdiff
path: root/cmd-attach-session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2013-02-24 00:43:28 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2013-02-24 00:43:28 +0000
commitf339cfd31563aaae0ae94361228bb697c83aa3bf (patch)
treee757507211a47b2cd9c8e2e782cc774ecfa96e29 /cmd-attach-session.c
parentc5239c59846c2d09725d4b1db0e728b3376c3998 (diff)
downloadrtmux-f339cfd31563aaae0ae94361228bb697c83aa3bf.tar.gz
rtmux-f339cfd31563aaae0ae94361228bb697c83aa3bf.tar.bz2
rtmux-f339cfd31563aaae0ae94361228bb697c83aa3bf.zip
Add -A flag to new-session to make it behave like attach-session if the session
exists. If -A is used, -D behaves like -d to attach-session.
Diffstat (limited to 'cmd-attach-session.c')
-rw-r--r--cmd-attach-session.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 5c8f76ed..07185737 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -39,9 +39,8 @@ const struct cmd_entry cmd_attach_session_entry = {
};
enum cmd_retval
-cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
+cmd_attach_session(struct cmd_q *cmdq, const char* tflag, int dflag, int rflag)
{
- struct args *args = self->args;
struct session *s;
struct client *c;
const char *update;
@@ -53,14 +52,14 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
- if ((s = cmd_find_session(cmdq, args_get(args, 't'), 1)) == NULL)
+ if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (cmdq->client->session != NULL) {
- if (args_has(self->args, 'd')) {
+ if (dflag) {
/*
* Can't use server_write_session in case attaching to
* the same session as currently attached to.
@@ -87,10 +86,10 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
- if (args_has(self->args, 'r'))
+ if (rflag)
cmdq->client->flags |= CLIENT_READONLY;
- if (args_has(self->args, 'd'))
+ if (dflag)
server_write_session(s, MSG_DETACH, NULL, 0);
update = options_get_string(&s->options, "update-environment");
@@ -110,3 +109,12 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
+
+enum cmd_retval
+cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+ struct args *args = self->args;
+
+ return (cmd_attach_session(cmdq, args_get(args, 't'),
+ args_has(args, 'd'), args_has(args, 'r')));
+}