Annotation of src/usr.bin/tmux/cmd-respawn-pane.c, Revision 1.6
1.6 ! nicm 1: /* $OpenBSD: cmd-respawn-pane.c,v 1.5 2012/03/17 22:34:12 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:
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:
31: int cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
32:
33: const struct cmd_entry cmd_respawn_pane_entry = {
34: "respawn-pane", "respawnp",
35: "kt:", 0, 1,
36: "[-k] " CMD_TARGET_PANE_USAGE " [command]",
37: 0,
38: NULL,
39: NULL,
40: cmd_respawn_pane_exec
41: };
42:
43: int
44: cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
45: {
46: struct args *args = self->args;
47: struct winlink *wl;
48: struct window *w;
49: struct window_pane *wp;
50: struct session *s;
51: struct environ env;
52: const char *cmd;
1.4 nicm 53: char *cause;
54: u_int idx;
1.1 nicm 55:
56: if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
57: return (-1);
58: w = wl->window;
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.1 nicm 63: ctx->error(ctx, "pane still active: %s:%u.%u",
1.4 nicm 64: s->name, wl->idx, idx);
1.1 nicm 65: return (-1);
66: }
67:
68: environ_init(&env);
69: environ_copy(&global_environ, &env);
70: environ_copy(&s->environ, &env);
71: server_fill_environ(s, &env);
72:
73: window_pane_reset_mode(wp);
1.2 nicm 74: screen_reinit(&wp->base);
1.1 nicm 75: input_init(wp);
76:
77: if (args->argc != 0)
78: cmd = args->argv[0];
79: else
80: cmd = NULL;
81: if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
82: ctx->error(ctx, "respawn pane failed: %s", cause);
1.6 ! nicm 83: free(cause);
1.1 nicm 84: environ_free(&env);
85: return (-1);
86: }
87: wp->flags |= PANE_REDRAW;
88: server_status_window(w);
89:
90: environ_free(&env);
91: return (0);
92: }