MINOR: threads/checks: Add a lock to protect the pid list used by external checks
diff --git a/src/checks.c b/src/checks.c
index ed99bb5..cf1c59e 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -35,6 +35,7 @@
#include <common/mini-clist.h>
#include <common/standard.h>
#include <common/time.h>
+#include <common/hathreads.h>
#include <types/global.h>
#include <types/dns.h>
@@ -1582,6 +1583,9 @@
static struct list pid_list = LIST_HEAD_INIT(pid_list);
static struct pool_head *pool2_pid_list;
+#ifdef USE_THREAD
+HA_SPINLOCK_T pid_list_lock;
+#endif
void block_sigchld(void)
{
@@ -1612,7 +1616,11 @@
elem->exited = 0;
check->curpid = elem;
LIST_INIT(&elem->list);
+
+ SPIN_LOCK(PID_LIST_LOCK, &pid_list_lock);
LIST_ADD(&pid_list, &elem->list);
+ SPIN_UNLOCK(PID_LIST_LOCK, &pid_list_lock);
+
return elem;
}
@@ -1623,7 +1631,10 @@
if (!elem)
return;
+ SPIN_LOCK(PID_LIST_LOCK, &pid_list_lock);
LIST_DEL(&elem->list);
+ SPIN_UNLOCK(PID_LIST_LOCK, &pid_list_lock);
+
if (!elem->exited)
kill(elem->pid, SIGTERM);
@@ -1637,15 +1648,17 @@
{
struct pid_list *elem;
+ SPIN_LOCK(PID_LIST_LOCK, &pid_list_lock);
list_for_each_entry(elem, &pid_list, list) {
if (elem->pid == pid) {
elem->t->expire = now_ms;
elem->status = status;
elem->exited = 1;
task_wakeup(elem->t, TASK_WOKEN_IO);
- return;
+ break;
}
}
+ SPIN_UNLOCK(PID_LIST_LOCK, &pid_list_lock);
}
static void sigchld_handler(struct sig_handler *sh)
@@ -1676,6 +1689,8 @@
return 1;
}
+ SPIN_INIT(&pid_list_lock);
+
return 0;
}