pgpool2.git / summary / log / commit / refs
commit a5e2e0411dc3ef91aafc8f4c5e1d7369e7eb3b46
Author: Tatsuo Ishii <ishii@sraoss.co.jp>
Date: Fri Apr 01 10:54:49 2022 +0000
Prevent hang in terminate_all_childrens().
waitpid() was used in the function without WNOHANG was being set.
This could cause hang in waitpic().
Also fix typo. Rename terminate_all_childrens to terminate_all_children.
src/main/pgpool_main.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c
index 861d9a27d..95998ed07 100644
--- a/src/main/pgpool_main.c
+++ b/src/main/pgpool_main.c
@@ -171,7 +171,7 @@ static int trigger_failover_command(int node, const char *command_line,
int old_main_node, int new_main_node, int old_primary);
static int find_primary_node(void);
static int find_primary_node_repeatedly(void);
-static void terminate_all_childrens(int sig);
+static void terminate_all_children(int sig);
static void system_will_go_down(int code, Datum arg);
static char *process_name_from_pid(pid_t pid);
static void sync_backend_from_watchdog(void);
@@ -998,12 +998,11 @@ create_unix_domain_socket(struct sockaddr_un un_addr_tmp)
}
/*
- * sends the kill signal to all Pgpool children except to
- * the pgpool_logger child
- * wait for the termination of all killed children before returning.
+ * Send the kill signal to all Pgpool children except to the pgpool_logger
+ * child and wait for the termination of all killed children before returning.
*/
static void
-terminate_all_childrens(int sig)
+terminate_all_children(int sig)
{
pid_t wpid;
int i;
@@ -1084,7 +1083,7 @@ terminate_all_childrens(int sig)
{
int ret_pid;
- wpid = waitpid(-1, &ret_pid, 0);
+ wpid = waitpid(-1, &ret_pid, WNOHANG);
if (wpid > 0)
terminated_count++;
} while (terminated_count < killed_count &&
@@ -1135,7 +1134,7 @@ static RETSIGTYPE exit_handler(int sig)
ereport(LOG,
(errmsg("terminating all child processes")));
- terminate_all_childrens(sig);
+ terminate_all_children(sig);
/*
* Send signal to follow child process and it's children.
@@ -3251,7 +3250,7 @@ system_will_go_down(int code, Datum arg)
{
ereport(LOG,
(errmsg("shutting down")));
- terminate_all_childrens(SIGINT);
+ terminate_all_children(SIGINT);
}
/*
[parent: e37da6e7d0ef]