[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.30

1.30    ! nicm        1: /* $OpenBSD: cmd-detach-client.c,v 1.29 2016/10/16 19:04:05 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.29      nicm       29: static enum cmd_retval cmd_detach_client_exec(struct cmd *,
                     30:                            struct cmdq_item *);
1.1       nicm       31:
                     32: const struct cmd_entry cmd_detach_client_entry = {
1.25      nicm       33:        .name = "detach-client",
                     34:        .alias = "detach",
                     35:
1.30    ! nicm       36:        .args = { "aE:s:t:P", 0, 0 },
        !            37:        .usage = "[-aP] [-E shell-command] "
        !            38:                 "[-s target-session] " CMD_TARGET_CLIENT_USAGE,
1.25      nicm       39:
1.26      nicm       40:        .sflag = CMD_SESSION,
                     41:        .tflag = CMD_CLIENT,
                     42:
                     43:        .flags = CMD_READONLY,
1.25      nicm       44:        .exec = cmd_detach_client_exec
1.1       nicm       45: };
                     46:
1.18      nicm       47: const struct cmd_entry cmd_suspend_client_entry = {
1.25      nicm       48:        .name = "suspend-client",
                     49:        .alias = "suspendc",
                     50:
                     51:        .args = { "t:", 0, 0 },
                     52:        .usage = CMD_TARGET_CLIENT_USAGE,
                     53:
1.26      nicm       54:        .tflag = CMD_CLIENT,
                     55:
                     56:        .flags = 0,
1.25      nicm       57:        .exec = cmd_detach_client_exec
1.18      nicm       58: };
                     59:
1.28      nicm       60: static enum cmd_retval
1.29      nicm       61: cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       62: {
1.6       nicm       63:        struct args     *args = self->args;
1.29      nicm       64:        struct client   *c = item->state.c, *cloop;
1.15      nicm       65:        struct session  *s;
                     66:        enum msgtype     msgtype;
1.30    ! nicm       67:        const char      *cmd = args_get(args, 'E');
1.18      nicm       68:
                     69:        if (self->entry == &cmd_suspend_client_entry) {
                     70:                tty_stop_tty(&c->tty);
                     71:                c->flags |= CLIENT_SUSPENDED;
1.21      nicm       72:                proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
1.18      nicm       73:                return (CMD_RETURN_NORMAL);
                     74:        }
1.1       nicm       75:
1.7       nicm       76:        if (args_has(args, 'P'))
1.8       nicm       77:                msgtype = MSG_DETACHKILL;
1.7       nicm       78:        else
1.8       nicm       79:                msgtype = MSG_DETACH;
                     80:
                     81:        if (args_has(args, 's')) {
1.29      nicm       82:                s = item->state.sflag.s;
1.20      nicm       83:                TAILQ_FOREACH(cloop, &clients, entry) {
1.30    ! nicm       84:                        if (cloop->session == s) {
        !            85:                                if (cmd != NULL)
        !            86:                                        server_client_exec(cloop, cmd);
        !            87:                                else
        !            88:                                        server_client_detach(cloop, msgtype);
        !            89:                        }
1.8       nicm       90:                }
1.19      nicm       91:                return (CMD_RETURN_STOP);
                     92:        }
1.8       nicm       93:
1.19      nicm       94:        if (args_has(args, 'a')) {
1.20      nicm       95:                TAILQ_FOREACH(cloop, &clients, entry) {
1.30    ! nicm       96:                        if (cloop->session != NULL && cloop != c) {
        !            97:                                if (cmd != NULL)
        !            98:                                        server_client_exec(cloop, cmd);
        !            99:                                else
        !           100:                                        server_client_detach(cloop, msgtype);
        !           101:                        }
1.15      nicm      102:                }
1.19      nicm      103:                return (CMD_RETURN_NORMAL);
1.8       nicm      104:        }
1.1       nicm      105:
1.30    ! nicm      106:        if (cmd != NULL)
        !           107:                server_client_exec(c, cmd);
        !           108:        else
        !           109:                server_client_detach(c, msgtype);
1.13      nicm      110:        return (CMD_RETURN_STOP);
1.1       nicm      111: }