-/* $OpenBSD: cfg.c,v 1.58 2017/04/25 14:46:23 nicm Exp $ */
+/* $OpenBSD: cfg.c,v 1.59 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
line);
continue;
}
- ft = format_create(NULL, FORMAT_NONE, FORMAT_NOJOBS);
+ ft = format_create(NULL, NULL, FORMAT_NONE,
+ FORMAT_NOJOBS);
s = p + 3;
while (isspace((u_char)*s))
-/* $OpenBSD: cmd-display-message.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-display-message.c,v 1.42 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
if (template == NULL)
template = DISPLAY_MESSAGE_TEMPLATE;
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_defaults(ft, c, s, wl, wp);
msg = format_expand_time(ft, template, time(NULL));
-/* $OpenBSD: cmd-list-buffers.c,v 1.34 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-list-buffers.c,v 1.35 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
pb = NULL;
while ((pb = paste_walk(pb)) != NULL) {
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_defaults_paste_buffer(ft, pb);
line = format_expand(ft, template);
-/* $OpenBSD: cmd-list-clients.c,v 1.33 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-list-clients.c,v 1.34 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
if (c->session == NULL || (s != NULL && s != c->session))
continue;
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_add(ft, "line", "%u", idx);
format_defaults(ft, c, NULL, NULL, NULL);
-/* $OpenBSD: cmd-list-keys.c,v 1.43 2017/04/21 14:01:19 nicm Exp $ */
+/* $OpenBSD: cmd-list-keys.c,v 1.44 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
"#{command_list_usage}";
}
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_defaults(ft, NULL, NULL, NULL, NULL);
for (entryp = cmd_table; *entryp != NULL; entryp++) {
-/* $OpenBSD: cmd-list-panes.c,v 1.32 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-list-panes.c,v 1.33 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
n = 0;
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, wp);
-/* $OpenBSD: cmd-list-sessions.c,v 1.28 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-list-sessions.c,v 1.29 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
n = 0;
RB_FOREACH(s, sessions, &sessions) {
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, NULL, NULL);
-/* $OpenBSD: cmd-list-windows.c,v 1.42 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-list-windows.c,v 1.43 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
{
struct args *args = self->args;
struct winlink *wl;
- u_int n;
+ u_int n;
struct format_tree *ft;
const char *template;
char *line;
n = 0;
RB_FOREACH(wl, winlinks, &s->windows) {
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, NULL);
-/* $OpenBSD: cmd-pipe-pane.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-pipe-pane.c,v 1.42 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
}
/* Expand the command. */
- ft = format_create(item, FORMAT_NONE, 0);
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
format_defaults(ft, c, s, wl, wp);
cmd = format_expand_time(ft, args->argv[0], time(NULL));
format_free(ft);
-/* $OpenBSD: cmd-queue.c,v 1.54 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.55 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
va_end(ap);
if (shared->formats == NULL)
- shared->formats = format_create(NULL, FORMAT_NONE, 0);
+ shared->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
format_add(shared->formats, key, "%s", value);
free(value);
-/* $OpenBSD: format.c,v 1.130 2017/04/21 14:01:19 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.131 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
/* Entry in format job tree. */
struct format_job {
+ struct client *client;
u_int tag;
const char *cmd;
const char *expanded;
struct session *s;
struct window_pane *wp;
+ struct client *client;
u_int tag;
int flags;
struct format_job *fj = job->data;
char *line, *buf;
size_t len;
- struct client *c;
fj->job = NULL;
free(buf);
if (fj->status) {
- TAILQ_FOREACH(c, &clients, entry)
- server_status_client(c);
+ if (fj->client != NULL)
+ server_status_client(fj->client);
fj->status = 0;
}
}
static char *
format_job_get(struct format_tree *ft, const char *cmd)
{
+ struct format_job_tree *jobs;
struct format_job fj0, *fj;
time_t t;
char *expanded;
int force;
+ if (ft->client == NULL)
+ jobs = &format_jobs;
+ else if (ft->client->jobs != NULL)
+ jobs = ft->client->jobs;
+ else {
+ jobs = ft->client->jobs = xmalloc(sizeof *ft->client->jobs);
+ RB_INIT(jobs);
+ }
+
fj0.tag = ft->tag;
fj0.cmd = cmd;
- if ((fj = RB_FIND(format_job_tree, &format_jobs, &fj0)) == NULL) {
+ if ((fj = RB_FIND(format_job_tree, jobs, &fj0)) == NULL) {
fj = xcalloc(1, sizeof *fj);
+ fj->client = ft->client;
fj->tag = ft->tag;
fj->cmd = xstrdup(cmd);
fj->expanded = NULL;
xasprintf(&fj->out, "<'%s' not ready>", fj->cmd);
- RB_INSERT(format_job_tree, &format_jobs, fj);
+ RB_INSERT(format_job_tree, jobs, fj);
}
expanded = format_expand(ft, cmd);
/* Remove old jobs. */
static void
-format_job_timer(__unused int fd, __unused short events, __unused void *arg)
+format_job_tidy(struct format_job_tree *jobs, int force)
{
struct format_job *fj, *fj1;
time_t now;
- struct timeval tv = { .tv_sec = 60 };
now = time(NULL);
- RB_FOREACH_SAFE(fj, format_job_tree, &format_jobs, fj1) {
- if (fj->last > now || now - fj->last < 3600)
+ RB_FOREACH_SAFE(fj, format_job_tree, jobs, fj1) {
+ if (!force && (fj->last > now || now - fj->last < 3600))
continue;
- RB_REMOVE(format_job_tree, &format_jobs, fj);
+ RB_REMOVE(format_job_tree, jobs, fj);
log_debug("%s: %s", __func__, fj->cmd);
free(fj);
}
+}
+
+/* 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);
+}
+
+/* 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);
/* Create a new tree. */
struct format_tree *
-format_create(struct cmdq_item *item, int tag, int flags)
+format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
{
struct format_tree *ft;
ft = xcalloc(1, sizeof *ft);
RB_INIT(&ft->tree);
+ if (c != NULL) {
+ ft->client = c;
+ ft->client->references++;
+ }
+
ft->tag = tag;
ft->flags = flags;
free(fe);
}
+ if (ft->client != NULL)
+ server_client_unref(ft->client);
free(ft);
}
struct format_tree *ft;
char *expanded;
- ft = format_create(item, FORMAT_NONE, 0);
+ if (item != NULL)
+ ft = format_create(item->client, item, FORMAT_NONE, 0);
+ else
+ ft = format_create(NULL, item, FORMAT_NONE, 0);
format_defaults(ft, c, s, wl, wp);
expanded = format_expand(ft, fmt);
-/* $OpenBSD: names.c,v 1.39 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: names.c,v 1.40 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
const char *fmt;
char *name;
- ft = format_create(NULL, FORMAT_WINDOW|w->id, 0);
+ ft = format_create(NULL, NULL, FORMAT_WINDOW|w->id, 0);
format_defaults_window(ft, w);
format_defaults_pane(ft, w->active);
-/* $OpenBSD: screen-redraw.c,v 1.45 2017/04/05 10:49:46 nicm Exp $ */
+/* $OpenBSD: screen-redraw.c,v 1.46 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
fmt = options_get_string(w->options, "pane-border-format");
- ft = format_create(NULL, FORMAT_PANE|wp->id, 0);
+ ft = format_create(c, NULL, FORMAT_PANE|wp->id, 0);
format_defaults(ft, c, NULL, NULL, wp);
memcpy(&old, &wp->status_screen, sizeof old);
-/* $OpenBSD: server-client.c,v 1.227 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.228 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
free(c->prompt_string);
free(c->prompt_buffer);
+ format_lost_client(c);
environ_free(c->environ);
proc_remove_peer(c->peer);
template = options_get_string(s->options, "set-titles-string");
- ft = format_create(NULL, FORMAT_NONE, 0);
+ ft = format_create(c, NULL, FORMAT_NONE, 0);
format_defaults(ft, c, NULL, NULL, NULL);
title = format_expand_time(ft, template, time(NULL));
-/* $OpenBSD: status.c,v 1.163 2017/04/22 12:55:06 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.164 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
else
tag = FORMAT_NONE;
if (c->flags & CLIENT_STATUSFORCE)
- ft = format_create(NULL, tag, FORMAT_STATUS|FORMAT_FORCE);
+ ft = format_create(c, NULL, tag, FORMAT_STATUS|FORMAT_FORCE);
else
- ft = format_create(NULL, tag, FORMAT_STATUS);
+ ft = format_create(c, NULL, tag, FORMAT_STATUS);
format_defaults(ft, c, NULL, wl, NULL);
expanded = format_expand_time(ft, fmt, t);
time_t t;
char *tmp;
- ft = format_create(NULL, FORMAT_NONE, 0);
+ ft = format_create(c, NULL, FORMAT_NONE, 0);
format_defaults(ft, c, NULL, NULL, NULL);
t = time(NULL);
time_t t;
char *tmp;
- ft = format_create(NULL, FORMAT_NONE, 0);
+ ft = format_create(c, NULL, FORMAT_NONE, 0);
format_defaults(ft, c, NULL, NULL, NULL);
t = time(NULL);
-/* $OpenBSD: tmux.h,v 1.755 2017/04/28 19:13:55 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.756 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
struct cmdq_item;
struct cmdq_list;
struct environ;
+struct format_job_tree;
struct input_ctx;
struct mode_key_cmdstr;
struct mouse_event;
struct timeval activity_time;
struct environ *environ;
+ struct format_job_tree *jobs;
char *title;
const char *cwd;
#define FORMAT_PANE 0x80000000U
#define FORMAT_WINDOW 0x40000000U
struct format_tree;
-struct format_tree *format_create(struct cmdq_item *, int, int);
+struct format_tree *format_create(struct client *, struct cmdq_item *, int,
+ int);
void format_free(struct format_tree *);
void printflike(3, 4) format_add(struct format_tree *, const char *,
const char *, ...);
struct window_pane *);
void format_defaults_paste_buffer(struct format_tree *,
struct paste_buffer *);
+void format_lost_client(struct client *);
/* hooks.c */
struct hook;
-/* $OpenBSD: window-choose.c,v 1.89 2017/04/28 19:13:55 nicm Exp $ */
+/* $OpenBSD: window-choose.c,v 1.90 2017/05/01 12:20:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
wcd = xmalloc(sizeof *wcd);
wcd->type = type;
- wcd->ft = format_create(NULL, FORMAT_NONE, 0);
+ wcd->ft = format_create(c, NULL, FORMAT_NONE, 0);
wcd->ft_template = NULL;
wcd->command = NULL;