15494e770Schristos /* $OpenBSD$ */
2698d5317Sjmmv
3698d5317Sjmmv /*
4ed4e6cd4Schristos * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5698d5317Sjmmv *
6698d5317Sjmmv * Permission to use, copy, modify, and distribute this software for any
7698d5317Sjmmv * purpose with or without fee is hereby granted, provided that the above
8698d5317Sjmmv * copyright notice and this permission notice appear in all copies.
9698d5317Sjmmv *
10698d5317Sjmmv * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11698d5317Sjmmv * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12698d5317Sjmmv * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13698d5317Sjmmv * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14698d5317Sjmmv * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15698d5317Sjmmv * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16698d5317Sjmmv * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17698d5317Sjmmv */
18698d5317Sjmmv
19698d5317Sjmmv #include <sys/types.h>
20698d5317Sjmmv
21698d5317Sjmmv #include "tmux.h"
22698d5317Sjmmv
23698d5317Sjmmv /*
24698d5317Sjmmv * Destroy session, detaching all clients attached to it and destroying any
25698d5317Sjmmv * windows linked only to this session.
26698d5317Sjmmv *
27698d5317Sjmmv * Note this deliberately has no alias to make it hard to hit by accident.
28698d5317Sjmmv */
29698d5317Sjmmv
304e179ddaSchristos static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmdq_item *);
31698d5317Sjmmv
32698d5317Sjmmv const struct cmd_entry cmd_kill_session_entry = {
33ed4e6cd4Schristos .name = "kill-session",
34ed4e6cd4Schristos .alias = NULL,
35ed4e6cd4Schristos
36*6db26757Swiz .args = { "aCt:", 0, 0, NULL },
37ed4e6cd4Schristos .usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
38ed4e6cd4Schristos
39c9ad075bSchristos .target = { 't', CMD_FIND_SESSION, 0 },
40ed4e6cd4Schristos
41ed4e6cd4Schristos .flags = 0,
42ed4e6cd4Schristos .exec = cmd_kill_session_exec
43698d5317Sjmmv };
44698d5317Sjmmv
454e179ddaSchristos static enum cmd_retval
cmd_kill_session_exec(struct cmd * self,struct cmdq_item * item)464e179ddaSchristos cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
47698d5317Sjmmv {
489fb66d81Schristos struct args *args = cmd_get_args(self);
499fb66d81Schristos struct cmd_find_state *target = cmdq_get_target(item);
509fb66d81Schristos struct session *s = target->s, *sloop, *stmp;
51ed4e6cd4Schristos struct winlink *wl;
52698d5317Sjmmv
53ed4e6cd4Schristos if (args_has(args, 'C')) {
54ed4e6cd4Schristos RB_FOREACH(wl, winlinks, &s->windows) {
55ed4e6cd4Schristos wl->window->flags &= ~WINDOW_ALERTFLAGS;
56ed4e6cd4Schristos wl->flags &= ~WINLINK_ALERTFLAGS;
57ed4e6cd4Schristos }
58ed4e6cd4Schristos server_redraw_session(s);
59ed4e6cd4Schristos } else if (args_has(args, 'a')) {
605494e770Schristos RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
615494e770Schristos if (sloop != s) {
625494e770Schristos server_destroy_session(sloop);
636483eba0Schristos session_destroy(sloop, 1, __func__);
64928fc495Schristos }
65928fc495Schristos }
66928fc495Schristos } else {
67698d5317Sjmmv server_destroy_session(s);
686483eba0Schristos session_destroy(s, 1, __func__);
69928fc495Schristos }
70928fc495Schristos return (CMD_RETURN_NORMAL);
71698d5317Sjmmv }
72