version 1.21, 2012/07/10 11:53:01 |
version 1.22, 2012/07/11 07:10:15 |
|
|
* Attach existing session to the current terminal. |
* Attach existing session to the current terminal. |
*/ |
*/ |
|
|
int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); |
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); |
|
|
const struct cmd_entry cmd_attach_session_entry = { |
const struct cmd_entry cmd_attach_session_entry = { |
"attach-session", "attach", |
"attach-session", "attach", |
|
|
cmd_attach_session_exec |
cmd_attach_session_exec |
}; |
}; |
|
|
int |
enum cmd_retval |
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) |
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
|
|
|
|
if (RB_EMPTY(&sessions)) { |
if (RB_EMPTY(&sessions)) { |
ctx->error(ctx, "no sessions"); |
ctx->error(ctx, "no sessions"); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL) |
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL) |
return (-1); |
return (CMD_RETURN_ERROR); |
|
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL) |
if (ctx->cmdclient == NULL && ctx->curclient == NULL) |
return (0); |
return (CMD_RETURN_NORMAL); |
|
|
if (ctx->cmdclient == NULL) { |
if (ctx->cmdclient == NULL) { |
if (args_has(self->args, 'd')) { |
if (args_has(self->args, 'd')) { |
|
|
if (server_client_open(ctx->cmdclient, s, &cause) != 0) { |
if (server_client_open(ctx->cmdclient, s, &cause) != 0) { |
ctx->error(ctx, "open terminal failed: %s", cause); |
ctx->error(ctx, "open terminal failed: %s", cause); |
free(cause); |
free(cause); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
if (args_has(self->args, 'r')) |
if (args_has(self->args, 'r')) |
|
|
recalculate_sizes(); |
recalculate_sizes(); |
server_update_socket(); |
server_update_socket(); |
|
|
return (1); /* 1 means don't tell command client to exit */ |
return (CMD_RETURN_ATTACH); |
} |
} |