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

Annotation of src/usr.bin/tmux/cmd-respawn-pane.c, Revision 1.36

1.36    ! nicm        1: /* $OpenBSD: cmd-respawn-pane.c,v 1.35 2021/08/20 19:50:16 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.20      nicm        4:  * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        5:  * Copyright (c) 2011 Marcel P. Partap <mpartap@gmx.net>
                      6:  *
                      7:  * Permission to use, copy, modify, and distribute this software for any
                      8:  * purpose with or without fee is hereby granted, provided that the above
                      9:  * copyright notice and this permission notice appear in all copies.
                     10:  *
                     11:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     12:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     13:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     14:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     15:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     16:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     17:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     18:  */
                     19:
                     20: #include <sys/types.h>
                     21:
1.6       nicm       22: #include <stdlib.h>
1.28      nicm       23: #include <string.h>
1.1       nicm       24:
                     25: #include "tmux.h"
                     26:
                     27: /*
                     28:  * Respawn a pane (restart the command). Kill existing if -k given.
                     29:  */
                     30:
1.22      nicm       31: static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmdq_item *);
1.1       nicm       32:
                     33: const struct cmd_entry cmd_respawn_pane_entry = {
1.18      nicm       34:        .name = "respawn-pane",
                     35:        .alias = "respawnp",
                     36:
1.36    ! nicm       37:        .args = { "c:e:kt:", 0, -1, NULL },
1.29      nicm       38:        .usage = "[-k] [-c start-directory] [-e environment] "
                     39:                 CMD_TARGET_PANE_USAGE " [command]",
1.18      nicm       40:
1.24      nicm       41:        .target = { 't', CMD_FIND_PANE, 0 },
1.19      nicm       42:
                     43:        .flags = 0,
1.18      nicm       44:        .exec = cmd_respawn_pane_exec
1.1       nicm       45: };
                     46:
1.21      nicm       47: static enum cmd_retval
1.22      nicm       48: cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       49: {
1.31      nicm       50:        struct args             *args = cmd_get_args(self);
1.32      nicm       51:        struct cmd_find_state   *target = cmdq_get_target(item);
1.35      nicm       52:        struct spawn_context     sc = { 0 };
1.32      nicm       53:        struct session          *s = target->s;
                     54:        struct winlink          *wl = target->wl;
                     55:        struct window_pane      *wp = target->wp;
1.28      nicm       56:        char                    *cause = NULL;
1.34      nicm       57:        struct args_value       *av;
1.28      nicm       58:
                     59:        sc.item = item;
                     60:        sc.s = s;
                     61:        sc.wl = wl;
                     62:
                     63:        sc.wp0 = wp;
                     64:        sc.lc = NULL;
                     65:
                     66:        sc.name = NULL;
1.35      nicm       67:        args_vector(args, &sc.argc, &sc.argv);
1.29      nicm       68:        sc.environ = environ_create();
                     69:
1.34      nicm       70:        av = args_first_value(args, 'e');
                     71:        while (av != NULL) {
                     72:                environ_put(sc.environ, av->value, 0);
                     73:                av = args_next_value(av);
1.29      nicm       74:        }
1.28      nicm       75:
                     76:        sc.idx = -1;
                     77:        sc.cwd = args_get(args, 'c');
                     78:
                     79:        sc.flags = SPAWN_RESPAWN;
                     80:        if (args_has(args, 'k'))
                     81:                sc.flags |= SPAWN_KILL;
1.1       nicm       82:
1.28      nicm       83:        if (spawn_pane(&sc, &cause) == NULL) {
1.22      nicm       84:                cmdq_error(item, "respawn pane failed: %s", cause);
1.6       nicm       85:                free(cause);
1.35      nicm       86:                if (sc.argv != NULL)
                     87:                        cmd_free_argv(sc.argc, sc.argv);
1.34      nicm       88:                environ_free(sc.environ);
1.7       nicm       89:                return (CMD_RETURN_ERROR);
1.1       nicm       90:        }
1.23      nicm       91:
1.1       nicm       92:        wp->flags |= PANE_REDRAW;
1.33      nicm       93:        server_redraw_window_borders(wp->window);
1.28      nicm       94:        server_status_window(wp->window);
1.1       nicm       95:
1.35      nicm       96:        if (sc.argv != NULL)
                     97:                cmd_free_argv(sc.argc, sc.argv);
1.29      nicm       98:        environ_free(sc.environ);
1.7       nicm       99:        return (CMD_RETURN_NORMAL);
1.1       nicm      100: }