Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (95 sloc) 3.232 kb
0f2e3364 »
2012-01-21 Import upstream snapshot from SVN r2670
1 /* $Id: cmd-attach-session.c 2665 2012-01-21 19:30:07Z tcunha $ */
8fade26b »
2009-11-22 Imported Upstream version 1.1
2
3 /*
4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/types.h>
20
21 #include "tmux.h"
22
23 /*
24 * Attach existing session to the current terminal.
25 */
26
27 int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
28
29 const struct cmd_entry cmd_attach_session_entry = {
30 "attach-session", "attach",
7216c39c »
2011-07-09 Imported Upstream version 1.5
31 "drt:", 0, 0,
dda8e8e5 »
2010-03-13 Imported Upstream version 1.2
32 "[-dr] " CMD_TARGET_SESSION_USAGE,
7216c39c »
2011-07-09 Imported Upstream version 1.5
33 CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON,
34 NULL,
35 NULL,
36 cmd_attach_session_exec
8fade26b »
2009-11-22 Imported Upstream version 1.1
37 };
38
39 int
40 cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
41 {
7216c39c »
2011-07-09 Imported Upstream version 1.5
42 struct args *args = self->args;
43 struct session *s;
44 struct client *c;
45 const char *update;
46 char *overrides, *cause;
47 u_int i;
8fade26b »
2009-11-22 Imported Upstream version 1.1
48
77c63de6 »
2010-12-28 Import upstream version 1.4
49 if (RB_EMPTY(&sessions)) {
8fade26b »
2009-11-22 Imported Upstream version 1.1
50 ctx->error(ctx, "no sessions");
51 return (-1);
52 }
7216c39c »
2011-07-09 Imported Upstream version 1.5
53
54 if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL)
8fade26b »
2009-11-22 Imported Upstream version 1.1
55 return (-1);
56
57 if (ctx->cmdclient == NULL && ctx->curclient == NULL)
58 return (0);
59
60 if (ctx->cmdclient == NULL) {
7216c39c »
2011-07-09 Imported Upstream version 1.5
61 if (args_has(self->args, 'd')) {
dda8e8e5 »
2010-03-13 Imported Upstream version 1.2
62 /*
8fade26b »
2009-11-22 Imported Upstream version 1.1
63 * Can't use server_write_session in case attaching to
64 * the same session as currently attached to.
65 */
66 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
67 c = ARRAY_ITEM(&clients, i);
68 if (c == NULL || c->session != s)
69 continue;
70 if (c == ctx->curclient)
71 continue;
72 server_write_client(c, MSG_DETACH, NULL, 0);
73 }
74 }
dda8e8e5 »
2010-03-13 Imported Upstream version 1.2
75
8fade26b »
2009-11-22 Imported Upstream version 1.1
76 ctx->curclient->session = s;
7216c39c »
2011-07-09 Imported Upstream version 1.5
77 session_update_activity(s);
8fade26b »
2009-11-22 Imported Upstream version 1.1
78 server_redraw_client(ctx->curclient);
0f2e3364 »
2012-01-21 Import upstream snapshot from SVN r2670
79 s->curw->flags &= ~WINLINK_ALERTFLAGS;
8fade26b »
2009-11-22 Imported Upstream version 1.1
80 } else {
81 if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
82 ctx->error(ctx, "not a terminal");
83 return (-1);
84 }
85
86 overrides =
87 options_get_string(&s->options, "terminal-overrides");
88 if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
89 ctx->error(ctx, "terminal open failed: %s", cause);
90 xfree(cause);
91 return (-1);
92 }
93
7216c39c »
2011-07-09 Imported Upstream version 1.5
94 if (args_has(self->args, 'r'))
dda8e8e5 »
2010-03-13 Imported Upstream version 1.2
95 ctx->cmdclient->flags |= CLIENT_READONLY;
96
7216c39c »
2011-07-09 Imported Upstream version 1.5
97 if (args_has(self->args, 'd'))
8fade26b »
2009-11-22 Imported Upstream version 1.1
98 server_write_session(s, MSG_DETACH, NULL, 0);
99
100 ctx->cmdclient->session = s;
7216c39c »
2011-07-09 Imported Upstream version 1.5
101 session_update_activity(s);
8fade26b »
2009-11-22 Imported Upstream version 1.1
102 server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
103
104 update = options_get_string(&s->options, "update-environment");
105 environ_update(update, &ctx->cmdclient->environ, &s->environ);
106
107 server_redraw_client(ctx->cmdclient);
0f2e3364 »
2012-01-21 Import upstream snapshot from SVN r2670
108 s->curw->flags &= ~WINLINK_ALERTFLAGS;
8fade26b »
2009-11-22 Imported Upstream version 1.1
109 }
110 recalculate_sizes();
dda8e8e5 »
2010-03-13 Imported Upstream version 1.2
111 server_update_socket();
8fade26b »
2009-11-22 Imported Upstream version 1.1
112
113 return (1); /* 1 means don't tell command client to exit */
114 }
Something went wrong with that request. Please try again.