version 1.14, 2011/01/01 01:12:09 |
version 1.15, 2011/01/04 00:42:46 |
|
|
|
|
const struct cmd_entry cmd_attach_session_entry = { |
const struct cmd_entry cmd_attach_session_entry = { |
"attach-session", "attach", |
"attach-session", "attach", |
|
"drt:", 0, 0, |
"[-dr] " CMD_TARGET_SESSION_USAGE, |
"[-dr] " CMD_TARGET_SESSION_USAGE, |
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "dr", |
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, |
cmd_target_init, |
NULL, |
cmd_target_parse, |
NULL, |
cmd_attach_session_exec, |
cmd_attach_session_exec |
cmd_target_free, |
|
cmd_target_print |
|
}; |
}; |
|
|
int |
int |
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) |
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) |
{ |
{ |
struct cmd_target_data *data = self->data; |
struct args *args = self->args; |
struct session *s; |
struct session *s; |
struct client *c; |
struct client *c; |
const char *update; |
const char *update; |
char *overrides, *cause; |
char *overrides, *cause; |
u_int i; |
u_int i; |
|
|
if (RB_EMPTY(&sessions)) { |
if (RB_EMPTY(&sessions)) { |
ctx->error(ctx, "no sessions"); |
ctx->error(ctx, "no sessions"); |
return (-1); |
return (-1); |
} |
} |
if ((s = cmd_find_session(ctx, data->target)) == NULL) |
|
|
if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) |
return (-1); |
return (-1); |
|
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL) |
if (ctx->cmdclient == NULL && ctx->curclient == NULL) |
return (0); |
return (0); |
|
|
if (ctx->cmdclient == NULL) { |
if (ctx->cmdclient == NULL) { |
if (cmd_check_flag(data->chflags, 'd')) { |
if (args_has(self->args, 'd')) { |
/* |
/* |
* Can't use server_write_session in case attaching to |
* Can't use server_write_session in case attaching to |
* the same session as currently attached to. |
* the same session as currently attached to. |
|
|
return (-1); |
return (-1); |
} |
} |
|
|
if (cmd_check_flag(data->chflags, 'r')) |
if (args_has(self->args, 'r')) |
ctx->cmdclient->flags |= CLIENT_READONLY; |
ctx->cmdclient->flags |= CLIENT_READONLY; |
|
|
if (cmd_check_flag(data->chflags, 'd')) |
if (args_has(self->args, 'd')) |
server_write_session(s, MSG_DETACH, NULL, 0); |
server_write_session(s, MSG_DETACH, NULL, 0); |
|
|
ctx->cmdclient->session = s; |
ctx->cmdclient->session = s; |