Annotation of src/usr.bin/tmux/cmd-detach-client.c, Revision 1.28
1.28 ! nicm 1: /* $OpenBSD: cmd-detach-client.c,v 1.27 2016/01/19 15:59:12 nicm Exp $ */
1.1 nicm 2:
3: /*
1.27 nicm 4: * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 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:
1.15 nicm 21: #include <string.h>
22:
1.1 nicm 23: #include "tmux.h"
24:
25: /*
26: * Detach a client.
27: */
28:
1.28 ! nicm 29: static enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *);
1.1 nicm 30:
31: const struct cmd_entry cmd_detach_client_entry = {
1.25 nicm 32: .name = "detach-client",
33: .alias = "detach",
34:
35: .args = { "as:t:P", 0, 0 },
36: .usage = "[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
37:
1.26 nicm 38: .sflag = CMD_SESSION,
39: .tflag = CMD_CLIENT,
40:
41: .flags = CMD_READONLY,
1.25 nicm 42: .exec = cmd_detach_client_exec
1.1 nicm 43: };
44:
1.18 nicm 45: const struct cmd_entry cmd_suspend_client_entry = {
1.25 nicm 46: .name = "suspend-client",
47: .alias = "suspendc",
48:
49: .args = { "t:", 0, 0 },
50: .usage = CMD_TARGET_CLIENT_USAGE,
51:
1.26 nicm 52: .tflag = CMD_CLIENT,
53:
54: .flags = 0,
1.25 nicm 55: .exec = cmd_detach_client_exec
1.18 nicm 56: };
57:
1.28 ! nicm 58: static enum cmd_retval
1.13 nicm 59: cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 60: {
1.6 nicm 61: struct args *args = self->args;
1.24 nicm 62: struct client *c = cmdq->state.c, *cloop;
1.15 nicm 63: struct session *s;
64: enum msgtype msgtype;
1.18 nicm 65:
66: if (self->entry == &cmd_suspend_client_entry) {
67: tty_stop_tty(&c->tty);
68: c->flags |= CLIENT_SUSPENDED;
1.21 nicm 69: proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
1.18 nicm 70: return (CMD_RETURN_NORMAL);
71: }
1.1 nicm 72:
1.7 nicm 73: if (args_has(args, 'P'))
1.8 nicm 74: msgtype = MSG_DETACHKILL;
1.7 nicm 75: else
1.8 nicm 76: msgtype = MSG_DETACH;
77:
78: if (args_has(args, 's')) {
1.24 nicm 79: s = cmdq->state.sflag.s;
1.20 nicm 80: TAILQ_FOREACH(cloop, &clients, entry) {
1.23 nicm 81: if (cloop->session == s)
82: server_client_detach(cloop, msgtype);
1.8 nicm 83: }
1.19 nicm 84: return (CMD_RETURN_STOP);
85: }
1.8 nicm 86:
1.19 nicm 87: if (args_has(args, 'a')) {
1.20 nicm 88: TAILQ_FOREACH(cloop, &clients, entry) {
1.23 nicm 89: if (cloop->session != NULL && cloop != c)
90: server_client_detach(cloop, msgtype);
1.15 nicm 91: }
1.19 nicm 92: return (CMD_RETURN_NORMAL);
1.8 nicm 93: }
1.1 nicm 94:
1.23 nicm 95: server_client_detach(c, msgtype);
1.13 nicm 96: return (CMD_RETURN_STOP);
1.1 nicm 97: }