diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/core/hook/wee-hook-connect.c | 2 | ||||
-rw-r--r-- | src/core/hook/wee-hook-process.c | 2 | ||||
-rw-r--r-- | src/core/wee-hook.c | 24 | ||||
-rw-r--r-- | src/core/wee-hook.h | 2 |
5 files changed, 20 insertions, 11 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 2df687836..a4865a1e5 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -20,6 +20,7 @@ New features:: Bug fixes:: + * core: fix random timeouts when a lot of concurrent processes are launched with hook_process (issue #2033) * irc: revert compute of nick colors to case sensitive way, deprecate again infos "irc_nick_color" and "irc_nick_color_name" (issue #194, issue #2032) Build:: diff --git a/src/core/hook/wee-hook-connect.c b/src/core/hook/wee-hook-connect.c index d03fe4bec..545fdcb2d 100644 --- a/src/core/hook/wee-hook-connect.c +++ b/src/core/hook/wee-hook-connect.c @@ -270,7 +270,7 @@ hook_connect_free_data (struct t_hook *hook) if (HOOK_CONNECT(hook, child_pid) > 0) { kill (HOOK_CONNECT(hook, child_pid), SIGKILL); - hook_schedule_clean_children (); + hook_schedule_clean_process (HOOK_CONNECT(hook, child_pid)); HOOK_CONNECT(hook, child_pid) = 0; } if (HOOK_CONNECT(hook, child_read) != -1) diff --git a/src/core/hook/wee-hook-process.c b/src/core/hook/wee-hook-process.c index 21b889fed..ccfb5f47d 100644 --- a/src/core/hook/wee-hook-process.c +++ b/src/core/hook/wee-hook-process.c @@ -862,7 +862,7 @@ hook_process_free_data (struct t_hook *hook) if (HOOK_PROCESS(hook, child_pid) > 0) { kill (HOOK_PROCESS(hook, child_pid), SIGKILL); - hook_schedule_clean_children (); + hook_schedule_clean_process (HOOK_PROCESS(hook, child_pid)); HOOK_PROCESS(hook, child_pid) = 0; } if (HOOK_PROCESS(hook, child_read[HOOK_PROCESS_STDIN]) != -1) diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index d0c120640..d23d70221 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -28,6 +28,7 @@ #include <string.h> #include <time.h> #include <sys/socket.h> +#include <sys/wait.h> #include <errno.h> #include "weechat.h" @@ -38,7 +39,6 @@ #include "wee-log.h" #include "wee-signal.h" #include "wee-string.h" -#include "wee-sys.h" #include "wee-util.h" #include "../gui/gui-chat.h" #include "../plugins/plugin.h" @@ -629,20 +629,19 @@ hook_set (struct t_hook *hook, const char *property, const char *value) } /* - * Callback used to clean all children (forked processes) by acknowledging - * their end. + * Callback used to clean a process (forked processes) by acknowledging its end. */ int -hook_timer_clean_children_cb (const void *pointer, void *data, - int remaining_calls) +hook_timer_clean_process_cb (const void *pointer, void *data, + int remaining_calls) { /* make C compiler happy */ (void) pointer; (void) data; (void) remaining_calls; - sys_waitpid (); + waitpid (*((pid_t *)data), NULL, WNOHANG); return WEECHAT_RC_OK; } @@ -652,9 +651,18 @@ hook_timer_clean_children_cb (const void *pointer, void *data, */ void -hook_schedule_clean_children () +hook_schedule_clean_process (pid_t pid) { - hook_timer (NULL, 100, 0, 1, &hook_timer_clean_children_cb, NULL, NULL); + pid_t *temp_pid; + + /* temp_pid will be freed when the timer is removed */ + temp_pid = malloc (sizeof (*temp_pid)); + if (temp_pid) + { + *temp_pid = pid; + hook_timer (NULL, 100, 0, 1, + &hook_timer_clean_process_cb, NULL, temp_pid); + } } /* diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 8ae79a3c6..b4163da18 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -146,7 +146,7 @@ extern void hook_callback_end (struct t_hook *hook, extern char *hook_get_description (struct t_hook *hook); extern void hook_set (struct t_hook *hook, const char *property, const char *value); -extern void hook_schedule_clean_children (); +extern void hook_schedule_clean_process (pid_t pid); extern void unhook (struct t_hook *hook); extern void unhook_all_plugin (struct t_weechat_plugin *plugin, const char *subplugin); |