Annotation of src/usr.bin/tmux/cmd-respawn-pane.c, Revision 1.23
1.23 ! nicm 1: /* $OpenBSD: cmd-respawn-pane.c,v 1.22 2016/10/16 19:04:05 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.1 nicm 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:
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:
37: .args = { "kt:", 0, -1 },
38: .usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
39:
1.19 nicm 40: .tflag = CMD_PANE,
41:
42: .flags = 0,
1.18 nicm 43: .exec = cmd_respawn_pane_exec
1.1 nicm 44: };
45:
1.21 nicm 46: static enum cmd_retval
1.22 nicm 47: cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 48: {
49: struct args *args = self->args;
1.22 nicm 50: struct winlink *wl = item->state.tflag.wl;
1.17 nicm 51: struct window *w = wl->window;
1.22 nicm 52: struct window_pane *wp = item->state.tflag.wp;
53: struct session *s = item->state.tflag.s;
1.15 nicm 54: struct environ *env;
1.12 nicm 55: const char *path;
1.4 nicm 56: char *cause;
57: u_int idx;
1.11 nicm 58: struct environ_entry *envent;
1.1 nicm 59:
60: if (!args_has(self->args, 'k') && wp->fd != -1) {
1.4 nicm 61: if (window_pane_index(wp, &idx) != 0)
62: fatalx("index not found");
1.22 nicm 63: cmdq_error(item, "pane still active: %s:%d.%u",
1.4 nicm 64: s->name, wl->idx, idx);
1.7 nicm 65: return (CMD_RETURN_ERROR);
1.1 nicm 66: }
67:
68: window_pane_reset_mode(wp);
1.2 nicm 69: screen_reinit(&wp->base);
1.1 nicm 70: input_init(wp);
71:
1.11 nicm 72: path = NULL;
1.22 nicm 73: if (item->client != NULL && item->client->session == NULL)
74: envent = environ_find(item->client->environ, "PATH");
1.11 nicm 75: else
1.15 nicm 76: envent = environ_find(s->environ, "PATH");
1.11 nicm 77: if (envent != NULL)
78: path = envent->value;
79:
1.23 ! nicm 80: env = environ_for_session(s);
1.16 nicm 81: if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
1.12 nicm 82: s->tio, &cause) != 0) {
1.22 nicm 83: cmdq_error(item, "respawn pane failed: %s", cause);
1.6 nicm 84: free(cause);
1.15 nicm 85: environ_free(env);
1.7 nicm 86: return (CMD_RETURN_ERROR);
1.1 nicm 87: }
1.23 ! nicm 88: environ_free(env);
! 89:
1.1 nicm 90: wp->flags |= PANE_REDRAW;
91: server_status_window(w);
92:
1.7 nicm 93: return (CMD_RETURN_NORMAL);
1.1 nicm 94: }