mirror of
https://github.com/tmux/tmux.git
synced 2025-03-29 02:08:48 +00:00
Tidy old jobs every hour instead of every 30 seconds.
This commit is contained in:
parent
3eb91efba1
commit
ee0df1b8f8
37
format.c
37
format.c
@ -41,7 +41,6 @@
|
|||||||
struct format_expand_state;
|
struct format_expand_state;
|
||||||
|
|
||||||
static char *format_job_get(struct format_expand_state *, const char *);
|
static char *format_job_get(struct format_expand_state *, const char *);
|
||||||
static void format_job_timer(int, short, void *);
|
|
||||||
static char *format_expand1(struct format_expand_state *, const char *);
|
static char *format_expand1(struct format_expand_state *, const char *);
|
||||||
static int format_replace(struct format_expand_state *, const char *,
|
static int format_replace(struct format_expand_state *, const char *,
|
||||||
size_t, char **, size_t *, size_t *);
|
size_t, char **, size_t *, size_t *);
|
||||||
@ -69,7 +68,6 @@ struct format_job {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Format job tree. */
|
/* Format job tree. */
|
||||||
static struct event format_job_event;
|
|
||||||
static int format_job_cmp(struct format_job *, struct format_job *);
|
static int format_job_cmp(struct format_job *, struct format_job *);
|
||||||
static RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER();
|
static RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER();
|
||||||
RB_GENERATE_STATIC(format_job_tree, format_job, entry, format_job_cmp);
|
RB_GENERATE_STATIC(format_job_tree, format_job, entry, format_job_cmp);
|
||||||
@ -437,6 +435,19 @@ format_job_tidy(struct format_job_tree *jobs, int force)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tidy old jobs for all clients. */
|
||||||
|
void
|
||||||
|
format_tidy_jobs(void)
|
||||||
|
{
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
format_job_tidy(&format_jobs, 0);
|
||||||
|
TAILQ_FOREACH(c, &clients, entry) {
|
||||||
|
if (c->jobs != NULL)
|
||||||
|
format_job_tidy(c->jobs, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove old jobs for client. */
|
/* Remove old jobs for client. */
|
||||||
void
|
void
|
||||||
format_lost_client(struct client *c)
|
format_lost_client(struct client *c)
|
||||||
@ -446,23 +457,6 @@ format_lost_client(struct client *c)
|
|||||||
free(c->jobs);
|
free(c->jobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove old jobs periodically. */
|
|
||||||
static void
|
|
||||||
format_job_timer(__unused int fd, __unused short events, __unused void *arg)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
struct timeval tv = { .tv_sec = 60 };
|
|
||||||
|
|
||||||
format_job_tidy(&format_jobs, 0);
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->jobs != NULL)
|
|
||||||
format_job_tidy(c->jobs, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
evtimer_del(&format_job_event);
|
|
||||||
evtimer_add(&format_job_event, &tv);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wrapper for asprintf. */
|
/* Wrapper for asprintf. */
|
||||||
static char * printflike(1, 2)
|
static char * printflike(1, 2)
|
||||||
format_printf(const char *fmt, ...)
|
format_printf(const char *fmt, ...)
|
||||||
@ -3048,11 +3042,6 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
|
|||||||
{
|
{
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
|
|
||||||
if (!event_initialized(&format_job_event)) {
|
|
||||||
evtimer_set(&format_job_event, format_job_timer, NULL);
|
|
||||||
format_job_timer(-1, 0, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
ft = xcalloc(1, sizeof *ft);
|
ft = xcalloc(1, sizeof *ft);
|
||||||
RB_INIT(&ft->tree);
|
RB_INIT(&ft->tree);
|
||||||
|
|
||||||
|
26
server.c
26
server.c
@ -48,6 +48,7 @@ static int server_fd = -1;
|
|||||||
static uint64_t server_client_flags;
|
static uint64_t server_client_flags;
|
||||||
static int server_exit;
|
static int server_exit;
|
||||||
static struct event server_ev_accept;
|
static struct event server_ev_accept;
|
||||||
|
static struct event server_ev_tidy;
|
||||||
|
|
||||||
struct cmd_find_state marked_pane;
|
struct cmd_find_state marked_pane;
|
||||||
|
|
||||||
@ -151,15 +152,29 @@ fail:
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tidy up every hour. */
|
||||||
|
static void
|
||||||
|
server_tidy_event(__unused int fd, __unused short events, __unused void *data)
|
||||||
|
{
|
||||||
|
struct timeval tv = { .tv_sec = 3600 };
|
||||||
|
uint64_t t = get_timer();
|
||||||
|
|
||||||
|
format_tidy_jobs();
|
||||||
|
|
||||||
|
log_debug("%s: took %llu milliseconds", __func__, get_timer() - t);
|
||||||
|
evtimer_add(&server_ev_tidy, &tv);
|
||||||
|
}
|
||||||
|
|
||||||
/* Fork new server. */
|
/* Fork new server. */
|
||||||
int
|
int
|
||||||
server_start(struct tmuxproc *client, int flags, struct event_base *base,
|
server_start(struct tmuxproc *client, int flags, struct event_base *base,
|
||||||
int lockfd, char *lockfile)
|
int lockfd, char *lockfile)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
sigset_t set, oldset;
|
sigset_t set, oldset;
|
||||||
struct client *c = NULL;
|
struct client *c = NULL;
|
||||||
char *cause = NULL;
|
char *cause = NULL;
|
||||||
|
struct timeval tv = { .tv_sec = 3600 };
|
||||||
|
|
||||||
sigfillset(&set);
|
sigfillset(&set);
|
||||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||||
@ -218,6 +233,9 @@ server_start(struct tmuxproc *client, int flags, struct event_base *base,
|
|||||||
free(cause);
|
free(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evtimer_set(&server_ev_tidy, server_tidy_event, NULL);
|
||||||
|
evtimer_add(&server_ev_tidy, &tv);
|
||||||
|
|
||||||
server_add_accept(0);
|
server_add_accept(0);
|
||||||
proc_loop(server_proc, server_loop);
|
proc_loop(server_proc, server_loop);
|
||||||
|
|
||||||
|
1
tmux.h
1
tmux.h
@ -1947,6 +1947,7 @@ char *paste_make_sample(struct paste_buffer *);
|
|||||||
struct format_tree;
|
struct format_tree;
|
||||||
struct format_modifier;
|
struct format_modifier;
|
||||||
typedef void *(*format_cb)(struct format_tree *);
|
typedef void *(*format_cb)(struct format_tree *);
|
||||||
|
void format_tidy_jobs(void);
|
||||||
const char *format_skip(const char *, const char *);
|
const char *format_skip(const char *, const char *);
|
||||||
int format_true(const char *);
|
int format_true(const char *);
|
||||||
struct format_tree *format_create(struct client *, struct cmdq_item *, int,
|
struct format_tree *format_create(struct client *, struct cmdq_item *, int,
|
||||||
|
Loading…
Reference in New Issue
Block a user