summaryrefslogtreecommitdiff
path: root/src/core/wee-hook.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-10-20 21:00:22 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-10-20 21:00:22 +0200
commitd6343020aafa86e6819d3d12aac46c4f009d65a0 (patch)
treee0eca3b1356f44ece02b2aeb1b277c343584b596 /src/core/wee-hook.c
parent8a389395b9e3b23640eb0226b63056f9998728d1 (diff)
downloadweechat-d6343020aafa86e6819d3d12aac46c4f009d65a0.zip
core: fix random timeouts when a lot of concurrent processes are launched with hook_process (closes #2033)
Diffstat (limited to 'src/core/wee-hook.c')
-rw-r--r--src/core/wee-hook.c24
1 files changed, 16 insertions, 8 deletions
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);
+ }
}
/*