sync with OpenBSD -current

This commit is contained in:
purplerain 2024-05-17 17:07:28 +00:00
parent 65428aad14
commit 57ecf9bd1d
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
2058 changed files with 272997 additions and 201906 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.161 2023/07/10 12:00:08 nicm Exp $ */
/* $OpenBSD: client.c,v 1.162 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -490,20 +490,10 @@ client_send_identify(const char *ttynam, const char *termname, char **caps,
static __dead void
client_exec(const char *shell, const char *shellcmd)
{
const char *name, *ptr;
char *argv0;
char *argv0;
log_debug("shell %s, command %s", shell, shellcmd);
ptr = strrchr(shell, '/');
if (ptr != NULL && *(ptr + 1) != '\0')
name = ptr + 1;
else
name = shell;
if (client_flags & CLIENT_LOGIN)
xasprintf(&argv0, "-%s", name);
else
xasprintf(&argv0, "%s", name);
argv0 = shell_argv0(shell, !!(client_flags & CLIENT_LOGIN));
setenv("SHELL", shell, 1);
proc_clear_signals(client_proc, 1);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: cmd-confirm-before.c,v 1.54 2024/04/15 08:19:55 nicm Exp $ */
/* $OpenBSD: cmd-confirm-before.c,v 1.55 2024/05/15 08:39:30 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@ -92,6 +92,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
cdata->confirm_key = confirm_key[0];
else {
cmdq_error(item, "invalid confirm key");
free(cdata);
return (CMD_RETURN_ERROR);
}
}
@ -102,8 +103,8 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
xasprintf(&new_prompt, "%s ", prompt);
else {
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ",
cmd, cdata->confirm_key);
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", cmd,
cdata->confirm_key);
}
status_prompt_set(tc, target, new_prompt, NULL,

View file

@ -1,4 +1,4 @@
/* $OpenBSD: cmd-queue.c,v 1.116 2024/04/23 13:34:51 jsg Exp $ */
/* $OpenBSD: cmd-queue.c,v 1.117 2024/05/14 07:52:19 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -665,9 +665,18 @@ cmdq_fire_command(struct cmdq_item *item)
out:
item->client = saved;
if (retval == CMD_RETURN_ERROR)
if (retval == CMD_RETURN_ERROR) {
fsp = NULL;
if (cmd_find_valid_state(&item->target))
fsp = &item->target;
else if (cmd_find_valid_state(&item->state->current))
fsp = &item->state->current;
else if (cmd_find_from_client(&fs, item->client, 0) == 0)
fsp = &fs;
cmdq_insert_hook(fsp != NULL ? fsp->s : NULL, item, fsp,
"command-error");
cmdq_guard(item, "error", flags);
else
} else
cmdq_guard(item, "end", flags);
return (retval);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: cmd-run-shell.c,v 1.85 2023/08/23 08:40:25 nicm Exp $ */
/* $OpenBSD: cmd-run-shell.c,v 1.86 2024/05/14 07:33:01 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@ -85,12 +85,18 @@ cmd_run_shell_print(struct job *job, const char *msg)
if (cdata->wp_id != -1)
wp = window_pane_find_by_id(cdata->wp_id);
if (wp == NULL && cdata->item != NULL && cdata->client != NULL)
wp = server_client_get_pane(cdata->client);
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
wp = fs.wp;
if (wp == NULL)
return;
if (wp == NULL) {
if (cdata->item != NULL) {
cmdq_print(cdata->item, "%s", msg);
return;
}
if (cdata->item != NULL && cdata->client != NULL)
wp = server_client_get_pane(cdata->client);
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
wp = fs.wp;
if (wp == NULL)
return;
}
wme = TAILQ_FIRST(&wp->modes);
if (wme == NULL || wme->mode != &window_view_mode)

View file

@ -1,4 +1,4 @@
/* $OpenBSD: job.c,v 1.67 2022/02/01 12:05:42 nicm Exp $ */
/* $OpenBSD: job.c,v 1.68 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -79,19 +79,28 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
struct environ *env;
pid_t pid;
int nullfd, out[2], master;
const char *home;
const char *home, *shell;
sigset_t set, oldset;
struct winsize ws;
char **argvp, tty[TTY_NAME_MAX];
char **argvp, tty[TTY_NAME_MAX], *argv0;
/*
* Do not set TERM during .tmux.conf, it is nice to be able to use
* if-shell to decide on default-terminal based on outside TERM.
* Do not set TERM during .tmux.conf (second argument here), it is nice
* to be able to use if-shell to decide on default-terminal based on
* outside TERM.
*/
env = environ_for_session(s, !cfg_finished);
if (e != NULL)
environ_copy(e, env);
if (s != NULL)
shell = options_get_string(s->options, "default-shell");
else
shell = options_get_string(global_s_options, "default-shell");
if (!checkshell(shell))
shell = _PATH_BSHELL;
argv0 = shell_argv0(shell, 0);
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, &oldset);
@ -107,10 +116,11 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
}
if (cmd == NULL) {
cmd_log_argv(argc, argv, "%s:", __func__);
log_debug("%s: cwd=%s", __func__, cwd == NULL ? "" : cwd);
log_debug("%s: cwd=%s, shell=%s", __func__,
cwd == NULL ? "" : cwd, shell);
} else {
log_debug("%s: cmd=%s, cwd=%s", __func__, cmd,
cwd == NULL ? "" : cwd);
log_debug("%s: cmd=%s, cwd=%s, shell=%s", __func__, cmd,
cwd == NULL ? "" : cwd, shell);
}
switch (pid) {
@ -152,7 +162,8 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
closefrom(STDERR_FILENO + 1);
if (cmd != NULL) {
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
setenv("SHELL", shell, 1);
execl(shell, argv0, "-c", cmd, (char *)NULL);
fatal("execl failed");
} else {
argvp = cmd_copy_argv(argc, argv);
@ -163,6 +174,7 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
sigprocmask(SIG_SETMASK, &oldset, NULL);
environ_free(env);
free(argv0);
job = xmalloc(sizeof *job);
job->state = JOB_RUNNING;
@ -196,12 +208,13 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
fatalx("out of memory");
bufferevent_enable(job->event, EV_READ|EV_WRITE);
log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid);
log_debug("run job %p: %s, pid %ld", job, job->cmd, (long)job->pid);
return (job);
fail:
sigprocmask(SIG_SETMASK, &oldset, NULL);
environ_free(env);
free(argv0);
return (NULL);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: options-table.c,v 1.171 2024/04/10 07:36:25 nicm Exp $ */
/* $OpenBSD: options-table.c,v 1.174 2024/05/14 09:32:37 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -1326,6 +1326,7 @@ const struct options_table_entry options_table[] = {
OPTIONS_TABLE_HOOK("client-focus-out", ""),
OPTIONS_TABLE_HOOK("client-resized", ""),
OPTIONS_TABLE_HOOK("client-session-changed", ""),
OPTIONS_TABLE_HOOK("command-error", ""),
OPTIONS_TABLE_PANE_HOOK("pane-died", ""),
OPTIONS_TABLE_PANE_HOOK("pane-exited", ""),
OPTIONS_TABLE_PANE_HOOK("pane-focus-in", ""),

View file

@ -1,4 +1,4 @@
/* $OpenBSD: server.c,v 1.205 2023/09/15 15:49:05 nicm Exp $ */
/* $OpenBSD: server.c,v 1.206 2024/05/14 10:11:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -258,7 +258,7 @@ server_loop(void)
struct client *c;
u_int items;
current_time = time (NULL);
current_time = time(NULL);
do {
items = cmdq_next(NULL);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: status.c,v 1.241 2023/11/14 15:59:49 nicm Exp $ */
/* $OpenBSD: status.c,v 1.242 2024/05/15 08:39:30 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -994,8 +994,7 @@ status_prompt_paste(struct client *c)
if ((pb = paste_get_top(NULL)) == NULL)
return (0);
bufdata = paste_buffer_data(pb, &bufsize);
ud = xreallocarray(NULL, bufsize + 1, sizeof *ud);
udp = ud;
ud = udp = xreallocarray(NULL, bufsize + 1, sizeof *ud);
for (i = 0; i != bufsize; /* nothing */) {
more = utf8_open(udp, bufdata[i]);
if (more == UTF8_MORE) {
@ -1016,25 +1015,24 @@ status_prompt_paste(struct client *c)
udp->size = 0;
n = udp - ud;
}
if (n == 0)
return (0);
c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1,
sizeof *c->prompt_buffer);
if (c->prompt_index == size) {
memcpy(c->prompt_buffer + c->prompt_index, ud,
n * sizeof *c->prompt_buffer);
c->prompt_index += n;
c->prompt_buffer[c->prompt_index].size = 0;
} else {
memmove(c->prompt_buffer + c->prompt_index + n,
c->prompt_buffer + c->prompt_index,
(size + 1 - c->prompt_index) * sizeof *c->prompt_buffer);
memcpy(c->prompt_buffer + c->prompt_index, ud,
n * sizeof *c->prompt_buffer);
c->prompt_index += n;
if (n != 0) {
c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1,
sizeof *c->prompt_buffer);
if (c->prompt_index == size) {
memcpy(c->prompt_buffer + c->prompt_index, ud,
n * sizeof *c->prompt_buffer);
c->prompt_index += n;
c->prompt_buffer[c->prompt_index].size = 0;
} else {
memmove(c->prompt_buffer + c->prompt_index + n,
c->prompt_buffer + c->prompt_index,
(size + 1 - c->prompt_index) *
sizeof *c->prompt_buffer);
memcpy(c->prompt_buffer + c->prompt_index, ud,
n * sizeof *c->prompt_buffer);
c->prompt_index += n;
}
}
if (ud != c->prompt_saved)
free(ud);
return (1);
@ -1839,6 +1837,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s,
}
if (size == 0) {
menu_free(menu);
free(spm);
return (NULL);
}
if (size == 1) {
@ -1849,6 +1848,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s,
} else
tmp = list[0];
free(list);
free(spm);
return (tmp);
}
if (height > size)

View file

@ -1,4 +1,4 @@
.\" $OpenBSD: tmux.1,v 1.941 2024/04/10 07:36:25 nicm Exp $
.\" $OpenBSD: tmux.1,v 1.944 2024/05/14 09:32:37 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: April 10 2024 $
.Dd $Mdocdate: May 14 2024 $
.Dt TMUX 1
.Os
.Sh NAME
@ -4881,6 +4881,14 @@ layout after every
set-hook -g after-split-window "selectl even-vertical"
.Ed
.Pp
If a command fails, the
.Ql command-error
hook will be fired.
For example, this could be used to write to a log file:
.Bd -literal -offset indent
set-hook -g command-error "run-shell \\"echo 'a tmux command failed' >>/tmp/log\\""
.Ed
.Pp
All the notifications listed in the
.Sx CONTROL MODE
section are hooks (without any arguments), except
@ -4913,6 +4921,8 @@ Run when focus exits a client
Run when a client is resized.
.It client-session-changed
Run when a client's attached session is changed.
.It command-error
Run when a command fails.
.It pane-died
Run when the program running in a pane exits, but
.Ic remain-on-exit

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tmux.c,v 1.211 2023/04/17 18:00:19 nicm Exp $ */
/* $OpenBSD: tmux.c,v 1.212 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -239,6 +239,24 @@ fail:
return (NULL);
}
char *
shell_argv0(const char *shell, int is_login)
{
const char *slash, *name;
char *argv0;
slash = strrchr(shell, '/');
if (slash != NULL && slash[1] != '\0')
name = slash + 1;
else
name = shell;
if (is_login)
xasprintf(&argv0, "-%s", name);
else
xasprintf(&argv0, "%s", name);
return (argv0);
}
void
setblocking(int fd, int state)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tmux.h,v 1.1214 2024/04/10 07:36:25 nicm Exp $ */
/* $OpenBSD: tmux.h,v 1.1215 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -2062,6 +2062,7 @@ extern int ptm_fd;
extern const char *shell_command;
int checkshell(const char *);
void setblocking(int, int);
char *shell_argv0(const char *, int);
uint64_t get_timer(void);
const char *sig2name(int);
const char *find_cwd(void);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tty.c,v 1.435 2023/09/15 15:49:05 nicm Exp $ */
/* $OpenBSD: tty.c,v 1.436 2024/05/14 10:11:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
@ -374,13 +375,13 @@ tty_send_requests(struct tty *tty)
tty_puts(tty, "\033]11;?\033\\");
} else
tty->flags |= TTY_ALL_REQUEST_FLAGS;
tty->last_requests = time (NULL);
tty->last_requests = time(NULL);
}
void
tty_repeat_requests(struct tty *tty)
{
time_t t = time (NULL);
time_t t = time(NULL);
if (~tty->flags & TTY_STARTED)
return;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: window-copy.c,v 1.348 2024/04/23 13:34:51 jsg Exp $ */
/* $OpenBSD: window-copy.c,v 1.350 2024/05/14 09:32:37 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -3614,11 +3614,10 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
struct grid *sgd, u_int fx, u_int fy, u_int endline, int cis, int wrap,
int direction, int regex)
{
u_int i, px, sx, ssize = 1;
int found = 0, cflags = REG_EXTENDED;
char *sbuf;
regex_t reg;
struct grid_line *gl;
u_int i, px, sx, ssize = 1;
int found = 0, cflags = REG_EXTENDED;
char *sbuf;
regex_t reg;
if (regex) {
sbuf = xmalloc(ssize);
@ -3635,9 +3634,6 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
if (direction) {
for (i = fy; i <= endline; i++) {
gl = grid_get_line(gd, i);
if (i != endline && gl->flags & GRID_LINE_WRAPPED)
continue;
if (regex) {
found = window_copy_search_lr_regex(gd,
&px, &sx, i, fx, gd->sx, &reg);
@ -3651,9 +3647,6 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
}
} else {
for (i = fy + 1; endline < i; i--) {
gl = grid_get_line(gd, i - 1);
if (i != endline && gl->flags & GRID_LINE_WRAPPED)
continue;
if (regex) {
found = window_copy_search_rl_regex(gd,
&px, &sx, i - 1, 0, fx + 1, &reg);