mirror of
https://github.com/tmux/tmux.git
synced 2026-10-06 17:49:52 +00:00
Do not leak client if lost before configuration is loaded, and do not load
multiple times. GitHub issues 5661 and 5662 from Alexandre Fiori.
This commit is contained in:
30
cfg.c
30
cfg.c
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cfg.c,v 1.91 2026/08/03 13:38:42 nicm Exp $ */
|
||||
/* $OpenBSD: cfg.c,v 1.92 2026/10/02 12:28:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@@ -32,14 +32,17 @@ int cfg_finished;
|
||||
static char **cfg_causes;
|
||||
static u_int cfg_ncauses;
|
||||
static struct cmdq_item *cfg_item;
|
||||
static int cfg_started;
|
||||
|
||||
int cfg_quiet = 1;
|
||||
char **cfg_files;
|
||||
u_int cfg_nfiles;
|
||||
|
||||
static enum cmd_retval
|
||||
cfg_client_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
cfg_client_done(struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
if (cmdq_get_client(item)->flags & CLIENT_DEAD)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (!cfg_finished)
|
||||
return (CMD_RETURN_WAIT);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -54,14 +57,28 @@ cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
|
||||
cfg_show_causes(NULL);
|
||||
|
||||
if (cfg_item != NULL)
|
||||
if (cfg_item != NULL) {
|
||||
cmdq_continue(cfg_item);
|
||||
cfg_item = NULL;
|
||||
}
|
||||
|
||||
prompt_load_history();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cfg_client_lost(struct client *c)
|
||||
{
|
||||
if (c != cfg_client)
|
||||
return;
|
||||
cfg_client = NULL;
|
||||
if (cfg_item != NULL) {
|
||||
cmdq_continue(cfg_item);
|
||||
cfg_item = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
start_cfg(void)
|
||||
{
|
||||
@@ -78,12 +95,19 @@ start_cfg(void)
|
||||
* Because start_cfg() is called so early, we can be sure the client's
|
||||
* command queue is currently empty and our callback will be at the
|
||||
* front - we need to get in before MSG_COMMAND.
|
||||
*
|
||||
* If the initial client is lost before the configuration finishes, the
|
||||
* next client to identify is first in the list and ends up here. Block
|
||||
* it instead, but do not load the files again.
|
||||
*/
|
||||
cfg_client = c = TAILQ_FIRST(&clients);
|
||||
if (c != NULL) {
|
||||
cfg_item = cmdq_get_callback(cfg_client_done, NULL);
|
||||
cmdq_append(c, cfg_item);
|
||||
}
|
||||
if (cfg_started)
|
||||
return;
|
||||
cfg_started = 1;
|
||||
|
||||
if (cfg_quiet)
|
||||
flags = CMD_PARSE_QUIET;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: server-client.c,v 1.515 2026/09/28 11:25:51 nicm Exp $ */
|
||||
/* $OpenBSD: server-client.c,v 1.516 2026/10/02 12:28:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@@ -374,8 +374,7 @@ server_client_lost(struct client *c)
|
||||
{
|
||||
struct client_file *cf, *cf1;
|
||||
|
||||
if (cfg_client == c)
|
||||
cfg_client = NULL;
|
||||
cfg_client_lost(c);
|
||||
c->flags |= CLIENT_DEAD;
|
||||
|
||||
status_prompt_clear(c);
|
||||
|
||||
3
tmux.h
3
tmux.h
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: tmux.h,v 1.1449 2026/09/28 10:10:16 nicm Exp $ */
|
||||
/* $OpenBSD: tmux.h,v 1.1450 2026/10/02 12:28:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@@ -2570,6 +2570,7 @@ extern char **cfg_files;
|
||||
extern u_int cfg_nfiles;
|
||||
extern int cfg_quiet;
|
||||
void start_cfg(void);
|
||||
void cfg_client_lost(struct client *);
|
||||
int load_cfg(const char *, struct client *, struct cmdq_item *,
|
||||
struct cmd_find_state *, int, struct cmdq_item **);
|
||||
int load_cfg_from_buffer(const void *, size_t, const char *,
|
||||
|
||||
Reference in New Issue
Block a user