2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2015-10-27 13:23:24 +00:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/uio.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-10-27 13:23:24 +00:00
|
|
|
#include <imsg.h>
|
2012-07-10 11:53:01 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <string.h>
|
2009-07-14 06:59:06 +00:00
|
|
|
#include <time.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static struct session *server_next_session(struct session *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void server_destroy_session_group(struct session *);
|
2009-11-04 23:29:42 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
server_redraw_client(struct client *c)
|
|
|
|
{
|
|
|
|
c->flags |= CLIENT_REDRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_status_client(struct client *c)
|
|
|
|
{
|
|
|
|
c->flags |= CLIENT_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_redraw_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
2009-06-01 22:58:49 +00:00
|
|
|
if (c->session == s)
|
|
|
|
server_redraw_client(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-10 10:02:48 +00:00
|
|
|
void
|
|
|
|
server_redraw_session_group(struct session *s)
|
|
|
|
{
|
|
|
|
struct session_group *sg;
|
|
|
|
|
2017-02-09 15:04:53 +00:00
|
|
|
if ((sg = session_group_contains(s)) == NULL)
|
2009-10-10 10:02:48 +00:00
|
|
|
server_redraw_session(s);
|
|
|
|
else {
|
|
|
|
TAILQ_FOREACH(s, &sg->sessions, gentry)
|
|
|
|
server_redraw_session(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
server_status_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
2009-06-01 22:58:49 +00:00
|
|
|
if (c->session == s)
|
|
|
|
server_status_client(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-10 10:02:48 +00:00
|
|
|
void
|
|
|
|
server_status_session_group(struct session *s)
|
|
|
|
{
|
|
|
|
struct session_group *sg;
|
|
|
|
|
2017-02-09 15:04:53 +00:00
|
|
|
if ((sg = session_group_contains(s)) == NULL)
|
2009-10-10 10:02:48 +00:00
|
|
|
server_status_session(s);
|
|
|
|
else {
|
|
|
|
TAILQ_FOREACH(s, &sg->sessions, gentry)
|
|
|
|
server_status_session(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
server_redraw_window(struct window *w)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != NULL && c->session->curw->window == w)
|
2009-06-01 22:58:49 +00:00
|
|
|
server_redraw_client(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-03 12:51:05 +00:00
|
|
|
void
|
|
|
|
server_redraw_window_borders(struct window *w)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != NULL && c->session->curw->window == w)
|
2010-01-03 12:51:05 +00:00
|
|
|
c->flags |= CLIENT_BORDERS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
server_status_window(struct window *w)
|
|
|
|
{
|
|
|
|
struct session *s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is slightly different. We want to redraw the status line of any
|
2013-03-24 09:54:10 +00:00
|
|
|
* clients containing this window rather than anywhere it is the
|
2009-06-01 22:58:49 +00:00
|
|
|
* current window.
|
|
|
|
*/
|
|
|
|
|
2010-12-21 22:37:59 +00:00
|
|
|
RB_FOREACH(s, sessions, &sessions) {
|
2015-04-22 15:32:33 +00:00
|
|
|
if (session_has(s, w))
|
2009-06-01 22:58:49 +00:00
|
|
|
server_status_session(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_lock(void)
|
|
|
|
{
|
2009-09-24 14:17:09 +00:00
|
|
|
struct client *c;
|
2009-09-02 16:38:35 +00:00
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != NULL)
|
|
|
|
server_lock_client(c);
|
2009-09-24 14:17:09 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-09-24 14:17:09 +00:00
|
|
|
void
|
|
|
|
server_lock_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session == s)
|
|
|
|
server_lock_client(c);
|
2009-12-03 22:50:09 +00:00
|
|
|
}
|
2009-09-24 14:17:09 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-09-24 14:17:09 +00:00
|
|
|
void
|
|
|
|
server_lock_client(struct client *c)
|
|
|
|
{
|
2013-10-10 12:13:56 +00:00
|
|
|
const char *cmd;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2013-03-22 10:42:55 +00:00
|
|
|
if (c->flags & CLIENT_CONTROL)
|
2013-03-21 18:47:01 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-04 10:55:30 +00:00
|
|
|
if (c->flags & CLIENT_SUSPENDED)
|
|
|
|
return;
|
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
cmd = options_get_string(c->session->options, "lock-command");
|
2017-08-29 09:18:48 +00:00
|
|
|
if (*cmd == '\0' || strlen(cmd) + 1 > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
|
2009-09-24 14:17:09 +00:00
|
|
|
return;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-09-24 14:17:09 +00:00
|
|
|
tty_stop_tty(&c->tty);
|
|
|
|
tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_SMCUP));
|
|
|
|
tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_CLEAR));
|
2011-10-23 10:16:14 +00:00
|
|
|
tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_E3));
|
2009-09-24 14:17:09 +00:00
|
|
|
|
|
|
|
c->flags |= CLIENT_SUSPENDED;
|
2017-07-12 09:07:52 +00:00
|
|
|
proc_send(c->peer, MSG_LOCK, -1, cmd, strlen(cmd) + 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-07-17 20:37:03 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
server_kill_window(struct window *w)
|
|
|
|
{
|
2013-07-05 14:52:33 +00:00
|
|
|
struct session *s, *next_s, *target_s;
|
|
|
|
struct session_group *sg;
|
|
|
|
struct winlink *wl;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2010-12-23 21:56:38 +00:00
|
|
|
next_s = RB_MIN(sessions, &sessions);
|
|
|
|
while (next_s != NULL) {
|
|
|
|
s = next_s;
|
|
|
|
next_s = RB_NEXT(sessions, &sessions, s);
|
|
|
|
|
2015-04-22 15:32:33 +00:00
|
|
|
if (!session_has(s, w))
|
2009-07-17 20:37:03 +00:00
|
|
|
continue;
|
2015-01-06 09:12:53 +00:00
|
|
|
server_unzoom_window(w);
|
2010-01-23 21:07:31 +00:00
|
|
|
while ((wl = winlink_find_by_window(&s->windows, w)) != NULL) {
|
|
|
|
if (session_detach(s, wl)) {
|
|
|
|
server_destroy_session_group(s);
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
server_redraw_session_group(s);
|
|
|
|
}
|
2012-04-29 17:20:01 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
if (options_get_number(s->options, "renumber-windows")) {
|
2017-02-09 15:04:53 +00:00
|
|
|
if ((sg = session_group_contains(s)) != NULL) {
|
2013-07-05 14:52:33 +00:00
|
|
|
TAILQ_FOREACH(target_s, &sg->sessions, gentry)
|
|
|
|
session_renumber_windows(target_s);
|
|
|
|
} else
|
|
|
|
session_renumber_windows(s);
|
|
|
|
}
|
2009-07-17 20:37:03 +00:00
|
|
|
}
|
2013-04-22 13:35:18 +00:00
|
|
|
recalculate_sizes();
|
2009-09-20 17:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-10 10:02:48 +00:00
|
|
|
server_link_window(struct session *src, struct winlink *srcwl,
|
2014-04-17 14:45:49 +00:00
|
|
|
struct session *dst, int dstidx, int killflag, int selectflag,
|
|
|
|
char **cause)
|
2009-09-20 17:27:18 +00:00
|
|
|
{
|
2009-10-10 10:02:48 +00:00
|
|
|
struct winlink *dstwl;
|
|
|
|
struct session_group *srcsg, *dstsg;
|
|
|
|
|
2017-02-09 15:04:53 +00:00
|
|
|
srcsg = session_group_contains(src);
|
|
|
|
dstsg = session_group_contains(dst);
|
2009-10-10 10:02:48 +00:00
|
|
|
if (src != dst && srcsg != NULL && dstsg != NULL && srcsg == dstsg) {
|
|
|
|
xasprintf(cause, "sessions are grouped");
|
|
|
|
return (-1);
|
|
|
|
}
|
2009-09-20 17:27:18 +00:00
|
|
|
|
|
|
|
dstwl = NULL;
|
|
|
|
if (dstidx != -1)
|
|
|
|
dstwl = winlink_find_by_index(&dst->windows, dstidx);
|
|
|
|
if (dstwl != NULL) {
|
2010-10-09 12:58:00 +00:00
|
|
|
if (dstwl->window == srcwl->window) {
|
|
|
|
xasprintf(cause, "same index: %d", dstidx);
|
2010-08-11 07:36:23 +00:00
|
|
|
return (-1);
|
2010-10-09 12:58:00 +00:00
|
|
|
}
|
2009-09-20 17:27:18 +00:00
|
|
|
if (killflag) {
|
|
|
|
/*
|
|
|
|
* Can't use session_detach as it will destroy session
|
|
|
|
* if this makes it empty.
|
|
|
|
*/
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_session_window("window-unlinked", dst,
|
|
|
|
dstwl->window);
|
2010-06-21 01:27:46 +00:00
|
|
|
dstwl->flags &= ~WINLINK_ALERTFLAGS;
|
2009-09-20 17:27:18 +00:00
|
|
|
winlink_stack_remove(&dst->lastw, dstwl);
|
|
|
|
winlink_remove(&dst->windows, dstwl);
|
|
|
|
|
|
|
|
/* Force select/redraw if current. */
|
2009-10-11 10:39:27 +00:00
|
|
|
if (dstwl == dst->curw) {
|
2009-09-20 17:27:18 +00:00
|
|
|
selectflag = 1;
|
2009-10-11 10:39:27 +00:00
|
|
|
dst->curw = NULL;
|
|
|
|
}
|
2009-09-20 17:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstidx == -1)
|
2015-10-27 15:58:42 +00:00
|
|
|
dstidx = -1 - options_get_number(dst->options, "base-index");
|
2009-09-20 17:27:18 +00:00
|
|
|
dstwl = session_attach(dst, srcwl->window, dstidx, cause);
|
|
|
|
if (dstwl == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
2009-10-10 10:02:48 +00:00
|
|
|
if (selectflag)
|
2009-09-20 17:27:18 +00:00
|
|
|
session_select(dst, dstwl->idx);
|
2009-10-10 10:02:48 +00:00
|
|
|
server_redraw_session_group(dst);
|
2009-09-20 17:27:18 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_unlink_window(struct session *s, struct winlink *wl)
|
|
|
|
{
|
|
|
|
if (session_detach(s, wl))
|
2009-10-10 10:02:48 +00:00
|
|
|
server_destroy_session_group(s);
|
2009-09-20 17:27:18 +00:00
|
|
|
else
|
2009-10-10 10:02:48 +00:00
|
|
|
server_redraw_session_group(s);
|
|
|
|
}
|
|
|
|
|
2009-11-13 17:33:07 +00:00
|
|
|
void
|
2016-10-16 22:06:40 +00:00
|
|
|
server_destroy_pane(struct window_pane *wp, int notify)
|
2009-11-13 17:33:07 +00:00
|
|
|
{
|
2011-09-05 23:40:51 +00:00
|
|
|
struct window *w = wp->window;
|
|
|
|
int old_fd;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
struct grid_cell gc;
|
2009-11-13 17:33:07 +00:00
|
|
|
|
2011-09-05 23:40:51 +00:00
|
|
|
old_fd = wp->fd;
|
2010-04-17 23:25:16 +00:00
|
|
|
if (wp->fd != -1) {
|
|
|
|
bufferevent_free(wp->event);
|
2012-01-29 02:22:11 +00:00
|
|
|
close(wp->fd);
|
2010-04-17 23:25:16 +00:00
|
|
|
wp->fd = -1;
|
|
|
|
}
|
2009-11-13 17:33:07 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
if (options_get_number(w->options, "remain-on-exit")) {
|
2011-09-05 23:40:51 +00:00
|
|
|
if (old_fd == -1)
|
|
|
|
return;
|
2016-10-16 22:06:40 +00:00
|
|
|
|
|
|
|
if (notify)
|
|
|
|
notify_pane("pane-died", wp);
|
|
|
|
|
2011-09-05 23:40:51 +00:00
|
|
|
screen_write_start(&ctx, wp, &wp->base);
|
|
|
|
screen_write_scrollregion(&ctx, 0, screen_size_y(ctx.s) - 1);
|
|
|
|
screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1);
|
2017-05-12 13:00:56 +00:00
|
|
|
screen_write_linefeed(&ctx, 1, 8);
|
2011-09-05 23:40:51 +00:00
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
gc.attr |= GRID_ATTR_BRIGHT;
|
|
|
|
screen_write_puts(&ctx, &gc, "Pane is dead");
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
wp->flags |= PANE_REDRAW;
|
2015-12-16 21:50:37 +00:00
|
|
|
|
2009-11-13 17:33:07 +00:00
|
|
|
return;
|
2011-09-05 23:40:51 +00:00
|
|
|
}
|
2009-11-13 17:33:07 +00:00
|
|
|
|
2016-10-16 22:06:40 +00:00
|
|
|
if (notify)
|
|
|
|
notify_pane("pane-exited", wp);
|
|
|
|
|
2013-03-24 09:57:59 +00:00
|
|
|
server_unzoom_window(w);
|
2009-11-13 17:33:07 +00:00
|
|
|
layout_close_pane(wp);
|
|
|
|
window_remove_pane(w, wp);
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&w->panes))
|
|
|
|
server_kill_window(w);
|
|
|
|
else
|
|
|
|
server_redraw_window(w);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-10-10 10:02:48 +00:00
|
|
|
server_destroy_session_group(struct session *s)
|
|
|
|
{
|
|
|
|
struct session_group *sg;
|
2013-10-10 11:46:28 +00:00
|
|
|
struct session *s1;
|
2009-10-10 10:02:48 +00:00
|
|
|
|
2017-02-09 15:04:53 +00:00
|
|
|
if ((sg = session_group_contains(s)) == NULL)
|
2009-10-10 10:02:48 +00:00
|
|
|
server_destroy_session(s);
|
|
|
|
else {
|
2013-10-10 11:46:28 +00:00
|
|
|
TAILQ_FOREACH_SAFE(s, &sg->sessions, gentry, s1) {
|
2009-10-10 10:02:48 +00:00
|
|
|
server_destroy_session(s);
|
2017-07-09 22:33:09 +00:00
|
|
|
session_destroy(s, __func__);
|
2013-10-10 11:46:28 +00:00
|
|
|
}
|
2009-10-10 10:02:48 +00:00
|
|
|
}
|
2009-07-17 20:37:03 +00:00
|
|
|
}
|
2009-08-31 20:46:19 +00:00
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static struct session *
|
2010-06-27 00:22:22 +00:00
|
|
|
server_next_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct session *s_loop, *s_out;
|
|
|
|
|
|
|
|
s_out = NULL;
|
2010-12-21 22:37:59 +00:00
|
|
|
RB_FOREACH(s_loop, sessions, &sessions) {
|
|
|
|
if (s_loop == s)
|
2010-06-27 00:22:22 +00:00
|
|
|
continue;
|
|
|
|
if (s_out == NULL ||
|
|
|
|
timercmp(&s_loop->activity_time, &s_out->activity_time, <))
|
|
|
|
s_out = s_loop;
|
|
|
|
}
|
|
|
|
return (s_out);
|
|
|
|
}
|
|
|
|
|
2009-09-12 13:01:19 +00:00
|
|
|
void
|
|
|
|
server_destroy_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct client *c;
|
2010-06-27 00:22:22 +00:00
|
|
|
struct session *s_new;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
if (!options_get_number(s->options, "detach-on-destroy"))
|
2010-06-27 00:22:22 +00:00
|
|
|
s_new = server_next_session(s);
|
|
|
|
else
|
|
|
|
s_new = NULL;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != s)
|
2009-09-12 13:01:19 +00:00
|
|
|
continue;
|
2010-06-27 00:22:22 +00:00
|
|
|
if (s_new == NULL) {
|
|
|
|
c->session = NULL;
|
2010-07-24 20:11:59 +00:00
|
|
|
c->flags |= CLIENT_EXIT;
|
2010-06-27 00:22:22 +00:00
|
|
|
} else {
|
2010-12-20 00:17:22 +00:00
|
|
|
c->last_session = NULL;
|
2010-06-27 00:22:22 +00:00
|
|
|
c->session = s_new;
|
2015-12-12 18:32:24 +00:00
|
|
|
server_client_set_key_table(c, NULL);
|
2015-08-28 12:16:28 +00:00
|
|
|
status_timer_start(c);
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_client("client-session-changed", c);
|
2015-08-28 13:01:03 +00:00
|
|
|
session_update_activity(s_new, NULL);
|
2015-09-10 08:58:14 +00:00
|
|
|
gettimeofday(&s_new->last_attached_time, NULL);
|
2010-06-27 00:22:22 +00:00
|
|
|
server_redraw_client(c);
|
2015-12-11 12:39:47 +00:00
|
|
|
alerts_check_session(s_new);
|
2010-06-27 00:22:22 +00:00
|
|
|
}
|
2009-09-12 13:01:19 +00:00
|
|
|
}
|
2010-06-26 23:55:50 +00:00
|
|
|
recalculate_sizes();
|
2009-09-12 13:01:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 20:43:30 +00:00
|
|
|
void
|
2014-02-14 13:59:01 +00:00
|
|
|
server_check_unattached(void)
|
2010-09-26 20:43:30 +00:00
|
|
|
{
|
|
|
|
struct session *s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If any sessions are no longer attached and have destroy-unattached
|
|
|
|
* set, collect them.
|
|
|
|
*/
|
2010-12-21 22:37:59 +00:00
|
|
|
RB_FOREACH(s, sessions, &sessions) {
|
|
|
|
if (!(s->flags & SESSION_UNATTACHED))
|
2010-09-26 20:43:30 +00:00
|
|
|
continue;
|
2015-10-27 15:58:42 +00:00
|
|
|
if (options_get_number (s->options, "destroy-unattached"))
|
2017-07-09 22:33:09 +00:00
|
|
|
session_destroy(s, __func__);
|
2010-09-26 20:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 18:27:42 +00:00
|
|
|
/* Set stdin callback. */
|
|
|
|
int
|
|
|
|
server_set_stdin_callback(struct client *c, void (*cb)(struct client *, int,
|
|
|
|
void *), void *cb_data, char **cause)
|
|
|
|
{
|
2013-03-24 09:54:10 +00:00
|
|
|
if (c == NULL || c->session != NULL) {
|
2012-05-21 18:27:42 +00:00
|
|
|
*cause = xstrdup("no client with stdin");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (c->flags & CLIENT_TERMINAL) {
|
|
|
|
*cause = xstrdup("stdin is a tty");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (c->stdin_callback != NULL) {
|
|
|
|
*cause = xstrdup("stdin in use");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
c->stdin_callback_data = cb_data;
|
|
|
|
c->stdin_callback = cb;
|
|
|
|
|
|
|
|
c->references++;
|
|
|
|
|
|
|
|
if (c->stdin_closed)
|
2014-02-14 13:59:01 +00:00
|
|
|
c->stdin_callback(c, 1, c->stdin_callback_data);
|
2012-09-03 08:48:57 +00:00
|
|
|
|
2015-10-27 13:23:24 +00:00
|
|
|
proc_send(c->peer, MSG_STDIN, -1, NULL, 0);
|
2012-09-03 08:48:57 +00:00
|
|
|
|
2012-05-21 18:27:42 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2013-03-24 09:57:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
server_unzoom_window(struct window *w)
|
|
|
|
{
|
2015-04-19 21:34:21 +00:00
|
|
|
if (window_unzoom(w) == 0) {
|
|
|
|
server_redraw_window(w);
|
|
|
|
server_status_window(w);
|
|
|
|
}
|
2013-03-24 09:57:59 +00:00
|
|
|
}
|