File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / tmux / cmd-respawn-pane.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 14 12:22:44 2017 UTC (7 years, 9 months ago) by misho
Branches: tmux, MAIN
CVS tags: v2_4p0, v2_4, HEAD
tmux 2.4

    1: /* $OpenBSD$ */
    2: 
    3: /*
    4:  * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
    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 <stdlib.h>
   23: #include <unistd.h>
   24: 
   25: #include "tmux.h"
   26: 
   27: /*
   28:  * Respawn a pane (restart the command). Kill existing if -k given.
   29:  */
   30: 
   31: static enum cmd_retval	cmd_respawn_pane_exec(struct cmd *, struct cmdq_item *);
   32: 
   33: const struct cmd_entry cmd_respawn_pane_entry = {
   34: 	.name = "respawn-pane",
   35: 	.alias = "respawnp",
   36: 
   37: 	.args = { "kt:", 0, -1 },
   38: 	.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
   39: 
   40: 	.tflag = CMD_PANE,
   41: 
   42: 	.flags = 0,
   43: 	.exec = cmd_respawn_pane_exec
   44: };
   45: 
   46: static enum cmd_retval
   47: cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
   48: {
   49: 	struct args		*args = self->args;
   50: 	struct winlink		*wl = item->state.tflag.wl;
   51: 	struct window		*w = wl->window;
   52: 	struct window_pane	*wp = item->state.tflag.wp;
   53: 	struct session		*s = item->state.tflag.s;
   54: 	struct environ		*env;
   55: 	const char		*path;
   56: 	char			*cause;
   57: 	u_int			 idx;
   58: 	struct environ_entry	*envent;
   59: 
   60: 	if (!args_has(self->args, 'k') && wp->fd != -1) {
   61: 		if (window_pane_index(wp, &idx) != 0)
   62: 			fatalx("index not found");
   63: 		cmdq_error(item, "pane still active: %s:%d.%u",
   64: 		    s->name, wl->idx, idx);
   65: 		return (CMD_RETURN_ERROR);
   66: 	}
   67: 
   68: 	window_pane_reset_mode(wp);
   69: 	screen_reinit(&wp->base);
   70: 	input_init(wp);
   71: 
   72: 	path = NULL;
   73: 	if (item->client != NULL && item->client->session == NULL)
   74: 		envent = environ_find(item->client->environ, "PATH");
   75: 	else
   76: 		envent = environ_find(s->environ, "PATH");
   77: 	if (envent != NULL)
   78: 		path = envent->value;
   79: 
   80: 	env = environ_for_session(s);
   81: 	if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
   82: 	    s->tio, &cause) != 0) {
   83: 		cmdq_error(item, "respawn pane failed: %s", cause);
   84: 		free(cause);
   85: 		environ_free(env);
   86: 		return (CMD_RETURN_ERROR);
   87: 	}
   88: 	environ_free(env);
   89: 
   90: 	wp->flags |= PANE_REDRAW;
   91: 	server_status_window(w);
   92: 
   93: 	return (CMD_RETURN_NORMAL);
   94: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>