diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index ec6091ed..2247efb7 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -124,7 +124,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) /* Fork the child. */ sigfillset(&set); sigprocmask(SIG_BLOCK, &set, &oldset); - switch (fork()) { + switch ((wp->pipe_pid = fork())) { case -1: sigprocmask(SIG_SETMASK, &oldset, NULL); cmdq_error(item, "fork error: %s", strerror(errno)); @@ -137,6 +137,9 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) sigprocmask(SIG_SETMASK, &oldset, NULL); close(pipe_fd[0]); + if (setpgid(0, 0) == -1) + _exit(1); + null_fd = open(_PATH_DEVNULL, O_WRONLY); if (out) { if (dup2(pipe_fd[1], STDIN_FILENO) == -1) diff --git a/format.c b/format.c index dd4ce542..2ed398c2 100644 --- a/format.c +++ b/format.c @@ -2225,6 +2225,17 @@ format_cb_pane_pipe(struct format_tree *ft) return (NULL); } +/* Callback for pane_pipe_pid. */ +static void * +format_cb_pane_pipe_pid(struct format_tree *ft) +{ + char *value = NULL; + + if (ft->wp != NULL && ft->wp->pipe_fd != -1) + xasprintf(&value, "%ld", (long)ft->wp->pipe_pid); + return (value); +} + /* Callback for pane_right. */ static void * format_cb_pane_right(struct format_tree *ft) @@ -3311,6 +3322,9 @@ static const struct format_table_entry format_table[] = { { "pane_pipe", FORMAT_TABLE_STRING, format_cb_pane_pipe }, + { "pane_pipe_pid", FORMAT_TABLE_STRING, + format_cb_pane_pipe_pid + }, { "pane_right", FORMAT_TABLE_STRING, format_cb_pane_right }, diff --git a/tmux.1 b/tmux.1 index f5be9a8e..32b0c640 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6323,6 +6323,7 @@ The following variables are available, where appropriate: .It Li "pane_path" Ta "" Ta "Path of pane (can be set by application)" .It Li "pane_pid" Ta "" Ta "PID of first process in pane" .It Li "pane_pipe" Ta "" Ta "1 if pane is being piped" +.It Li "pane_pipe_pid" Ta "" Ta "PID of pipe process, if any" .It Li "pane_right" Ta "" Ta "Right of pane" .It Li "pane_search_string" Ta "" Ta "Last search string in copy mode" .It Li "pane_start_command" Ta "" Ta "Command pane started with" diff --git a/tmux.h b/tmux.h index 349347c9..2a9eb46f 100644 --- a/tmux.h +++ b/tmux.h @@ -1213,6 +1213,7 @@ struct window_pane { enum client_theme last_theme; int pipe_fd; + pid_t pipe_pid; struct bufferevent *pipe_event; struct window_pane_offset pipe_offset;