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

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