Coverage Report

Created: 2026-01-09 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tmux/cmd-respawn-pane.c
Line
Count
Source
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 <string.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 = { "c:e:kt:", 0, -1, NULL },
38
  .usage = "[-k] [-c start-directory] [-e environment] "
39
     CMD_TARGET_PANE_USAGE " [shell-command [argument ...]]",
40
41
  .target = { 't', CMD_FIND_PANE, 0 },
42
43
  .flags = 0,
44
  .exec = cmd_respawn_pane_exec
45
};
46
47
static enum cmd_retval
48
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
49
0
{
50
0
  struct args   *args = cmd_get_args(self);
51
0
  struct cmd_find_state *target = cmdq_get_target(item);
52
0
  struct spawn_context   sc = { 0 };
53
0
  struct session    *s = target->s;
54
0
  struct winlink    *wl = target->wl;
55
0
  struct window_pane  *wp = target->wp;
56
0
  char      *cause = NULL;
57
0
  struct args_value *av;
58
59
0
  sc.item = item;
60
0
  sc.s = s;
61
0
  sc.wl = wl;
62
63
0
  sc.wp0 = wp;
64
65
0
  args_to_vector(args, &sc.argc, &sc.argv);
66
0
  sc.environ = environ_create();
67
68
0
  av = args_first_value(args, 'e');
69
0
  while (av != NULL) {
70
0
    environ_put(sc.environ, av->string, 0);
71
0
    av = args_next_value(av);
72
0
  }
73
74
0
  sc.idx = -1;
75
0
  sc.cwd = args_get(args, 'c');
76
77
0
  sc.flags = SPAWN_RESPAWN;
78
0
  if (args_has(args, 'k'))
79
0
    sc.flags |= SPAWN_KILL;
80
81
0
  if (spawn_pane(&sc, &cause) == NULL) {
82
0
    cmdq_error(item, "respawn pane failed: %s", cause);
83
0
    free(cause);
84
0
    if (sc.argv != NULL)
85
0
      cmd_free_argv(sc.argc, sc.argv);
86
0
    environ_free(sc.environ);
87
0
    return (CMD_RETURN_ERROR);
88
0
  }
89
90
0
  wp->flags |= PANE_REDRAW;
91
0
  server_redraw_window_borders(wp->window);
92
0
  server_status_window(wp->window);
93
94
0
  if (sc.argv != NULL)
95
0
    cmd_free_argv(sc.argc, sc.argv);
96
0
  environ_free(sc.environ);
97
0
  return (CMD_RETURN_NORMAL);
98
0
}