diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2014-03-07 09:22:21 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2014-03-07 09:22:21 +0100 |
commit | 7a191c2de18c6e66285b85ea293fc99047f1d9da (patch) | |
tree | c6df1439a1591a55a16ddcfacc73aa487fed41c6 /src/plugins/relay | |
parent | c87cd88e726c875aee4c8f81a588d23cb182508c (diff) | |
download | weechat-7a191c2de18c6e66285b85ea293fc99047f1d9da.zip |
relay: fix crash on /upgrade received from a client (weechat protocol)
Some commands like /upgrade sent by relay client can cause problems, because
they were executed immediately (while relay code is running). The /upgrade
command unloads all plugins, so the result is unpredictable (it can cause a
crash).
This commit adds a timer (1 millisecond) to delay the execution of command
after we go back in the WeeChat main loop.
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/weechat/relay-weechat-protocol.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/plugins/relay/weechat/relay-weechat-protocol.c b/src/plugins/relay/weechat/relay-weechat-protocol.c index 7820ecab0..23e780bd2 100644 --- a/src/plugins/relay/weechat/relay-weechat-protocol.c +++ b/src/plugins/relay/weechat/relay-weechat-protocol.c @@ -333,6 +333,43 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(nicklist) } /* + * Timer callback for input command. + */ + +int +relay_weechat_protocol_input_timer_cb (void *data, + int remaining_calls) +{ + char **timer_args; + int i; + struct t_gui_buffer *ptr_buffer; + + /* make C compiler happy */ + (void) remaining_calls; + + timer_args = (char **)data; + + if (!timer_args) + return WEECHAT_RC_ERROR; + + if (timer_args[0] && timer_args[1] && timer_args[2]) + { + ptr_buffer = weechat_buffer_search (timer_args[0], timer_args[1]); + if (ptr_buffer) + weechat_command (ptr_buffer, timer_args[2]); + } + + for (i = 0; i < 3; i++) + { + if (timer_args[i]) + free (timer_args[i]); + } + free (timer_args); + + return WEECHAT_RC_OK; +} + +/* * Callback for command "input" (from client). * * Message looks like: @@ -344,7 +381,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(nicklist) RELAY_WEECHAT_PROTOCOL_CALLBACK(input) { struct t_gui_buffer *ptr_buffer; - char *pos; + char *pos, **timer_args; RELAY_WEECHAT_PROTOCOL_MIN_ARGS(2); @@ -353,7 +390,25 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(input) { pos = strchr (argv_eol[0], ' '); if (pos) - weechat_command (ptr_buffer, pos + 1); + { + /* + * use a timer to execute the command after we go back in the + * WeeChat main loop (some commands like /upgrade executed now can + * cause a crash) + */ + timer_args = malloc (3 * sizeof (*timer_args)); + if (timer_args) + { + timer_args[0] = strdup (weechat_buffer_get_string (ptr_buffer, + "plugin")); + timer_args[1] = strdup (weechat_buffer_get_string (ptr_buffer, + "name")); + timer_args[2] = strdup (pos + 1); + weechat_hook_timer (1, 0, 1, + &relay_weechat_protocol_input_timer_cb, + timer_args); + } + } } return WEECHAT_RC_OK; |