For those who asked, here are excerpts from emails I've sent
to Debian regarding the CTWM crashes that I've repaired.

 #################################################################

A brief sketch of typical usage and failure mode:

   I am running CTWM with eight workspaces (most are populated)
   and switching workspaces fairly often.  The most active
   X apps are xterm, Firefox, exmh and mahjongg.  I typically
   have several Firefox windows open, each of which has multiple
   tabs active, sometimes dozens.  Failure seemed most often
   to happen immediately after I switched workspaces to one
   containing a Firefox window with a *LOT* of tabs open.
   I've not seen it even once since this I made this fix.

   Note that I was usually able to recover my entire X session
   and continue without harm if I could manage to launch a
   new instance of CTWM from the console or an SSH session.
   Until I patched my CTWM I actually had a shell loop right
   inside my .xsession file that would automatically relaunch
   CTWM when it crashed, so I was able to live with it for
   several years before finally getting fed up and fixing it!

 #################################################################

Here's a bit of GDB output to illustrate the specific
fauilt that was constantly occurring before I fixed it:

 Program received signal SIGSEGV, Segmentation fault.
 0x0805f131 in PlaceOntop (ontop=8, where=0) at menus.c:3756
 3756        for (t = Scr->TwmRoot.next; t != NULL; t = t->next) {
 (gdb) where
 #0  0x0805f131 in PlaceOntop (ontop=8, where=0) at menus.c:3756
 #1  0x0805f24b in RaiseWindow (tmp_win=0x83343a0) at menus.c:3787
 #2  0x0806ab10 in AutoRaiseWindow (tmp=0x83343a0) at events.c:218
 #3  0x0807096f in HandleEvents () at events.c:547
 #4  0x0804e3a7 in main (argc=2, argv=0xbff491a4, environ=0xbff491b0)
     at ctwm.c:1027
 (gdb) print Scr
 $2 = (ScreenInfo *) 0x0

 #################################################################

To: Debian Bug Tracking System <[email protected]>
Date: Tue, 06 Mar 2012 15:42:25 -0500
Subject: debianBug#662860 - ctwm: SIGSEGV when changing workspaces

 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=662860

Package: ctwm
Version: 3.7-3.2
Severity: important
Tags: upstream patch

Dear Maintainer,

I'm a longtime CTWM user who finally got tired of the random
crashes that occur, typically when I'm switching workspaces.
I can sometimes go for a month without seeing them and sometimes
it happens several times a day.  I've analyzed this to the point
where I can see that code in DispatchEvent() is occasionally
leaving the global Scr pointer NULL which causes a SIGSEGV on
our next pass through the loop in HandleEvents().

I've provided a patch that adds a few lines of defensive code
which seems to have improved the situation, though I have not
analyzed the root cause, which appears to be that, for unknown
reasons, either XFindContext() or FindScreenInfo() seem to be
unable to return the answer expected of them.

  --Michael O'Donnell

BEGIN PATCH:
--- events.c.b0rken     2012-03-06 15:10:42.093677349 -0500
+++ events.c    2012-03-06 15:19:52.369161662 -0500
@@ -435,21 +435,25 @@
  */
 Bool DispatchEvent2 (void)
 {
     Window w = Event.xany.window;
     StashEventTime (&Event);
+    ScreenInfo *lastScr = Scr;   /* XXX_MIKE - assume Scr OK on entry... */

     if (XFindContext (dpy, w, TwmContext, (XPointer *) &Tmp_win) == XCNOENT)
       Tmp_win = NULL;

     if (XFindContext (dpy, w, ScreenContext, (XPointer *)&Scr) == XCNOENT) {
        Scr = FindScreenInfo (WindowOfEvent (&Event));
     }

     dumpevent(&Event);

-    if (!Scr) return False;
+    if (!Scr) {
+        Scr = lastScr;           /* XXX_MIKE - try not to leave Scr NULL */
+        return False;
+    }
     if (Scr->Root != Scr->RealRoot) FixRootEvent (&Event);

 #ifdef SOUNDS
     play_sound(Event.type);
 #endif
@@ -473,21 +477,25 @@
  */
 Bool DispatchEvent (void)
 {
     Window w = Event.xany.window;
     StashEventTime (&Event);
+    ScreenInfo *lastScr = Scr;   /* XXX_MIKE - assume Scr OK on entry... */

     if (XFindContext (dpy, w, TwmContext, (XPointer *) &Tmp_win) == XCNOENT)
       Tmp_win = NULL;

     if (XFindContext (dpy, w, ScreenContext, (XPointer *)&Scr) == XCNOENT) {
        Scr = FindScreenInfo (WindowOfEvent (&Event));
     }

     dumpevent(&Event);

-    if (!Scr) return False;
+    if (!Scr) {
+        Scr = lastScr;           /* XXX_MIKE - try not to leave Scr NULL */
+        return False;
+    }

     if (captive) {
       if ((Event.type == ConfigureNotify) && (Event.xconfigure.window == 
Scr->CaptiveRoot)) {
        ConfigureRootWindow (&Event);
        return (False);

END PATCH

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 3.1.0 (SMP w/2 CPU cores)
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash

Versions of packages ctwm depends on:
ii  libc6       2.13-26
ii  libice6     2:1.0.7-2
ii  libjpeg8    8d-1
ii  librplay3   3.3.2-14
ii  libsm6      2:1.2.0-2
ii  libx11-6    2:1.4.4-4
ii  libxext6    2:1.3.0-3
ii  libxmu6     2:1.1.0-3
ii  libxpm4     1:3.5.9-4
ii  libxt6      1:1.1.1-2
ii  m4          1.4.16-2
ii  x11-common  1:7.6+11

ctwm recommends no packages.

ctwm suggests no packages.

-- Configuration Files:
/etc/X11/ctwm/system.ctwmrc [Errno 2] No such file or directory: 
u'/etc/X11/ctwm/system.ctwmrc'

-- no debconf information

-- debsums errors found:
debsums: missing file /usr/bin/ctwm (from ctwm package)

  Note that the above mentioned debsums error for
  /usr/bin/ctwm is due to my having built and installed
  a private version from source during debug....

Reply via email to