Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 961 lines (811 sloc) 24.48 kb
798186b @orebokech Import upstream version 1.6
orebokech authored
1 /* $Id: server-client.c 2674 2012-01-23 12:24:00Z tcunha $ */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
2
3 /*
4 * Copyright (c) 2009 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
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
21 #include <event.h>
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
22 #include <fcntl.h>
23 #include <string.h>
24 #include <time.h>
25 #include <unistd.h>
26
27 #include "tmux.h"
28
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
29 void server_client_handle_key(int, struct mouse_event *, void *);
30 void server_client_repeat_timer(int, short, void *);
77c63de @orebokech Import upstream version 1.4
orebokech authored
31 void server_client_check_exit(struct client *);
32 void server_client_check_backoff(struct client *);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
33 void server_client_check_redraw(struct client *);
34 void server_client_set_title(struct client *);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
35 void server_client_reset_state(struct client *);
77c63de @orebokech Import upstream version 1.4
orebokech authored
36 void server_client_in_callback(struct bufferevent *, short, void *);
37 void server_client_out_callback(struct bufferevent *, short, void *);
38 void server_client_err_callback(struct bufferevent *, short, void *);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
39
40 int server_client_msg_dispatch(struct client *);
41 void server_client_msg_command(struct client *, struct msg_command_data *);
42 void server_client_msg_identify(
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
43 struct client *, struct msg_identify_data *, int);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
44 void server_client_msg_shell(struct client *);
45
46 void printflike2 server_client_msg_error(struct cmd_ctx *, const char *, ...);
47 void printflike2 server_client_msg_print(struct cmd_ctx *, const char *, ...);
48 void printflike2 server_client_msg_info(struct cmd_ctx *, const char *, ...);
49
50 /* Create a new client. */
51 void
52 server_client_create(int fd)
53 {
54 struct client *c;
55 u_int i;
56
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
57 setblocking(fd, 0);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
58
59 c = xcalloc(1, sizeof *c);
60 c->references = 0;
61 imsg_init(&c->ibuf, fd);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
62 server_update_event(c);
63
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
64 if (gettimeofday(&c->creation_time, NULL) != 0)
65 fatal("gettimeofday failed");
66 memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
67
77c63de @orebokech Import upstream version 1.4
orebokech authored
68 c->stdin_event = NULL;
69 c->stdout_event = NULL;
70 c->stderr_event = NULL;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
71
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
72 c->tty.fd = -1;
73 c->title = NULL;
74
75 c->session = NULL;
77c63de @orebokech Import upstream version 1.4
orebokech authored
76 c->last_session = NULL;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
77 c->tty.sx = 80;
78 c->tty.sy = 24;
79
80 screen_init(&c->status, c->tty.sx, 1, 0);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
81 RB_INIT(&c->status_new);
82 RB_INIT(&c->status_old);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
83
84 c->message_string = NULL;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
85 ARRAY_INIT(&c->message_log);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
86
87 c->prompt_string = NULL;
88 c->prompt_buffer = NULL;
89 c->prompt_index = 0;
90
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
91 c->last_mouse.b = MOUSE_UP;
92 c->last_mouse.x = c->last_mouse.y = -1;
93
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
94 evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
95
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
96 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
97 if (ARRAY_ITEM(&clients, i) == NULL) {
98 ARRAY_SET(&clients, i, c);
99 return;
100 }
101 }
102 ARRAY_ADD(&clients, c);
103 log_debug("new client %d", fd);
104 }
105
106 /* Lost a client. */
107 void
108 server_client_lost(struct client *c)
109 {
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
110 struct message_entry *msg;
111 u_int i;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
112
113 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
114 if (ARRAY_ITEM(&clients, i) == c)
115 ARRAY_SET(&clients, i, NULL);
116 }
117 log_debug("lost client %d", c->ibuf.fd);
118
119 /*
120 * If CLIENT_TERMINAL hasn't been set, then tty_init hasn't been called
121 * and tty_free might close an unrelated fd.
122 */
123 if (c->flags & CLIENT_TERMINAL)
124 tty_free(&c->tty);
125
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
126 if (c->stdin_fd != -1) {
127 setblocking(c->stdin_fd, 1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
128 close(c->stdin_fd);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
129 }
77c63de @orebokech Import upstream version 1.4
orebokech authored
130 if (c->stdin_event != NULL)
131 bufferevent_free(c->stdin_event);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
132 if (c->stdout_fd != -1) {
133 setblocking(c->stdout_fd, 1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
134 close(c->stdout_fd);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
135 }
77c63de @orebokech Import upstream version 1.4
orebokech authored
136 if (c->stdout_event != NULL)
137 bufferevent_free(c->stdout_event);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
138 if (c->stderr_fd != -1) {
139 setblocking(c->stderr_fd, 1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
140 close(c->stderr_fd);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
141 }
77c63de @orebokech Import upstream version 1.4
orebokech authored
142 if (c->stderr_event != NULL)
143 bufferevent_free(c->stderr_event);
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
144
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
145 status_free_jobs(&c->status_new);
146 status_free_jobs(&c->status_old);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
147 screen_free(&c->status);
148
149 if (c->title != NULL)
150 xfree(c->title);
151
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
152 evtimer_del(&c->repeat_timer);
153
154 evtimer_del(&c->identify_timer);
155
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
156 if (c->message_string != NULL)
157 xfree(c->message_string);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
158 evtimer_del(&c->message_timer);
159 for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
160 msg = &ARRAY_ITEM(&c->message_log, i);
161 xfree(msg->msg);
162 }
163 ARRAY_FREE(&c->message_log);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
164
165 if (c->prompt_string != NULL)
166 xfree(c->prompt_string);
167 if (c->prompt_buffer != NULL)
168 xfree(c->prompt_buffer);
169
170 if (c->cwd != NULL)
171 xfree(c->cwd);
172
b016948 @orebokech Import upstream snapshot from SVN r2608
orebokech authored
173 environ_free(&c->environ);
174
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
175 close(c->ibuf.fd);
176 imsg_clear(&c->ibuf);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
177 event_del(&c->event);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
178
179 for (i = 0; i < ARRAY_LENGTH(&dead_clients); i++) {
180 if (ARRAY_ITEM(&dead_clients, i) == NULL) {
181 ARRAY_SET(&dead_clients, i, c);
182 break;
183 }
184 }
185 if (i == ARRAY_LENGTH(&dead_clients))
186 ARRAY_ADD(&dead_clients, c);
187 c->flags |= CLIENT_DEAD;
188
189 recalculate_sizes();
77c63de @orebokech Import upstream version 1.4
orebokech authored
190 server_check_unattached();
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
191 server_update_socket();
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
192 }
193
194 /* Process a single client event. */
195 void
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
196 server_client_callback(int fd, short events, void *data)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
197 {
198 struct client *c = data;
199
200 if (c->flags & CLIENT_DEAD)
201 return;
202
203 if (fd == c->ibuf.fd) {
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
204 if (events & EV_WRITE && msgbuf_write(&c->ibuf.w) < 0)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
205 goto client_lost;
206
207 if (c->flags & CLIENT_BAD) {
208 if (c->ibuf.w.queued == 0)
209 goto client_lost;
210 return;
211 }
212
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
213 if (events & EV_READ && server_client_msg_dispatch(c) != 0)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
214 goto client_lost;
215 }
216
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
217 server_update_event(c);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
218 return;
219
220 client_lost:
221 server_client_lost(c);
222 }
223
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
224 /* Handle client status timer. */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
225 void
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
226 server_client_status_timer(void)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
227 {
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
228 struct client *c;
229 struct session *s;
230 struct timeval tv;
231 u_int i;
232 int interval;
233 time_t difference;
234
235 if (gettimeofday(&tv, NULL) != 0)
236 fatal("gettimeofday failed");
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
237
238 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
239 c = ARRAY_ITEM(&clients, i);
240 if (c == NULL || c->session == NULL)
241 continue;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
242 if (c->message_string != NULL || c->prompt_string != NULL) {
243 /*
244 * Don't need timed redraw for messages/prompts so bail
245 * now. The status timer isn't reset when they are
246 * redrawn anyway.
247 */
248 continue;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
249 }
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
250 s = c->session;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
251
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
252 if (!options_get_number(&s->options, "status"))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
253 continue;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
254 interval = options_get_number(&s->options, "status-interval");
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
255
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
256 difference = tv.tv_sec - c->status_timer.tv_sec;
257 if (difference >= interval) {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
258 status_update_jobs(c);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
259 c->flags |= CLIENT_STATUS;
260 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
261 }
262 }
263
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
264 /* Handle data key input from client. */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
265 void
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
266 server_client_handle_key(int key, struct mouse_event *mouse, void *data)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
267 {
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
268 struct client *c = data;
269 struct session *s;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
270 struct window *w;
271 struct window_pane *wp;
272 struct options *oo;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
273 struct timeval tv;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
274 struct key_binding *bd;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
275 int xtimeout, isprefix;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
276
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
277 /* Check the client is good to accept input. */
278 if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
279 return;
280 if (c->session == NULL)
281 return;
282 s = c->session;
283
284 /* Update the activity timer. */
285 if (gettimeofday(&c->activity_time, NULL) != 0)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
286 fatal("gettimeofday failed");
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
287 memcpy(&s->activity_time, &c->activity_time, sizeof s->activity_time);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
288
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
289 w = c->session->curw->window;
290 wp = w->active;
291 oo = &c->session->options;
292
293 /* Special case: number keys jump to pane in identify mode. */
294 if (c->flags & CLIENT_IDENTIFY && key >= '0' && key <= '9') {
295 if (c->flags & CLIENT_READONLY)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
296 return;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
297 wp = window_pane_at_index(w, key - '0');
298 if (wp != NULL && window_pane_visible(wp))
299 window_set_active_pane(w, wp);
300 server_clear_identify(c);
301 return;
302 }
303
304 /* Handle status line. */
305 if (!(c->flags & CLIENT_READONLY)) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
306 status_message_clear(c);
307 server_clear_identify(c);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
308 }
309 if (c->prompt_string != NULL) {
310 if (!(c->flags & CLIENT_READONLY))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
311 status_prompt_key(c, key);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
312 return;
313 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
314
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
315 /* Check for mouse keys. */
316 if (key == KEYC_MOUSE) {
317 if (c->flags & CLIENT_READONLY)
318 return;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
319 if (options_get_number(oo, "mouse-select-pane") &&
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
320 (!(options_get_number(oo, "status") &&
321 mouse->y + 1 == c->tty.sy)) &&
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
322 ((!(mouse->b & MOUSE_DRAG) && mouse->b != MOUSE_UP) ||
323 wp->mode != &window_copy_mode)) {
324 /*
325 * Allow pane switching in copy mode only by mouse down
326 * (click).
327 */
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
328 window_set_active_at(w, mouse->x, mouse->y);
329 server_redraw_window_borders(w);
330 wp = w->active;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
331 }
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
332 if (mouse->y + 1 == c->tty.sy &&
333 options_get_number(oo, "mouse-select-window") &&
334 options_get_number(oo, "status")) {
335 if (mouse->b == MOUSE_UP &&
336 c->last_mouse.b != MOUSE_UP) {
337 status_set_window_at(c, mouse->x);
338 return;
339 }
340 if (mouse->b & MOUSE_45) {
341 if ((mouse->b & MOUSE_BUTTON) == MOUSE_1) {
342 session_previous(c->session, 0);
343 server_redraw_session(s);
344 }
345 if ((mouse->b & MOUSE_BUTTON) == MOUSE_2) {
346 session_next(c->session, 0);
347 server_redraw_session(s);
348 }
349 return;
350 }
351 }
352 if (options_get_number(oo, "mouse-resize-pane"))
353 layout_resize_pane_mouse(c, mouse);
354 memcpy(&c->last_mouse, mouse, sizeof c->last_mouse);
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
355 window_pane_mouse(wp, c->session, mouse);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
356 return;
357 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
358
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
359 /* Is this a prefix key? */
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
360 if (key == options_get_number(&c->session->options, "prefix"))
361 isprefix = 1;
362 else if (key == options_get_number(&c->session->options, "prefix2"))
363 isprefix = 1;
364 else
365 isprefix = 0;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
366
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
367 /* No previous prefix key. */
368 if (!(c->flags & CLIENT_PREFIX)) {
369 if (isprefix)
370 c->flags |= CLIENT_PREFIX;
371 else {
372 /* Try as a non-prefix key binding. */
373 if ((bd = key_bindings_lookup(key)) == NULL) {
374 if (!(c->flags & CLIENT_READONLY))
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
375 window_pane_key(wp, c->session, key);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
376 } else
377 key_bindings_dispatch(bd, c);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
378 }
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
379 return;
380 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
381
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
382 /* Prefix key already pressed. Reset prefix and lookup key. */
383 c->flags &= ~CLIENT_PREFIX;
384 if ((bd = key_bindings_lookup(key | KEYC_PREFIX)) == NULL) {
385 /* If repeating, treat this as a key, else ignore. */
386 if (c->flags & CLIENT_REPEAT) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
387 c->flags &= ~CLIENT_REPEAT;
388 if (isprefix)
389 c->flags |= CLIENT_PREFIX;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
390 else if (!(c->flags & CLIENT_READONLY))
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
391 window_pane_key(wp, c->session, key);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
392 }
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
393 return;
394 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
395
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
396 /* If already repeating, but this key can't repeat, skip it. */
397 if (c->flags & CLIENT_REPEAT && !bd->can_repeat) {
398 c->flags &= ~CLIENT_REPEAT;
399 if (isprefix)
400 c->flags |= CLIENT_PREFIX;
401 else if (!(c->flags & CLIENT_READONLY))
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
402 window_pane_key(wp, c->session, key);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
403 return;
404 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
405
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
406 /* If this key can repeat, reset the repeat flags and timer. */
407 xtimeout = options_get_number(&c->session->options, "repeat-time");
408 if (xtimeout != 0 && bd->can_repeat) {
409 c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
410
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
411 tv.tv_sec = xtimeout / 1000;
412 tv.tv_usec = (xtimeout % 1000) * 1000L;
413 evtimer_del(&c->repeat_timer);
414 evtimer_add(&c->repeat_timer, &tv);
415 }
416
417 /* Dispatch the command. */
418 key_bindings_dispatch(bd, c);
419 }
420
421 /* Client functions that need to happen every loop. */
422 void
423 server_client_loop(void)
424 {
425 struct client *c;
426 struct window *w;
427 struct window_pane *wp;
428 u_int i;
429
430 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
431 c = ARRAY_ITEM(&clients, i);
77c63de @orebokech Import upstream version 1.4
orebokech authored
432 if (c == NULL)
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
433 continue;
434
77c63de @orebokech Import upstream version 1.4
orebokech authored
435 server_client_check_exit(c);
436 if (c->session != NULL) {
437 server_client_check_redraw(c);
438 server_client_reset_state(c);
439 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
440 }
441
442 /*
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
443 * Any windows will have been redrawn as part of clients, so clear
444 * their flags now.
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
445 */
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
446 for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
447 w = ARRAY_ITEM(&windows, i);
448 if (w == NULL)
449 continue;
450
451 w->flags &= ~WINDOW_REDRAW;
452 TAILQ_FOREACH(wp, &w->panes, entry)
453 wp->flags &= ~PANE_REDRAW;
454 }
455 }
456
457 /*
458 * Update cursor position and mode settings. The scroll region and attributes
459 * are cleared when idle (waiting for an event) as this is the most likely time
460 * a user may interrupt tmux, for example with ~^Z in ssh(1). This is a
461 * compromise between excessive resets and likelihood of an interrupt.
462 *
463 * tty_region/tty_reset/tty_update_mode already take care of not resetting
464 * things that are already in their default state.
465 */
466 void
467 server_client_reset_state(struct client *c)
468 {
469 struct window *w = c->session->curw->window;
470 struct window_pane *wp = w->active;
471 struct screen *s = wp->screen;
472 struct options *oo = &c->session->options;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
473 struct options *wo = &w->options;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
474 int status, mode;
475
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
476 if (c->flags & CLIENT_SUSPENDED)
477 return;
478
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
479 tty_region(&c->tty, 0, c->tty.sy - 1);
480
481 status = options_get_number(oo, "status");
482 if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status)
483 tty_cursor(&c->tty, 0, 0);
484 else
485 tty_cursor(&c->tty, wp->xoff + s->cx, wp->yoff + s->cy);
486
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
487 /*
488 * Resizing panes with the mouse requires at least button mode to give
489 * a smooth appearance.
490 */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
491 mode = s->mode;
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
492 if ((c->last_mouse.b & MOUSE_RESIZE_PANE) &&
493 !(mode & (MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)))
494 mode |= MODE_MOUSE_BUTTON;
495
496 /*
497 * Any mode will do for mouse-select-pane, but set standard mode if
498 * none.
499 */
500 if ((mode & ALL_MOUSE_MODES) == 0) {
501 if (TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry) != NULL &&
502 options_get_number(oo, "mouse-select-pane"))
503 mode |= MODE_MOUSE_STANDARD;
504 else if (options_get_number(oo, "mouse-resize-pane"))
505 mode |= MODE_MOUSE_STANDARD;
506 else if (options_get_number(oo, "mouse-select-window"))
507 mode |= MODE_MOUSE_STANDARD;
508 else if (options_get_number(wo, "mode-mouse"))
509 mode |= MODE_MOUSE_STANDARD;
510 }
511
512 /*
513 * Set UTF-8 mouse input if required. If the terminal is UTF-8, the
514 * user has set mouse-utf8 and any mouse mode is in effect, turn on
515 * UTF-8 mouse input. If the receiving terminal hasn't requested it
516 * (that is, it isn't in s->mode), then it'll be converted in
517 * input_mouse.
518 */
519 if ((c->tty.flags & TTY_UTF8) &&
520 (mode & ALL_MOUSE_MODES) && options_get_number(oo, "mouse-utf8"))
521 mode |= MODE_MOUSE_UTF8;
522 else
523 mode &= ~MODE_MOUSE_UTF8;
524
525 /* Set the terminal mode and reset attributes. */
526 tty_update_mode(&c->tty, mode, s);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
527 tty_reset(&c->tty);
528 }
529
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
530 /* Repeat time callback. */
531 /* ARGSUSED */
532 void
533 server_client_repeat_timer(unused int fd, unused short events, void *data)
534 {
535 struct client *c = data;
536
537 if (c->flags & CLIENT_REPEAT)
538 c->flags &= ~(CLIENT_PREFIX|CLIENT_REPEAT);
539 }
540
77c63de @orebokech Import upstream version 1.4
orebokech authored
541 /* Check if client should be exited. */
542 void
543 server_client_check_exit(struct client *c)
544 {
545 struct msg_exit_data exitdata;
546
547 if (!(c->flags & CLIENT_EXIT))
548 return;
549
550 if (c->stdout_fd != -1 && c->stdout_event != NULL &&
551 EVBUFFER_LENGTH(c->stdout_event->output) != 0)
552 return;
553 if (c->stderr_fd != -1 && c->stderr_event != NULL &&
554 EVBUFFER_LENGTH(c->stderr_event->output) != 0)
555 return;
556
557 exitdata.retcode = c->retcode;
558 server_write_client(c, MSG_EXIT, &exitdata, sizeof exitdata);
559
560 c->flags &= ~CLIENT_EXIT;
561 }
562
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
563 /* Check for client redraws. */
564 void
565 server_client_check_redraw(struct client *c)
566 {
567 struct session *s = c->session;
568 struct window_pane *wp;
569 int flags, redraw;
570
571 flags = c->tty.flags & TTY_FREEZE;
572 c->tty.flags &= ~TTY_FREEZE;
573
574 if (c->flags & (CLIENT_REDRAW|CLIENT_STATUS)) {
575 if (options_get_number(&s->options, "set-titles"))
576 server_client_set_title(c);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
577
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
578 if (c->message_string != NULL)
579 redraw = status_message_redraw(c);
580 else if (c->prompt_string != NULL)
581 redraw = status_prompt_redraw(c);
582 else
583 redraw = status_redraw(c);
584 if (!redraw)
585 c->flags &= ~CLIENT_STATUS;
586 }
587
588 if (c->flags & CLIENT_REDRAW) {
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
589 screen_redraw_screen(c, 0, 0);
590 c->flags &= ~(CLIENT_STATUS|CLIENT_BORDERS);
77c63de @orebokech Import upstream version 1.4
orebokech authored
591 } else if (c->flags & CLIENT_REDRAWWINDOW) {
592 TAILQ_FOREACH(wp, &c->session->curw->window->panes, entry)
593 screen_redraw_pane(c, wp);
594 c->flags &= ~CLIENT_REDRAWWINDOW;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
595 } else {
596 TAILQ_FOREACH(wp, &c->session->curw->window->panes, entry) {
597 if (wp->flags & PANE_REDRAW)
598 screen_redraw_pane(c, wp);
599 }
600 }
601
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
602 if (c->flags & CLIENT_BORDERS)
603 screen_redraw_screen(c, 0, 1);
604
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
605 if (c->flags & CLIENT_STATUS)
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
606 screen_redraw_screen(c, 1, 0);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
607
608 c->tty.flags |= flags;
609
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
610 c->flags &= ~(CLIENT_REDRAW|CLIENT_STATUS|CLIENT_BORDERS);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
611 }
612
613 /* Set client title. */
614 void
615 server_client_set_title(struct client *c)
616 {
617 struct session *s = c->session;
618 const char *template;
619 char *title;
620
621 template = options_get_string(&s->options, "set-titles-string");
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
622
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
623 title = status_replace(c, NULL, NULL, NULL, template, time(NULL), 1);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
624 if (c->title == NULL || strcmp(title, c->title) != 0) {
625 if (c->title != NULL)
626 xfree(c->title);
627 c->title = xstrdup(title);
628 tty_set_title(&c->tty, c->title);
629 }
630 xfree(title);
631 }
632
77c63de @orebokech Import upstream version 1.4
orebokech authored
633 /*
634 * Error callback for client stdin. Caller must increase reference count when
635 * enabling event!
636 */
637 void
638 server_client_in_callback(
639 unused struct bufferevent *bufev, unused short what, void *data)
640 {
641 struct client *c = data;
642
643 c->references--;
644 if (c->flags & CLIENT_DEAD)
645 return;
646
647 bufferevent_disable(c->stdin_event, EV_READ|EV_WRITE);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
648 setblocking(c->stdin_fd, 1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
649 close(c->stdin_fd);
650 c->stdin_fd = -1;
651
652 if (c->stdin_callback != NULL)
653 c->stdin_callback(c, c->stdin_data);
654 }
655
656 /* Error callback for client stdout. */
657 void
658 server_client_out_callback(
659 unused struct bufferevent *bufev, unused short what, unused void *data)
660 {
661 struct client *c = data;
662
663 bufferevent_disable(c->stdout_event, EV_READ|EV_WRITE);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
664 setblocking(c->stdout_fd, 1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
665 close(c->stdout_fd);
666 c->stdout_fd = -1;
667 }
668
669 /* Error callback for client stderr. */
670 void
671 server_client_err_callback(
672 unused struct bufferevent *bufev, unused short what, unused void *data)
673 {
674 struct client *c = data;
675
676 bufferevent_disable(c->stderr_event, EV_READ|EV_WRITE);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
677 setblocking(c->stderr_fd, 1);
77c63de @orebokech Import upstream version 1.4
orebokech authored
678 close(c->stderr_fd);
679 c->stderr_fd = -1;
680 }
681
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
682 /* Dispatch message from client. */
683 int
684 server_client_msg_dispatch(struct client *c)
685 {
686 struct imsg imsg;
687 struct msg_command_data commanddata;
688 struct msg_identify_data identifydata;
689 struct msg_environ_data environdata;
690 ssize_t n, datalen;
691
692 if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
693 return (-1);
694
695 for (;;) {
696 if ((n = imsg_get(&c->ibuf, &imsg)) == -1)
697 return (-1);
698 if (n == 0)
699 return (0);
700 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
701
702 if (imsg.hdr.peerid != PROTOCOL_VERSION) {
703 server_write_client(c, MSG_VERSION, NULL, 0);
704 c->flags |= CLIENT_BAD;
705 imsg_free(&imsg);
706 continue;
707 }
708
709 log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd);
710 switch (imsg.hdr.type) {
711 case MSG_COMMAND:
712 if (datalen != sizeof commanddata)
713 fatalx("bad MSG_COMMAND size");
714 memcpy(&commanddata, imsg.data, sizeof commanddata);
715
716 server_client_msg_command(c, &commanddata);
717 break;
718 case MSG_IDENTIFY:
719 if (datalen != sizeof identifydata)
720 fatalx("bad MSG_IDENTIFY size");
721 if (imsg.fd == -1)
722 fatalx("MSG_IDENTIFY missing fd");
723 memcpy(&identifydata, imsg.data, sizeof identifydata);
724
77c63de @orebokech Import upstream version 1.4
orebokech authored
725 c->stdin_fd = imsg.fd;
726 c->stdin_event = bufferevent_new(c->stdin_fd,
727 NULL, NULL, server_client_in_callback, c);
728 if (c->stdin_event == NULL)
729 fatalx("failed to create stdin event");
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
730 setblocking(c->stdin_fd, 0);
77c63de @orebokech Import upstream version 1.4
orebokech authored
731
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
732 server_client_msg_identify(c, &identifydata, imsg.fd);
733 break;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
734 case MSG_STDOUT:
735 if (datalen != 0)
736 fatalx("bad MSG_STDOUT size");
737 if (imsg.fd == -1)
738 fatalx("MSG_STDOUT missing fd");
739
77c63de @orebokech Import upstream version 1.4
orebokech authored
740 c->stdout_fd = imsg.fd;
741 c->stdout_event = bufferevent_new(c->stdout_fd,
742 NULL, NULL, server_client_out_callback, c);
743 if (c->stdout_event == NULL)
744 fatalx("failed to create stdout event");
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
745 setblocking(c->stdout_fd, 0);
77c63de @orebokech Import upstream version 1.4
orebokech authored
746
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
747 break;
748 case MSG_STDERR:
749 if (datalen != 0)
750 fatalx("bad MSG_STDERR size");
751 if (imsg.fd == -1)
752 fatalx("MSG_STDERR missing fd");
753
77c63de @orebokech Import upstream version 1.4
orebokech authored
754 c->stderr_fd = imsg.fd;
755 c->stderr_event = bufferevent_new(c->stderr_fd,
756 NULL, NULL, server_client_err_callback, c);
757 if (c->stderr_event == NULL)
758 fatalx("failed to create stderr event");
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
759 setblocking(c->stderr_fd, 0);
77c63de @orebokech Import upstream version 1.4
orebokech authored
760
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
761 break;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
762 case MSG_RESIZE:
763 if (datalen != 0)
764 fatalx("bad MSG_RESIZE size");
765
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
766 if (tty_resize(&c->tty)) {
767 recalculate_sizes();
768 server_redraw_client(c);
769 }
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
770 break;
771 case MSG_EXITING:
772 if (datalen != 0)
773 fatalx("bad MSG_EXITING size");
774
775 c->session = NULL;
776 tty_close(&c->tty);
777 server_write_client(c, MSG_EXITED, NULL, 0);
778 break;
779 case MSG_WAKEUP:
780 case MSG_UNLOCK:
781 if (datalen != 0)
782 fatalx("bad MSG_WAKEUP size");
783
784 if (!(c->flags & CLIENT_SUSPENDED))
785 break;
786 c->flags &= ~CLIENT_SUSPENDED;
787
788 if (gettimeofday(&c->activity_time, NULL) != 0)
789 fatal("gettimeofday");
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
790 if (c->session != NULL)
791 session_update_activity(c->session);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
792
793 tty_start_tty(&c->tty);
794 server_redraw_client(c);
795 recalculate_sizes();
796 break;
797 case MSG_ENVIRON:
798 if (datalen != sizeof environdata)
799 fatalx("bad MSG_ENVIRON size");
800 memcpy(&environdata, imsg.data, sizeof environdata);
801
802 environdata.var[(sizeof environdata.var) - 1] = '\0';
803 if (strchr(environdata.var, '=') != NULL)
804 environ_put(&c->environ, environdata.var);
805 break;
806 case MSG_SHELL:
807 if (datalen != 0)
808 fatalx("bad MSG_SHELL size");
809
810 server_client_msg_shell(c);
811 break;
812 default:
813 fatalx("unexpected message");
814 }
815
816 imsg_free(&imsg);
817 }
818 }
819
820 /* Callback to send error message to client. */
821 void printflike2
822 server_client_msg_error(struct cmd_ctx *ctx, const char *fmt, ...)
823 {
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
824 va_list ap;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
825
826 va_start(ap, fmt);
77c63de @orebokech Import upstream version 1.4
orebokech authored
827 evbuffer_add_vprintf(ctx->cmdclient->stderr_event->output, fmt, ap);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
828 va_end(ap);
829
77c63de @orebokech Import upstream version 1.4
orebokech authored
830 bufferevent_write(ctx->cmdclient->stderr_event, "\n", 1);
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
831 ctx->cmdclient->retcode = 1;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
832 }
833
834 /* Callback to send print message to client. */
835 void printflike2
836 server_client_msg_print(struct cmd_ctx *ctx, const char *fmt, ...)
837 {
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
838 va_list ap;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
839
840 va_start(ap, fmt);
77c63de @orebokech Import upstream version 1.4
orebokech authored
841 evbuffer_add_vprintf(ctx->cmdclient->stdout_event->output, fmt, ap);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
842 va_end(ap);
843
77c63de @orebokech Import upstream version 1.4
orebokech authored
844 bufferevent_write(ctx->cmdclient->stdout_event, "\n", 1);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
845 }
846
847 /* Callback to send print message to client, if not quiet. */
848 void printflike2
849 server_client_msg_info(struct cmd_ctx *ctx, const char *fmt, ...)
850 {
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
851 va_list ap;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
852
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
853 if (options_get_number(&global_options, "quiet"))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
854 return;
855
856 va_start(ap, fmt);
77c63de @orebokech Import upstream version 1.4
orebokech authored
857 evbuffer_add_vprintf(ctx->cmdclient->stdout_event->output, fmt, ap);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
858 va_end(ap);
859
77c63de @orebokech Import upstream version 1.4
orebokech authored
860 bufferevent_write(ctx->cmdclient->stdout_event, "\n", 1);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
861 }
862
863 /* Handle command message. */
864 void
865 server_client_msg_command(struct client *c, struct msg_command_data *data)
866 {
77c63de @orebokech Import upstream version 1.4
orebokech authored
867 struct cmd_ctx ctx;
868 struct cmd_list *cmdlist = NULL;
869 int argc;
870 char **argv, *cause;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
871
872 ctx.error = server_client_msg_error;
873 ctx.print = server_client_msg_print;
874 ctx.info = server_client_msg_info;
875
876 ctx.msgdata = data;
877 ctx.curclient = NULL;
878
879 ctx.cmdclient = c;
880
881 argc = data->argc;
882 data->argv[(sizeof data->argv) - 1] = '\0';
883 if (cmd_unpack_argv(data->argv, sizeof data->argv, argc, &argv) != 0) {
884 server_client_msg_error(&ctx, "command too long");
885 goto error;
886 }
887
888 if (argc == 0) {
889 argc = 1;
890 argv = xcalloc(1, sizeof *argv);
891 *argv = xstrdup("new-session");
892 }
893
894 if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
895 server_client_msg_error(&ctx, "%s", cause);
896 cmd_free_argv(argc, argv);
897 goto error;
898 }
899 cmd_free_argv(argc, argv);
900
77c63de @orebokech Import upstream version 1.4
orebokech authored
901 if (cmd_list_exec(cmdlist, &ctx) != 1)
902 c->flags |= CLIENT_EXIT;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
903 cmd_list_free(cmdlist);
904 return;
905
906 error:
907 if (cmdlist != NULL)
908 cmd_list_free(cmdlist);
77c63de @orebokech Import upstream version 1.4
orebokech authored
909 c->flags |= CLIENT_EXIT;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
910 }
911
912 /* Handle identify message. */
913 void
914 server_client_msg_identify(
915 struct client *c, struct msg_identify_data *data, int fd)
916 {
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
917 int tty_fd;
918
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
919 c->cwd = NULL;
920 data->cwd[(sizeof data->cwd) - 1] = '\0';
921 if (*data->cwd != '\0')
922 c->cwd = xstrdup(data->cwd);
923
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
924 if (!isatty(fd))
925 return;
926 if ((tty_fd = dup(fd)) == -1)
927 fatal("dup failed");
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
928 data->term[(sizeof data->term) - 1] = '\0';
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
929 tty_init(&c->tty, tty_fd, data->term);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
930 if (data->flags & IDENTIFY_UTF8)
931 c->tty.flags |= TTY_UTF8;
932 if (data->flags & IDENTIFY_256COLOURS)
933 c->tty.term_flags |= TERM_256COLOURS;
934 else if (data->flags & IDENTIFY_88COLOURS)
935 c->tty.term_flags |= TERM_88COLOURS;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
936 c->tty.key_callback = server_client_handle_key;
937 c->tty.key_data = c;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
938
939 tty_resize(&c->tty);
940
941 c->flags |= CLIENT_TERMINAL;
942 }
943
944 /* Handle shell message. */
945 void
946 server_client_msg_shell(struct client *c)
947 {
948 struct msg_shell_data data;
949 const char *shell;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
950
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
951 shell = options_get_string(&global_s_options, "default-shell");
952
953 if (*shell == '\0' || areshell(shell))
954 shell = _PATH_BSHELL;
955 if (strlcpy(data.shell, shell, sizeof data.shell) >= sizeof data.shell)
956 strlcpy(data.shell, _PATH_BSHELL, sizeof data.shell);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
957
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
958 server_write_client(c, MSG_SHELL, &data, sizeof data);
959 c->flags |= CLIENT_BAD; /* it will die after exec */
960 }
Something went wrong with that request. Please try again.