Blame SOURCES/0026-Prevent-hanging-in-SIGCHLD-handler.patch

90e381
From 1e65a0a15f819b8bf1b551bd84f71d0da1f5a00c Mon Sep 17 00:00:00 2001
90e381
From: Martin Sehnoutka <msehnout@redhat.com>
90e381
Date: Thu, 17 Nov 2016 13:02:27 +0100
90e381
Subject: [PATCH 26/59] Prevent hanging in SIGCHLD handler.
90e381
90e381
vsftpd can now handle pam_exec.so in pam.d config without hanging
90e381
in SIGCHLD handler.
90e381
---
90e381
 sysutil.c    |  4 ++--
90e381
 sysutil.h    |  2 +-
90e381
 twoprocess.c | 13 +++++++++++--
90e381
 3 files changed, 14 insertions(+), 5 deletions(-)
90e381
90e381
diff --git a/sysutil.c b/sysutil.c
90e381
index 6d7cb3f..099748f 100644
90e381
--- a/sysutil.c
90e381
+++ b/sysutil.c
90e381
@@ -608,13 +608,13 @@ vsf_sysutil_exit(int exit_code)
90e381
 }
90e381
 
90e381
 struct vsf_sysutil_wait_retval
90e381
-vsf_sysutil_wait(void)
90e381
+vsf_sysutil_wait(int hang)
90e381
 {
90e381
   struct vsf_sysutil_wait_retval retval;
90e381
   vsf_sysutil_memclr(&retval, sizeof(retval));
90e381
   while (1)
90e381
   {
90e381
-    int sys_ret = wait(&retval.exit_status);
90e381
+    int sys_ret = waitpid(-1, &retval.exit_status, hang ? 0 : WNOHANG);
90e381
     if (sys_ret < 0 && errno == EINTR)
90e381
     {
90e381
       vsf_sysutil_check_pending_actions(kVSFSysUtilUnknown, 0, 0);
90e381
diff --git a/sysutil.h b/sysutil.h
90e381
index c145bdf..13153cd 100644
90e381
--- a/sysutil.h
90e381
+++ b/sysutil.h
90e381
@@ -177,7 +177,7 @@ struct vsf_sysutil_wait_retval
90e381
   int PRIVATE_HANDS_OFF_syscall_retval;
90e381
   int PRIVATE_HANDS_OFF_exit_status;
90e381
 };
90e381
-struct vsf_sysutil_wait_retval vsf_sysutil_wait(void);
90e381
+struct vsf_sysutil_wait_retval vsf_sysutil_wait(int hang);
90e381
 int vsf_sysutil_wait_reap_one(void);
90e381
 int vsf_sysutil_wait_get_retval(
90e381
   const struct vsf_sysutil_wait_retval* p_waitret);
90e381
diff --git a/twoprocess.c b/twoprocess.c
90e381
index 33d84dc..b1891e7 100644
90e381
--- a/twoprocess.c
90e381
+++ b/twoprocess.c
90e381
@@ -47,8 +47,17 @@ static void
90e381
 handle_sigchld(void* duff)
90e381
 {
90e381
 
90e381
-  struct vsf_sysutil_wait_retval wait_retval = vsf_sysutil_wait();
90e381
+  struct vsf_sysutil_wait_retval wait_retval = vsf_sysutil_wait(0);
90e381
   (void) duff;
90e381
+  if (!vsf_sysutil_wait_get_exitcode(&wait_retval) &&
90e381
+      !vsf_sysutil_wait_get_retval(&wait_retval))
90e381
+    /* There was nobody to wait for, possibly caused by underlying library
90e381
+     * which created a new process through fork()/vfork() and already picked
90e381
+     * it up, e.g. by pam_exec.so or integrity check routines for libraries
90e381
+     * when FIPS mode is on (nss freebl), which can lead to calling prelink
90e381
+     * if the prelink package is installed.
90e381
+     */
90e381
+    return;
90e381
   /* Child died, so we'll do the same! Report it as an error unless the child
90e381
    * exited normally with zero exit code
90e381
    */
90e381
@@ -390,7 +399,7 @@ common_do_login(struct vsf_session* p_sess, const struct mystr* p_user_str,
90e381
   priv_sock_send_result(p_sess->parent_fd, PRIV_SOCK_RESULT_OK);
90e381
   if (!p_sess->control_use_ssl)
90e381
   {
90e381
-    (void) vsf_sysutil_wait();
90e381
+    (void) vsf_sysutil_wait(1);
90e381
   }
90e381
   else
90e381
   {
90e381
-- 
90e381
2.14.4
90e381