cmd-detach-client.c revision 1.25
1/* $OpenBSD: cmd-detach-client.c,v 1.25 2015/12/13 21:53:57 nicm Exp $ */ 2 3/* 4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> 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 21#include <string.h> 22 23#include "tmux.h" 24 25/* 26 * Detach a client. 27 */ 28 29enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *); 30 31const struct cmd_entry cmd_detach_client_entry = { 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 38 .flags = CMD_READONLY|CMD_CLIENT_T|CMD_SESSION_S, 39 .exec = cmd_detach_client_exec 40}; 41 42const struct cmd_entry cmd_suspend_client_entry = { 43 .name = "suspend-client", 44 .alias = "suspendc", 45 46 .args = { "t:", 0, 0 }, 47 .usage = CMD_TARGET_CLIENT_USAGE, 48 49 .flags = CMD_CLIENT_T, 50 .exec = cmd_detach_client_exec 51}; 52 53enum cmd_retval 54cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) 55{ 56 struct args *args = self->args; 57 struct client *c = cmdq->state.c, *cloop; 58 struct session *s; 59 enum msgtype msgtype; 60 61 if (self->entry == &cmd_suspend_client_entry) { 62 tty_stop_tty(&c->tty); 63 c->flags |= CLIENT_SUSPENDED; 64 proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0); 65 return (CMD_RETURN_NORMAL); 66 } 67 68 if (args_has(args, 'P')) 69 msgtype = MSG_DETACHKILL; 70 else 71 msgtype = MSG_DETACH; 72 73 if (args_has(args, 's')) { 74 s = cmdq->state.sflag.s; 75 TAILQ_FOREACH(cloop, &clients, entry) { 76 if (cloop->session == s) 77 server_client_detach(cloop, msgtype); 78 } 79 return (CMD_RETURN_STOP); 80 } 81 82 if (args_has(args, 'a')) { 83 TAILQ_FOREACH(cloop, &clients, entry) { 84 if (cloop->session != NULL && cloop != c) 85 server_client_detach(cloop, msgtype); 86 } 87 return (CMD_RETURN_NORMAL); 88 } 89 90 server_client_detach(c, msgtype); 91 return (CMD_RETURN_STOP); 92} 93