Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Oct 2009 20:19:16 +0000 (UTC)
From:      Roman Divacky <rdivacky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r197812 - head/contrib/tcsh
Message-ID:  <200910062019.n96KJG5Q062846@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rdivacky
Date: Tue Oct  6 20:19:16 2009
New Revision: 197812
URL: http://svn.freebsd.org/changeset/base/197812

Log:
  Fix tcsh losing history when tcsh terminates because the pty beneath it
  is closed.
  
  Diagnosed by Ted Anderson:
  
  New signal queuing logic was introduced in 6.15 and allows the signal handlers
  to be run explicitly by calling handle_pending_signals, instead of
  immediately when the signal is delivered.  This function is called at
  various places, typically when receiving a EINTR from a slow system call
  such as read or write.  In the pty exit case, it was called from xwrite,
  called from flush, while printing the "exit" message after receiving EOF
  when reading from the pty (note that the read did not return EINTR but
  zero bytes, indicating EOF).  The SIGHUP handler, phup(), called
  rechist, which opened the history file and began writing the merged
  history to it.  This process invoked flush recursively to actually write
  the data.  In this case, however, the flush noticed it was being called
  recursively and decided fail by calling stderror.
  
  My conclusion was that the signal was being handled at a bad time.  But
  whether to fix flush not to care about the recursive call, or to handle
  the signal some other time and when to handle it, was unclear to me.
  However, by adding an extra call to handle_pending_signals, just after
  process() returns to main(), I was able to avoid the truncated history
  after network outages and similar failures.  I verified this fix in
  version 6.17.
  
  Approved by:	ed (mentor)
  MFC after:	1 week

Modified:
  head/contrib/tcsh/sh.c

Modified: head/contrib/tcsh/sh.c
==============================================================================
--- head/contrib/tcsh/sh.c	Tue Oct  6 19:44:44 2009	(r197811)
+++ head/contrib/tcsh/sh.c	Tue Oct  6 20:19:16 2009	(r197812)
@@ -1291,6 +1291,8 @@ main(int argc, char **argv)
     /*
      * Mop-up.
      */
+    /* Take care of these (especially HUP) here instead of inside flush. */
+    handle_pending_signals();
     if (intty) {
 	if (loginsh) {
 	    xprintf("logout\n");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200910062019.n96KJG5Q062846>