--- ./src/os_unix.c.orig	2020-06-02 01:46:24 +0000
+++ ./src/os_unix.c	2020-06-02 01:52:23 +0000
@@ -933,6 +933,39 @@
 }
 #endif
 
+    static int
+dt_is_blockable(int sigarg)
+{
+# ifdef SIGHUP
+       if (sigarg == SIGHUP) return 1;
+# endif
+# ifdef SIGQUIT
+       if (sigarg == SIGQUIT) return 1;
+# endif
+# ifdef SIGTERM
+       if (sigarg == SIGTERM) return 1;
+# endif
+# ifdef SIGPWR
+       if (sigarg == SIGPWR) return 1;
+# endif
+# ifdef SIGUSR1
+       if (sigarg == SIGUSR1) return 1;
+# endif
+# ifdef SIGUSR2
+       if (sigarg == SIGUSR2) return 1;
+# endif
+       return 0;
+}
+
+/* Count the number of times a signal was blocked.
+ * If we block signals continuously without ever entering the core
+ * deathtrap handler, then vim is likely disassociated from a terminal and
+ * repeatedly blocking SIGHUP.  Give up after dt_max_block times.
+ */
+int dt_blocked = 0;
+int dt_max_block = 100;
+
+
 /*
  * This function handles deadly signals.
  * It tries to preserve any swap files and exit properly.
@@ -980,33 +1013,18 @@
     // here.  This avoids that a non-reentrant function is interrupted, e.g.,
     // free().  Calling free() again may then cause a crash.
     if (entered == 0
-	    && (0
-# ifdef SIGHUP
-		|| sigarg == SIGHUP
-# endif
-# ifdef SIGQUIT
-		|| sigarg == SIGQUIT
-# endif
-# ifdef SIGTERM
-		|| sigarg == SIGTERM
-# endif
-# ifdef SIGPWR
-		|| sigarg == SIGPWR
-# endif
-# ifdef SIGUSR1
-		|| sigarg == SIGUSR1
-# endif
-# ifdef SIGUSR2
-		|| sigarg == SIGUSR2
-# endif
-		)
-	    && !vim_handle_signal(sigarg))
+           && dt_is_blockable(sigarg)
+           && !vim_handle_signal(sigarg)
+           && ((++dt_blocked) < dt_max_block))
 	SIGRETURN;
 #endif
 
     // Remember how often we have been called.
     ++entered;
 
+    /* Reset the blocked count. */
+    dt_blocked = 0;
+
     // Executing autocommands is likely to use more stack space than we have
     // available in the signal stack.
     block_autocmds();
@@ -1237,6 +1255,9 @@
     void
 mch_suspend(void)
 {
+       /* ... allow signals to kill us. */
+       (void)vim_handle_signal(SIGNAL_UNBLOCK);
+
     // BeOS does have SIGTSTP, but it doesn't work.
 #if defined(SIGTSTP) && !defined(__BEOS__)
     in_mch_suspend = TRUE;
@@ -1277,6 +1298,8 @@
 #else
     suspend_shell();
 #endif
+       /* block SIGHUP et al. */
+       (void)vim_handle_signal(SIGNAL_BLOCK);
 }
 
     void
