diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-10-20 21:00:22 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-10-20 21:00:22 +0200 |
commit | d6343020aafa86e6819d3d12aac46c4f009d65a0 (patch) | |
tree | e0eca3b1356f44ece02b2aeb1b277c343584b596 /src/core | |
parent | 8a389395b9e3b23640eb0226b63056f9998728d1 (diff) | |
download | weechat-d6343020aafa86e6819d3d12aac46c4f009d65a0.zip |
core: fix random timeouts when a lot of concurrent processes are launched with hook_process (closes #2033)
Diffstat (limited to 'src/core')
-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 |
4 files changed, 19 insertions, 11 deletions
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); |