[BACK]Return to cmd-detach-client.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-detach-client.c, Revision 1.25

1.25    ! nicm        1: /* $OpenBSD: cmd-detach-client.c,v 1.24 2015/12/13 14:32:38 nicm Exp $ */
1.1       nicm        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:
1.15      nicm       21: #include <string.h>
                     22:
1.1       nicm       23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Detach a client.
                     27:  */
                     28:
1.13      nicm       29: 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:
        !            38:        .flags = CMD_READONLY|CMD_CLIENT_T|CMD_SESSION_S,
        !            39:        .exec = cmd_detach_client_exec
1.1       nicm       40: };
                     41:
1.18      nicm       42: const struct cmd_entry cmd_suspend_client_entry = {
1.25    ! nicm       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
1.18      nicm       51: };
                     52:
1.11      nicm       53: enum cmd_retval
1.13      nicm       54: cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
1.1       nicm       55: {
1.6       nicm       56:        struct args     *args = self->args;
1.24      nicm       57:        struct client   *c = cmdq->state.c, *cloop;
1.15      nicm       58:        struct session  *s;
                     59:        enum msgtype     msgtype;
1.18      nicm       60:
                     61:        if (self->entry == &cmd_suspend_client_entry) {
                     62:                tty_stop_tty(&c->tty);
                     63:                c->flags |= CLIENT_SUSPENDED;
1.21      nicm       64:                proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
1.18      nicm       65:                return (CMD_RETURN_NORMAL);
                     66:        }
1.1       nicm       67:
1.7       nicm       68:        if (args_has(args, 'P'))
1.8       nicm       69:                msgtype = MSG_DETACHKILL;
1.7       nicm       70:        else
1.8       nicm       71:                msgtype = MSG_DETACH;
                     72:
                     73:        if (args_has(args, 's')) {
1.24      nicm       74:                s = cmdq->state.sflag.s;
1.20      nicm       75:                TAILQ_FOREACH(cloop, &clients, entry) {
1.23      nicm       76:                        if (cloop->session == s)
                     77:                                server_client_detach(cloop, msgtype);
1.8       nicm       78:                }
1.19      nicm       79:                return (CMD_RETURN_STOP);
                     80:        }
1.8       nicm       81:
1.19      nicm       82:        if (args_has(args, 'a')) {
1.20      nicm       83:                TAILQ_FOREACH(cloop, &clients, entry) {
1.23      nicm       84:                        if (cloop->session != NULL && cloop != c)
                     85:                                server_client_detach(cloop, msgtype);
1.15      nicm       86:                }
1.19      nicm       87:                return (CMD_RETURN_NORMAL);
1.8       nicm       88:        }
1.1       nicm       89:
1.23      nicm       90:        server_client_detach(c, msgtype);
1.13      nicm       91:        return (CMD_RETURN_STOP);
1.1       nicm       92: }