On Tue, 11 Dec 2001, Jan Schaumann wrote:

> In which case the following simple patch should fix the problem
> (assuming BB _can_ catch SIGPIPE, and I don't see any reason why it
> shouldn't be able to):

It may also need a signal handler setup. (My patch is below.)

Here is the startx logging and a strace of blackbox without handler for
sigpipe during a Zap:

gettimeofday({1008114271, 635620}, NULL) = 0
gettimeofday({1008114271, 636016}, NULL) = 0
gettimeofday({1008114271, 636332}, NULL) = 0
gettimeofday({1008114271, 636611}, NULL) = 0
write(3, "$\0\1\0\f\0\7\0f\0\0\1\17\0\0\1\377\3\0\0\177\1\0\0\1\0"..., 768) = -1 EPIPE 
(Broken pipe)
--- SIGPIPE (Broken pipe) ---
+++ killed by SIGPIPE +++
[1]-  Broken pipe             bbkeys -t -w -no
xinit:  connection to X server lost.

waiting for X server to shut down 


And with signal handler:

gettimeofday({1008115580, 606875}, NULL) = 0
select(4, [3], NULL, NULL, {39, 928605}) = 1 (in [3], left {39, 930000})
gettimeofday({1008115580, 607641}, NULL) = 0
ioctl(3, FIONREAD, [0])                 = 0
select(4, [3], NULL, NULL, {0, 0})      = 1 (in [3], left {0, 0})
ioctl(3, FIONREAD, [0])                 = 0
read(3, "", 32)                         = 0
write(2, "X connection to :2.0 broken (exp"..., 65X connection to :2.0 broken 
(explicit kill or server shutdown).
) = 65
munmap(0x40016000, 9288)                = 0
_exit(1)                                = ?
[1]-  Broken pipe             bbkeys -t -w -no
xinit:  connection to X server lost.


Here's my patch:

diff -u blackbox-0.61.1/src/BaseDisplay.cc blackbox-0.61.1-sigpipe/src/BaseDisplay.cc
--- blackbox-0.61.1/src/BaseDisplay.cc  Thu Oct  5 14:05:40 2000
+++ blackbox-0.61.1-sigpipe/src/BaseDisplay.cc  Tue Dec 11 15:49:14 2001
@@ -244,6 +244,7 @@
   sigaction(SIGHUP, &action, NULL);
   sigaction(SIGUSR1, &action, NULL);
   sigaction(SIGUSR2, &action, NULL);
+  sigaction(SIGPIPE, &action, NULL); /* properly handle Zap */
 #else // !HAVE_SIGACTION
   signal(SIGSEGV, (RETSIGTYPE (*)(int)) signalhandler);
   signal(SIGFPE, (RETSIGTYPE (*)(int)) signalhandler);
@@ -251,6 +252,7 @@
   signal(SIGINT, (RETSIGTYPE (*)(int)) signalhandler);
   signal(SIGUSR1, (RETSIGTYPE (*)(int)) signalhandler);
   signal(SIGUSR2, (RETSIGTYPE (*)(int)) signalhandler);
+  signal(SIGPIPE, (RETSIGTYPE (*)(int)) signalhandler); /* Zap */
   signal(SIGHUP, (RETSIGTYPE (*)(int)) signalhandler);
   signal(SIGCHLD, (RETSIGTYPE (*)(int)) signalhandler);
 #endif // HAVE_SIGACTION
diff -u blackbox-0.61.1/src/blackbox.cc blackbox-0.61.1-sigpipe/src/blackbox.cc
--- blackbox-0.61.1/src/blackbox.cc     Sat Jun 24 22:56:48 2000
+++ blackbox-0.61.1-sigpipe/src/blackbox.cc     Tue Dec 11 15:52:08 2001
@@ -753,6 +753,7 @@
   case SIGFPE:
   case SIGINT:
   case SIGTERM:
+  case SIGPIPE:  /* Properly cleanup and exit if Zapped */
     shutdown();
 
   default:


  Jeremy C. Reed
  http://bsd.reedmedia.net/  -- BSD news and resources
  http://www.isp-faq.com/    -- find answers to your questions

Reply via email to