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>
|
2017-10-12 11:32:27 +00:00
|
|
|
#include <sys/wait.h>
|
2015-10-27 13:23:24 +00:00
|
|
|
#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)
|
|
|
|
{
|
2018-08-19 16:45:03 +00:00
|
|
|
c->flags |= CLIENT_ALLREDRAWFLAGS;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_status_client(struct client *c)
|
|
|
|
{
|
2018-08-19 16:45:03 +00:00
|
|
|
c->flags |= CLIENT_REDRAWSTATUS;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-08-19 16:45:03 +00:00
|
|
|
c->flags |= CLIENT_REDRAWBORDERS;
|
2010-01-03 12:51:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-04-10 10:48:44 +00:00
|
|
|
void
|
|
|
|
server_kill_pane(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window *w = wp->window;
|
|
|
|
|
|
|
|
if (window_count_panes(w) == 1) {
|
2020-07-04 14:24:02 +00:00
|
|
|
server_kill_window(w, 1);
|
2018-04-10 10:48:44 +00:00
|
|
|
recalculate_sizes();
|
|
|
|
} else {
|
|
|
|
server_unzoom_window(w);
|
2020-05-16 16:20:59 +00:00
|
|
|
server_client_remove_pane(wp);
|
2018-04-10 10:48:44 +00:00
|
|
|
layout_close_pane(wp);
|
|
|
|
window_remove_pane(w, wp);
|
|
|
|
server_redraw_window(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 20:37:03 +00:00
|
|
|
void
|
2020-07-04 14:24:02 +00:00
|
|
|
server_kill_window(struct window *w, int renumber)
|
2009-07-17 20:37:03 +00:00
|
|
|
{
|
2020-07-04 14:24:02 +00:00
|
|
|
struct session *s, *s1;
|
|
|
|
struct winlink *wl;
|
2010-12-23 21:56:38 +00:00
|
|
|
|
2020-07-04 14:24:02 +00:00
|
|
|
RB_FOREACH_SAFE(s, sessions, &sessions, s1) {
|
2015-04-22 15:32:33 +00:00
|
|
|
if (!session_has(s, w))
|
2009-07-17 20:37:03 +00:00
|
|
|
continue;
|
2020-07-04 14:24:02 +00:00
|
|
|
|
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
|
|
|
|
2020-07-04 14:24:02 +00:00
|
|
|
if (renumber)
|
|
|
|
server_renumber_session(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
|
|
|
}
|
|
|
|
|
2020-07-04 14:24:02 +00:00
|
|
|
void
|
|
|
|
server_renumber_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct session_group *sg;
|
|
|
|
|
|
|
|
if (options_get_number(s->options, "renumber-windows")) {
|
|
|
|
if ((sg = session_group_contains(s)) != NULL) {
|
|
|
|
TAILQ_FOREACH(s, &sg->sessions, gentry)
|
|
|
|
session_renumber_windows(s);
|
|
|
|
} else
|
|
|
|
session_renumber_windows(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
server_renumber_all(void)
|
|
|
|
{
|
|
|
|
struct session *s;
|
|
|
|
|
|
|
|
RB_FOREACH(s, sessions, &sessions)
|
|
|
|
server_renumber_session(s);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
struct grid_cell gc;
|
2017-10-12 11:32:27 +00:00
|
|
|
time_t t;
|
|
|
|
char tim[26];
|
2021-01-04 08:43:16 +00:00
|
|
|
int remain_on_exit;
|
2009-11-13 17:33:07 +00:00
|
|
|
|
2010-04-17 23:25:16 +00:00
|
|
|
if (wp->fd != -1) {
|
|
|
|
bufferevent_free(wp->event);
|
2018-11-30 08:44:40 +00:00
|
|
|
wp->event = NULL;
|
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
|
|
|
|
2021-01-04 08:43:16 +00:00
|
|
|
remain_on_exit = options_get_number(wp->options, "remain-on-exit");
|
|
|
|
if (remain_on_exit != 0 && (~wp->flags & PANE_STATUSREADY))
|
|
|
|
return;
|
|
|
|
switch (remain_on_exit) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (WIFEXITED(wp->status) && WEXITSTATUS(wp->status) == 0)
|
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 1:
|
2017-10-12 11:32:27 +00:00
|
|
|
if (wp->flags & PANE_STATUSDRAWN)
|
|
|
|
return;
|
|
|
|
wp->flags |= PANE_STATUSDRAWN;
|
|
|
|
|
2016-10-16 22:06:40 +00:00
|
|
|
if (notify)
|
|
|
|
notify_pane("pane-died", wp);
|
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, &wp->base);
|
2011-09-05 23:40:51 +00:00
|
|
|
screen_write_scrollregion(&ctx, 0, screen_size_y(ctx.s) - 1);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1, 0);
|
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);
|
2017-10-12 11:32:27 +00:00
|
|
|
|
|
|
|
time(&t);
|
|
|
|
ctime_r(&t, tim);
|
2020-07-30 07:32:52 +00:00
|
|
|
tim[strcspn(tim, "\n")] = '\0';
|
2017-10-12 11:32:27 +00:00
|
|
|
|
|
|
|
if (WIFEXITED(wp->status)) {
|
|
|
|
screen_write_nputs(&ctx, -1, &gc,
|
|
|
|
"Pane is dead (status %d, %s)",
|
|
|
|
WEXITSTATUS(wp->status),
|
|
|
|
tim);
|
|
|
|
} else if (WIFSIGNALED(wp->status)) {
|
|
|
|
screen_write_nputs(&ctx, -1, &gc,
|
2020-04-16 07:28:36 +00:00
|
|
|
"Pane is dead (signal %s, %s)",
|
|
|
|
sig2name(WTERMSIG(wp->status)),
|
2017-10-12 11:32:27 +00:00
|
|
|
tim);
|
|
|
|
}
|
|
|
|
|
2011-09-05 23:40:51 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
wp->flags |= PANE_REDRAW;
|
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);
|
2020-05-16 16:20:59 +00:00
|
|
|
server_client_remove_pane(wp);
|
2009-11-13 17:33:07 +00:00
|
|
|
layout_close_pane(wp);
|
|
|
|
window_remove_pane(w, wp);
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&w->panes))
|
2020-07-04 14:24:02 +00:00
|
|
|
server_kill_window(w, 1);
|
2009-11-13 17:33:07 +00:00
|
|
|
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);
|
2019-04-17 14:37:48 +00:00
|
|
|
session_destroy(s, 1, __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)
|
|
|
|
{
|
2021-02-01 08:01:14 +00:00
|
|
|
struct session *s_loop, *s_out = NULL;
|
2010-06-27 00:22:22 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-02-01 08:01:14 +00:00
|
|
|
static struct session *
|
|
|
|
server_next_detached_session(struct session *s)
|
|
|
|
{
|
|
|
|
struct session *s_loop, *s_out = NULL;
|
|
|
|
|
|
|
|
RB_FOREACH(s_loop, sessions, &sessions) {
|
|
|
|
if (s_loop == s || s_loop->attached)
|
|
|
|
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;
|
2021-02-01 08:01:14 +00:00
|
|
|
int detach_on_destroy;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2021-02-01 08:01:14 +00:00
|
|
|
detach_on_destroy = options_get_number(s->options, "detach-on-destroy");
|
|
|
|
if (detach_on_destroy == 0)
|
2010-06-27 00:22:22 +00:00
|
|
|
s_new = server_next_session(s);
|
2021-02-01 08:01:14 +00:00
|
|
|
else if (detach_on_destroy == 2)
|
|
|
|
s_new = server_next_detached_session(s);
|
2010-06-27 00:22:22 +00:00
|
|
|
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;
|
2021-08-13 06:52:51 +00:00
|
|
|
server_client_set_session(c, NULL);
|
|
|
|
if (s_new == NULL)
|
2010-07-24 20:11:59 +00:00
|
|
|
c->flags |= CLIENT_EXIT;
|
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) {
|
2018-08-18 20:08:52 +00:00
|
|
|
if (s->attached != 0)
|
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"))
|
2019-04-17 14:37:48 +00:00
|
|
|
session_destroy(s, 1, __func__);
|
2010-09-26 20:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-24 09:57:59 +00:00
|
|
|
void
|
|
|
|
server_unzoom_window(struct window *w)
|
|
|
|
{
|
2018-02-28 08:55:44 +00:00
|
|
|
if (window_unzoom(w) == 0)
|
2015-04-19 21:34:21 +00:00
|
|
|
server_redraw_window(w);
|
2013-03-24 09:57:59 +00:00
|
|
|
}
|