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

Annotation of src/usr.bin/tmux/cmd-respawn-window.c, Revision 1.39

1.39    ! nicm        1: /* $OpenBSD: cmd-respawn-window.c,v 1.38 2019/04/17 14:37:48 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.30      nicm        4:  * Copyright (c) 2008 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 <stdlib.h>
1.38      nicm       22: #include <string.h>
1.1       nicm       23:
                     24: #include "tmux.h"
                     25:
                     26: /*
                     27:  * Respawn a window (restart the command). Kill existing if -k given.
                     28:  */
                     29:
1.32      nicm       30: static enum cmd_retval cmd_respawn_window_exec(struct cmd *,
                     31:                            struct cmdq_item *);
1.1       nicm       32:
                     33: const struct cmd_entry cmd_respawn_window_entry = {
1.27      nicm       34:        .name = "respawn-window",
                     35:        .alias = "respawnw",
                     36:
1.39    ! nicm       37:        .args = { "c:e:kt:", 0, -1 },
        !            38:        .usage = "[-k] [-c start-directory] [-e environment] "
        !            39:                 CMD_TARGET_WINDOW_USAGE " [command]",
1.27      nicm       40:
1.34      nicm       41:        .target = { 't', CMD_FIND_WINDOW, 0 },
1.28      nicm       42:
                     43:        .flags = 0,
1.27      nicm       44:        .exec = cmd_respawn_window_exec
1.1       nicm       45: };
                     46:
1.31      nicm       47: static enum cmd_retval
1.32      nicm       48: cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       49: {
1.13      nicm       50:        struct args             *args = self->args;
1.38      nicm       51:        struct spawn_context     sc;
1.34      nicm       52:        struct session          *s = item->target.s;
                     53:        struct winlink          *wl = item->target.wl;
1.38      nicm       54:        char                    *cause = NULL;
1.39    ! nicm       55:        const char              *add;
        !            56:        struct args_value       *value;
1.38      nicm       57:
                     58:        memset(&sc, 0, sizeof sc);
                     59:        sc.item = item;
                     60:        sc.s = s;
                     61:        sc.wl = wl;
                     62:
                     63:        sc.name = NULL;
                     64:        sc.argc = args->argc;
                     65:        sc.argv = args->argv;
1.39    ! nicm       66:        sc.environ = environ_create();
        !            67:
        !            68:        add = args_first_value(args, 'e', &value);
        !            69:        while (add != NULL) {
        !            70:                environ_put(sc.environ, add);
        !            71:                add = args_next_value(&value);
        !            72:        }
1.38      nicm       73:
                     74:        sc.idx = -1;
                     75:        sc.cwd = args_get(args, 'c');
                     76:
                     77:        sc.flags = SPAWN_RESPAWN;
                     78:        if (args_has(args, 'k'))
                     79:                sc.flags |= SPAWN_KILL;
1.1       nicm       80:
1.38      nicm       81:        if (spawn_window(&sc, &cause) == NULL) {
1.32      nicm       82:                cmdq_error(item, "respawn window failed: %s", cause);
1.15      nicm       83:                free(cause);
1.16      nicm       84:                return (CMD_RETURN_ERROR);
1.1       nicm       85:        }
                     86:
1.38      nicm       87:        server_redraw_window(wl->window);
1.1       nicm       88:
1.39    ! nicm       89:        environ_free(sc.environ);
1.16      nicm       90:        return (CMD_RETURN_NORMAL);
1.1       nicm       91: }