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

1.4     ! nicm        1: /* $Id: cmd-respawn-pane.c,v 1.3 2011/07/09 01:37:00 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
                      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:
                     22: #include <unistd.h>
                     23:
                     24: #include "tmux.h"
                     25:
                     26: /*
                     27:  * Respawn a pane (restart the command). Kill existing if -k given.
                     28:  */
                     29:
                     30: int    cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
                     31:
                     32: const struct cmd_entry cmd_respawn_pane_entry = {
                     33:        "respawn-pane", "respawnp",
                     34:        "kt:", 0, 1,
                     35:        "[-k] " CMD_TARGET_PANE_USAGE " [command]",
                     36:        0,
                     37:        NULL,
                     38:        NULL,
                     39:        cmd_respawn_pane_exec
                     40: };
                     41:
                     42: int
                     43: cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
                     44: {
                     45:        struct args             *args = self->args;
                     46:        struct winlink          *wl;
                     47:        struct window           *w;
                     48:        struct window_pane      *wp;
                     49:        struct session          *s;
                     50:        struct environ           env;
                     51:        const char              *cmd;
1.4     ! nicm       52:        char                    *cause;
        !            53:        u_int                    idx;
1.1       nicm       54:
                     55:        if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
                     56:                return (-1);
                     57:        w = wl->window;
                     58:
                     59:        if (!args_has(self->args, 'k') && wp->fd != -1) {
1.4     ! nicm       60:                if (window_pane_index(wp, &idx) != 0)
        !            61:                        fatalx("index not found");
1.1       nicm       62:                ctx->error(ctx, "pane still active: %s:%u.%u",
1.4     ! nicm       63:                    s->name, wl->idx, idx);
1.1       nicm       64:                return (-1);
                     65:        }
                     66:
                     67:        environ_init(&env);
                     68:        environ_copy(&global_environ, &env);
                     69:        environ_copy(&s->environ, &env);
                     70:        server_fill_environ(s, &env);
                     71:
                     72:        window_pane_reset_mode(wp);
1.2       nicm       73:        screen_reinit(&wp->base);
1.1       nicm       74:        input_init(wp);
                     75:
                     76:        if (args->argc != 0)
                     77:                cmd = args->argv[0];
                     78:        else
                     79:                cmd = NULL;
                     80:        if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
                     81:                ctx->error(ctx, "respawn pane failed: %s", cause);
                     82:                xfree(cause);
                     83:                environ_free(&env);
                     84:                return (-1);
                     85:        }
                     86:        wp->flags |= PANE_REDRAW;
                     87:        server_status_window(w);
                     88:
                     89:        environ_free(&env);
                     90:        return (0);
                     91: }