From: nicm Date: Thu, 11 Mar 2021 07:08:18 +0000 (+0000) Subject: Tidy old jobs every hour instead of every 30 seconds. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=97887b4c10d2ce44d533fa4f1918ef466274ae46;p=openbsd Tidy old jobs every hour instead of every 30 seconds. --- diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 1f9c63898d8..93e653826f3 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.281 2021/03/02 10:56:45 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.282 2021/03/11 07:08:18 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -41,7 +41,6 @@ struct format_expand_state; 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 int format_replace(struct format_expand_state *, const char *, size_t, char **, size_t *, size_t *); @@ -69,7 +68,6 @@ struct format_job { }; /* Format job tree. */ -static struct event format_job_event; static int format_job_cmp(struct format_job *, struct format_job *); static RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER(); RB_GENERATE_STATIC(format_job_tree, format_job, entry, format_job_cmp); @@ -437,30 +435,26 @@ format_job_tidy(struct format_job_tree *jobs, int force) } } -/* Remove old jobs for client. */ +/* Tidy old jobs for all clients. */ void -format_lost_client(struct client *c) -{ - if (c->jobs != NULL) - format_job_tidy(c->jobs, 1); - free(c->jobs); -} - -/* Remove old jobs periodically. */ -static void -format_job_timer(__unused int fd, __unused short events, __unused void *arg) +format_tidy_jobs(void) { 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); +/* Remove old jobs for client. */ +void +format_lost_client(struct client *c) +{ + if (c->jobs != NULL) + format_job_tidy(c->jobs, 1); + free(c->jobs); } /* Wrapper for asprintf. */ @@ -3048,11 +3042,6 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags) { 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); RB_INIT(&ft->tree); diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index ccbdddcdfc8..6fccb8e4a62 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.196 2021/02/11 09:39:29 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.197 2021/03/11 07:08:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -48,6 +48,7 @@ static int server_fd = -1; static uint64_t server_client_flags; static int server_exit; static struct event server_ev_accept; +static struct event server_ev_tidy; struct cmd_find_state marked_pane; @@ -151,15 +152,29 @@ fail: 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. */ int server_start(struct tmuxproc *client, int flags, struct event_base *base, int lockfd, char *lockfile) { - int fd; - sigset_t set, oldset; - struct client *c = NULL; - char *cause = NULL; + int fd; + sigset_t set, oldset; + struct client *c = NULL; + char *cause = NULL; + struct timeval tv = { .tv_sec = 3600 }; sigfillset(&set); sigprocmask(SIG_BLOCK, &set, &oldset); @@ -218,6 +233,9 @@ server_start(struct tmuxproc *client, int flags, struct event_base *base, free(cause); } + evtimer_set(&server_ev_tidy, server_tidy_event, NULL); + evtimer_add(&server_ev_tidy, &tv); + server_add_accept(0); proc_loop(server_proc, server_loop); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 74585717196..d363a1e770e 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1098 2021/03/11 06:41:04 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1099 2021/03/11 07:08:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1947,6 +1947,7 @@ char *paste_make_sample(struct paste_buffer *); struct format_tree; struct format_modifier; typedef void *(*format_cb)(struct format_tree *); +void format_tidy_jobs(void); const char *format_skip(const char *, const char *); int format_true(const char *); struct format_tree *format_create(struct client *, struct cmdq_item *, int,