Coverage Report

Created: 2026-10-17 06:19

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