1*a51dead1Snicm /* $OpenBSD: cmd-kill-session.c,v 1.28 2021/08/21 10:22:39 nicm Exp $ */
2311827fbSnicm
3311827fbSnicm /*
498ca8272Snicm * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5311827fbSnicm *
6311827fbSnicm * Permission to use, copy, modify, and distribute this software for any
7311827fbSnicm * purpose with or without fee is hereby granted, provided that the above
8311827fbSnicm * copyright notice and this permission notice appear in all copies.
9311827fbSnicm *
10311827fbSnicm * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11311827fbSnicm * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12311827fbSnicm * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13311827fbSnicm * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14311827fbSnicm * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15311827fbSnicm * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16311827fbSnicm * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17311827fbSnicm */
18311827fbSnicm
19311827fbSnicm #include <sys/types.h>
20311827fbSnicm
21311827fbSnicm #include "tmux.h"
22311827fbSnicm
23311827fbSnicm /*
24311827fbSnicm * Destroy session, detaching all clients attached to it and destroying any
25311827fbSnicm * windows linked only to this session.
26311827fbSnicm *
27311827fbSnicm * Note this deliberately has no alias to make it hard to hit by accident.
28311827fbSnicm */
29311827fbSnicm
3068e0a7f2Snicm static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmdq_item *);
31311827fbSnicm
32311827fbSnicm const struct cmd_entry cmd_kill_session_entry = {
33c057646bSnicm .name = "kill-session",
34c057646bSnicm .alias = NULL,
35c057646bSnicm
36*a51dead1Snicm .args = { "aCt:", 0, 0, NULL },
37c057646bSnicm .usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
38c057646bSnicm
39bf0d297eSnicm .target = { 't', CMD_FIND_SESSION, 0 },
408d471e80Snicm
418d471e80Snicm .flags = 0,
42c057646bSnicm .exec = cmd_kill_session_exec
43311827fbSnicm };
44311827fbSnicm
45dc1f0f5fSnicm static enum cmd_retval
cmd_kill_session_exec(struct cmd * self,struct cmdq_item * item)4668e0a7f2Snicm cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
47311827fbSnicm {
4890d7ba38Snicm struct args *args = cmd_get_args(self);
49040343aeSnicm struct cmd_find_state *target = cmdq_get_target(item);
50040343aeSnicm struct session *s = target->s, *sloop, *stmp;
51bd389ecbSnicm struct winlink *wl;
52311827fbSnicm
53bd389ecbSnicm if (args_has(args, 'C')) {
54bd389ecbSnicm RB_FOREACH(wl, winlinks, &s->windows) {
55bd389ecbSnicm wl->window->flags &= ~WINDOW_ALERTFLAGS;
56bd389ecbSnicm wl->flags &= ~WINLINK_ALERTFLAGS;
57bd389ecbSnicm }
58bd389ecbSnicm server_redraw_session(s);
59bd389ecbSnicm } else if (args_has(args, 'a')) {
60e2cd61c2Snicm RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
61e2cd61c2Snicm if (sloop != s) {
62e2cd61c2Snicm server_destroy_session(sloop);
63c26c4f79Snicm session_destroy(sloop, 1, __func__);
64d3a6ec70Snicm }
65d3a6ec70Snicm }
66d3a6ec70Snicm } else {
67f61b6cb0Snicm server_destroy_session(s);
68c26c4f79Snicm session_destroy(s, 1, __func__);
69d3a6ec70Snicm }
70a224d0d3Snicm return (CMD_RETURN_NORMAL);
71311827fbSnicm }
72