aboutsummaryrefslogtreecommitdiff
path: root/cmd-detach-client.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2011-04-11 06:44:56 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2011-04-11 06:44:56 +0000
commit457147d59d3e807309b7fdb2583d29278ae6acaa (patch)
tree8ccf3885dbee144bae3093ead7ec875f0a5767df /cmd-detach-client.c
parent75f218dc73a19ac6de9d2270aab43f83c5bb8816 (diff)
downloadrtmux-457147d59d3e807309b7fdb2583d29278ae6acaa.tar.gz
rtmux-457147d59d3e807309b7fdb2583d29278ae6acaa.tar.bz2
rtmux-457147d59d3e807309b7fdb2583d29278ae6acaa.zip
Add -s option to detach all clients attached to a session, from Zac
Sprackett.
Diffstat (limited to 'cmd-detach-client.c')
-rw-r--r--cmd-detach-client.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index 6052a790..66ed67bb 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-detach-client.c,v 1.13 2011-03-19 23:27:35 tcunha Exp $ */
+/* $Id: cmd-detach-client.c,v 1.14 2011-04-11 06:44:56 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,7 +28,7 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
- "t:P", 0, 0,
+ "s:t:P", 0, 0,
"[-P] " CMD_TARGET_CLIENT_USAGE,
CMD_READONLY,
NULL,
@@ -41,14 +41,32 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct client *c;
-
- if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
- return (-1);
+ struct session *s;
+ enum msgtype msgtype;
+ u_int i;
if (args_has(args, 'P'))
- server_write_client(c, MSG_DETACHKILL, NULL, 0);
+ msgtype = MSG_DETACHKILL;
else
- server_write_client(c, MSG_DETACH, NULL, 0);
+ msgtype = MSG_DETACH;
+
+ if (args_has(args, 's')) {
+ s = cmd_find_session(ctx, args_get(args, 's'), 0);
+ if (s == NULL)
+ return (-1);
+
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL && c->session == s)
+ server_write_client(c, msgtype, NULL, 0);
+ }
+ } else {
+ c = cmd_find_client(ctx, args_get(args, 't'));
+ if (c == NULL)
+ return (-1);
+
+ server_write_client(c, msgtype, NULL, 0);
+ }
return (0);
}