summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2017-04-28 19:13:55 +0000
committernicm <nicm@openbsd.org>2017-04-28 19:13:55 +0000
commit54279ec33d175bafb3360e7680f4f4770a7d2b06 (patch)
treefbebf0dbe4cefa487331f3fb26cd8f8bb01cd11e
parentRemove a reference from the right window when removing from a winlink's (diff)
downloadwireguard-openbsd-54279ec33d175bafb3360e7680f4f4770a7d2b06.tar.xz
wireguard-openbsd-54279ec33d175bafb3360e7680f4f4770a7d2b06.zip
Log what is happening with window and session reference counts much more
obviously.
-rw-r--r--usr.bin/tmux/alerts.c6
-rw-r--r--usr.bin/tmux/notify.c16
-rw-r--r--usr.bin/tmux/session.c18
-rw-r--r--usr.bin/tmux/tmux.h8
-rw-r--r--usr.bin/tmux/window-choose.c6
-rw-r--r--usr.bin/tmux/window.c24
6 files changed, 47 insertions, 31 deletions
diff --git a/usr.bin/tmux/alerts.c b/usr.bin/tmux/alerts.c
index da4bec99617..39a538e6044 100644
--- a/usr.bin/tmux/alerts.c
+++ b/usr.bin/tmux/alerts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: alerts.c,v 1.18 2017/04/28 19:10:48 nicm Exp $ */
+/* $OpenBSD: alerts.c,v 1.19 2017/04/28 19:13:55 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -64,7 +64,7 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
TAILQ_REMOVE(&alerts_list, w, alerts_entry);
w->flags &= ~WINDOW_ALERTFLAGS;
- window_remove_ref(w);
+ window_remove_ref(w, __func__);
}
alerts_fired = 0;
}
@@ -148,7 +148,7 @@ alerts_queue(struct window *w, int flags)
if (!w->alerts_queued) {
w->alerts_queued = 1;
TAILQ_INSERT_TAIL(&alerts_list, w, alerts_entry);
- w->references++;
+ window_add_ref(w, __func__);
}
if (!alerts_fired) {
diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c
index ab4e51b55c0..dd559092fdb 100644
--- a/usr.bin/tmux/notify.c
+++ b/usr.bin/tmux/notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notify.c,v 1.22 2017/04/21 20:26:34 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.23 2017/04/28 19:13:55 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
@@ -101,12 +101,12 @@ notify_callback(struct cmdq_item *item, void *data)
if (ne->client != NULL)
server_client_unref(ne->client);
if (ne->session != NULL)
- session_unref(ne->session);
+ session_remove_ref(ne->session, __func__);
if (ne->window != NULL)
- window_remove_ref(ne->window);
+ window_remove_ref(ne->window, __func__);
if (ne->fs.s != NULL)
- session_unref(ne->fs.s);
+ session_remove_ref(ne->fs.s, __func__);
free((void *)ne->name);
free(ne);
@@ -136,13 +136,13 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
if (c != NULL)
c->references++;
if (s != NULL)
- s->references++;
+ session_add_ref(s, __func__);
if (w != NULL)
- w->references++;
+ window_add_ref(w, __func__);
cmd_find_copy_state(&ne->fs, fs);
- if (ne->fs.s != NULL)
- ne->fs.s->references++; /* cmd_find_valid_state need session */
+ if (ne->fs.s != NULL) /* cmd_find_valid_state needs session */
+ session_add_ref(ne->fs.s, __func__);
new_item = cmdq_get_callback(notify_callback, ne);
cmdq_append(NULL, new_item);
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index ae52de4fdbb..456f13a2364 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.74 2017/04/25 15:35:10 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.75 2017/04/28 19:13:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -189,13 +189,21 @@ session_create(const char *prefix, const char *name, int argc, char **argv,
return (s);
}
-/* Remove a reference from a session. */
+/* Add a reference to a session. */
void
-session_unref(struct session *s)
+session_add_ref(struct session *s, const char *from)
{
- log_debug("session %s has %d references", s->name, s->references);
+ s->references++;
+ log_debug("%s: %s %s, now %d", __func__, s->name, from, s->references);
+}
+/* Remove a reference from a session. */
+void
+session_remove_ref(struct session *s, const char *from)
+{
s->references--;
+ log_debug("%s: %s %s, now %d", __func__, s->name, from, s->references);
+
if (s->references == 0)
event_once(-1, EV_TIMEOUT, session_free, s, NULL);
}
@@ -248,7 +256,7 @@ session_destroy(struct session *s)
free((void *)s->cwd);
- session_unref(s);
+ session_remove_ref(s, __func__);
}
/* Check a session name is valid: not empty and no colons or periods. */
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 74076d605da..d5aef5774cf 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.754 2017/04/25 18:30:29 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.755 2017/04/28 19:13:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2112,7 +2112,8 @@ struct window_pane *window_pane_find_down(struct window_pane *);
struct window_pane *window_pane_find_left(struct window_pane *);
struct window_pane *window_pane_find_right(struct window_pane *);
void window_set_name(struct window *, const char *);
-void window_remove_ref(struct window *);
+void window_add_ref(struct window *, const char *);
+void window_remove_ref(struct window *, const char *);
void winlink_clear_flags(struct winlink *);
int winlink_shuffle_up(struct session *, struct winlink *);
@@ -2226,7 +2227,8 @@ struct session *session_create(const char *, const char *, int, char **,
const char *, const char *, struct environ *,
struct termios *, int, u_int, u_int, char **);
void session_destroy(struct session *);
-void session_unref(struct session *);
+void session_add_ref(struct session *, const char *);
+void session_remove_ref(struct session *, const char *);
int session_check_name(const char *);
void session_update_activity(struct session *, struct timeval *);
struct session *session_next_session(struct session *);
diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c
index 76afe3f0c78..f157ccf30e7 100644
--- a/usr.bin/tmux/window-choose.c
+++ b/usr.bin/tmux/window-choose.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-choose.c,v 1.88 2017/03/17 14:41:54 nicm Exp $ */
+/* $OpenBSD: window-choose.c,v 1.89 2017/04/28 19:13:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -225,10 +225,10 @@ static void
window_choose_data_free(struct window_choose_data *wcd)
{
server_client_unref(wcd->start_client);
- session_unref(wcd->start_session);
+ session_remove_ref(wcd->start_session, __func__);
if (wcd->tree_session != NULL)
- session_unref(wcd->tree_session);
+ session_remove_ref(wcd->tree_session, __func__);
free(wcd->ft_template);
format_free(wcd->ft);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 1c2bdd0a2ad..45edbde1c22 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.191 2017/04/28 19:12:15 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.192 2017/04/28 19:13:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -186,11 +186,11 @@ winlink_set_window(struct winlink *wl, struct window *w)
{
if (wl->window != NULL) {
TAILQ_REMOVE(&wl->window->winlinks, wl, wentry);
- window_remove_ref(wl->window);
+ window_remove_ref(wl->window, __func__);
}
TAILQ_INSERT_TAIL(&w->winlinks, wl, wentry);
wl->window = w;
- w->references++;
+ window_add_ref(w, __func__);
}
void
@@ -200,7 +200,7 @@ winlink_remove(struct winlinks *wwl, struct winlink *wl)
if (w != NULL) {
TAILQ_REMOVE(&w->winlinks, wl, wentry);
- window_remove_ref(w);
+ window_remove_ref(w, __func__);
}
RB_REMOVE(winlinks, wwl, wl);
@@ -361,8 +361,7 @@ window_create_spawn(const char *name, int argc, char **argv, const char *path,
static void
window_destroy(struct window *w)
{
- if (!TAILQ_EMPTY(&w->winlinks))
- fatalx("window destroyed with winlinks");
+ log_debug("window @%u destroyed (%d references)", w->id, w->references);
RB_REMOVE(windows, &windows, w);
@@ -387,11 +386,18 @@ window_destroy(struct window *w)
}
void
-window_remove_ref(struct window *w)
+window_add_ref(struct window *w, const char *from)
+{
+ w->references++;
+ log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references);
+}
+
+void
+window_remove_ref(struct window *w, const char *from)
{
- if (w->references == 0)
- fatal("bad reference count");
w->references--;
+ log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references);
+
if (w->references == 0)
window_destroy(w);
}