-/* $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 <nicholas.marriott@gmail.com>
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 *);
};
/* 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);
}
}
-/* 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. */
{
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);
-/* $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 <nicholas.marriott@gmail.com>
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;
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);
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);
-/* $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 <nicholas.marriott@gmail.com>
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,