The branch, hooks has been updated
       via  801f36c25dae91f64554f5e4f1bc22bfa731b5b6 (commit)
       via  92cec78b4b2f72b6dbed075f89ebb7179fa00b63 (commit)
      from  b2bfe4a2d482ca7c6eb737493c9e0f3d02eb54b1 (commit)

- Log -----------------------------------------------------------------
commit 801f36c25dae91f64554f5e4f1bc22bfa731b5b6
Author: Thomas Adam <tho...@xteddy.org>
Commit: Thomas Adam <tho...@xteddy.org>

    Don't run notifys unconditionally
    
    Don't always run notifications; only do so on those clients accepting
    CONTROL.
---
 notify.c |   13 +++++++++++++
 tmux.h   |    3 +++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/notify.c b/notify.c
index ed6c67d..759ff34 100644
--- a/notify.c
+++ b/notify.c
@@ -134,10 +134,23 @@ void
 notify_drain(void)
 {
        struct notify_entry     *ne, *ne1;
+       struct client           *c = NULL, *cloop = NULL;
+       u_int                    i;
 
        if (notify_disabled)
                return;
 
+       /* If no clients want notifications, stop here! */
+       for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+               cloop = ARRAY_ITEM(&clients, i);
+               if (!CONTROL_SHOULD_NOTIFY_CLIENT(cloop))
+                       continue;
+               c = cloop;
+       }
+
+       if (c == NULL)
+               return;
+
        TAILQ_FOREACH_SAFE(ne, &notify_queue, entry, ne1) {
                switch (ne->type) {
                case NOTIFY_WINDOW_LAYOUT_CHANGED:
diff --git a/tmux.h b/tmux.h
index 062df70..1707e1e 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1607,6 +1607,9 @@ void      mode_key_init(struct mode_key_data *, struct 
mode_key_tree *);
 enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int, const char **);
 
 /* notify.c */
+#define CONTROL_SHOULD_NOTIFY_CLIENT(c) \
+       ((c) != NULL && ((c)->flags & CLIENT_CONTROL))
+
 void   notify_enable(void);
 void   notify_disable(void);
 void   notify_input(struct window_pane *, struct evbuffer *);


commit 92cec78b4b2f72b6dbed075f89ebb7179fa00b63
Author: Thomas Adam <tho...@xteddy.org>
Commit: Thomas Adam <tho...@xteddy.org>

    notify:  Avoid double-free
    
    Before making notify support hooks, notify_drain() was responsible solely
    for free()ing the notify_event.  This was fine, since there was only ever a
    single point of entry for it.
    
    But in making notify support hooks, running the commands via
    cmdq_hooks_run() now means the free() happens twice:  once from
    notify_drain() normally, and the other as a result of finish off running
    cmdq_run().
    
    To stop this happening, add a flag to the notify_event structure indicating
    when it needs to be free()d and only do it then.
---
 notify.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/notify.c b/notify.c
index 6968a60..ed6c67d 100644
--- a/notify.c
+++ b/notify.c
@@ -55,6 +55,7 @@ struct notify_entry {
        struct client           *client;
        struct session          *session;
        struct window           *window;
+       int                      do_free;
 
        TAILQ_ENTRY(notify_entry) entry;
 };
@@ -64,16 +65,16 @@ int notify_disabled;
 void   notify_drain(void);
 void   notify_add(enum notify_type, struct client *, struct session *,
            struct window *);
-void   notify_run_hook(const struct notify_entry *);
+void   notify_run_hook(struct notify_entry *);
 
 void
-notify_run_hook(const struct notify_entry *ne)
+notify_run_hook(struct notify_entry *ne)
 {
        struct hooks    *hooks;
        const char      *hook_name = NULL;
        u_int            i;
 
-       for(i = 0; i < nitems(notify_hooks_info); i++) {
+       for (i = 0; i < nitems(notify_hooks_info); i++) {
                if (notify_hooks_info[i].type == ne->type) {
                        hook_name = notify_hooks_info[i].hook_name;
                        break;
@@ -86,6 +87,7 @@ notify_run_hook(const struct notify_entry *ne)
        hooks = ne->session != NULL ? &ne->session->hooks : &global_hooks;
 
        /* Run the hooked commands */
+       ne->do_free = 1;
        cmdq_hooks_run(hooks, NULL, hook_name, NULL);
 }
 
@@ -117,6 +119,7 @@ notify_add(enum notify_type type, struct client *c, struct 
session *s,
        ne->client = c;
        ne->session = s;
        ne->window = w;
+       ne->do_free = 0;
        TAILQ_INSERT_TAIL(&notify_queue, ne, entry);
 
        if (c != NULL)
@@ -171,9 +174,10 @@ notify_drain(void)
                        window_remove_ref(ne->window);
 
                TAILQ_REMOVE(&notify_queue, ne, entry);
-               notify_run_hook(ne);
 
-               free(ne);
+               if (ne->do_free)
+                       free(ne);
+               notify_run_hook(ne);
        }
 }
 


-----------------------------------------------------------------------

Summary of changes:
 notify.c |   27 ++++++++++++++++++++++-----
 tmux.h   |    3 +++
 2 files changed, 25 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to