Coverage Report

Created: 2026-01-25 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tmux/cmd-respawn-window.c
Line
Count
Source
1
/* $OpenBSD$ */
2
3
/*
4
 * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 */
18
19
#include <sys/types.h>
20
21
#include <stdlib.h>
22
#include <string.h>
23
24
#include "tmux.h"
25
26
/*
27
 * Respawn a window (restart the command). Kill existing if -k given.
28
 */
29
30
static enum cmd_retval  cmd_respawn_window_exec(struct cmd *,
31
          struct cmdq_item *);
32
33
const struct cmd_entry cmd_respawn_window_entry = {
34
  .name = "respawn-window",
35
  .alias = "respawnw",
36
37
  .args = { "c:e:kt:", 0, -1, NULL },
38
  .usage = "[-k] [-c start-directory] [-e environment] "
39
     CMD_TARGET_WINDOW_USAGE " [shell-command [argument ...]]",
40
41
  .target = { 't', CMD_FIND_WINDOW, 0 },
42
43
  .flags = 0,
44
  .exec = cmd_respawn_window_exec
45
};
46
47
static enum cmd_retval
48
cmd_respawn_window_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 client   *tc = cmdq_get_target_client(item);
54
0
  struct session    *s = target->s;
55
0
  struct winlink    *wl = target->wl;
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
0
  sc.tc = tc;
63
64
0
  args_to_vector(args, &sc.argc, &sc.argv);
65
0
  sc.environ = environ_create();
66
67
0
  av = args_first_value(args, 'e');
68
0
  while (av != NULL) {
69
0
    environ_put(sc.environ, av->string, 0);
70
0
    av = args_next_value(av);
71
0
  }
72
73
0
  sc.idx = -1;
74
0
  sc.cwd = args_get(args, 'c');
75
76
0
  sc.flags = SPAWN_RESPAWN;
77
0
  if (args_has(args, 'k'))
78
0
    sc.flags |= SPAWN_KILL;
79
80
0
  if (spawn_window(&sc, &cause) == NULL) {
81
0
    cmdq_error(item, "respawn window failed: %s", cause);
82
0
    free(cause);
83
0
    if (sc.argv != NULL)
84
0
      cmd_free_argv(sc.argc, sc.argv);
85
0
    environ_free(sc.environ);
86
0
    return (CMD_RETURN_ERROR);
87
0
  }
88
89
0
  server_redraw_window(wl->window);
90
91
0
  if (sc.argv != NULL)
92
0
    cmd_free_argv(sc.argc, sc.argv);
93
0
  environ_free(sc.environ);
94
0
  return (CMD_RETURN_NORMAL);
95
0
}