[3ddesktop-dev] segfault problem

3ddeskd says "Daemon started.  Run 3ddesk to activate." but the child
process actually segfaulted.


Here's the gdb backtrace of the segfault:

gdb ./3ddeskd
GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".

(gdb) set follow-fork-mode child
(gdb) run
Starting program: /home/seymour/3ddesktop-0.2.8/3ddeskd
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Attaching after fork to child process 12297.
Daemon started.  Run 3ddesk to activate.

Program received signal SIGSEGV, Segmentation fault.
[Switching to process 12297]
0x40295143 in glXChannelRectSyncSGIX () from
/usr/lib/opengl/nvidia/lib/libGL.so.1
(gdb) bt
#0  0x40295143 in glXChannelRectSyncSGIX () from
/usr/lib/opengl/nvidia/lib/libGL.so.1
#1  0x0807f9b8 in ?? ()
#2  0x0805d6bf in _IO_stdin_used ()
#3  0x08061880 in faces ()
#4  0x4028e677 in glXCreateContext () from /usr/lib/opengl/nvidia/lib/libGL.so.1
(gdb)



Some Xorg log details (let me know if you want to know anything not
listed here or the entire log, for that matter - a little too large to
paste here):

X Window System Version 6.8.0
Current Operating System: Linux seymour 2.6.7-gentoo-r11 #6 SMP Fri
Sep 10 10:36:32 CDT 2004 i686
(--) PCI: (0:10:0) nVidia Corporation NV5M64 [RIVA TNT2 Model 64/Model
64 Pro] rev 21
(--) PCI:*(1:0:0) Matrox Graphics, Inc. MGA G400 AGP rev 4
(**) Xinerama: enabled




Enabled verbose output and got this (which seems to agree with gdb trace):

./3ddeskd
load_conf: opened /usr/local/etc/3ddesktop.conf
Found view: goright
Found view: goleft
Found view: slide
Found view: nozoom
Found view: linear
Found view: linearzip
Found view: bigmoney
vdesktops: EWMH
c=0, r=0, nc=4, nr=1
width 2560 x 1024
XF86VidModeExtension-Version 2.2
Only Singlebuffered Visual!
glX-Version 1.3
create context
Segmentation fault



Here's the output from configure and the build process:

checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking how to run the C++ preprocessor... g++ -E
checking for X... libraries , headers /usr/X11R6/include
checking for gethostbyname... yes
checking for connect... yes
checking for remove... yes
checking for shmat... yes
checking for IceConnectionNumber in -lICE... yes
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for gethostbyname... (cached) yes
checking for connect... (cached) yes
checking for remove... (cached) yes
checking for shmat... (cached) yes
checking for IceConnectionNumber in -lICE... (cached) yes
checking GL/gl.h usability... yes
checking GL/gl.h presence... yes
checking for GL/gl.h... yes
checking for XextCreateExtension in -lXext... yes
checking for XF86VidModeSetViewPort in -lXxf86vm... yes
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking dependency style of gcc... gcc3
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for main in -lm... yes
checking for OpenGL... yes
checking for cos in -lm... yes
checking for imlib2-config... yes
checking for inline... inline
checking whether time.h and sys/time.h may both be included... yes
checking for gettimeofday... yes
checking for mkdir... yes
checking for strerror... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating 3ddesktop.spec
config.status: creating maketar.sh
config.status: creating config.h
config.status: executing depfiles commands

cd . && /bin/sh /home/seymour/3ddesktop-0.2.8/missing --run autoheader
rm -f stamp-h1
touch config.h.in
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
make  all-am
make[1]: Entering directory `/home/seymour/3ddesktop-0.2.8'
if g++ -DHAVE_CONFIG_H -I. -I. -I.   -I/usr/X11R6/include
-I/usr/X11R6/include -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2  -MT 3ddesk.o -MD -MP
-MF ".deps/3ddesk.Tpo" -c -o 3ddesk.o 3ddesk.cpp; \
then mv -f ".deps/3ddesk.Tpo" ".deps/3ddesk.Po"; else rm -f
".deps/3ddesk.Tpo"; exit 1; fi
g++ -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2    -o 3ddesk 
3ddesk.o  -lm -lXxf86vm -lXext   -lSM -lICE -lSM -lICE
if g++ -DHAVE_CONFIG_H -I. -I. -I.   -I/usr/X11R6/include
-I/usr/X11R6/include -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2  -MT 3ddeskd.o -MD
-MP -MF ".deps/3ddeskd.Tpo" -c -o 3ddeskd.o 3ddeskd.cpp; \
then mv -f ".deps/3ddeskd.Tpo" ".deps/3ddeskd.Po"; else rm -f
".deps/3ddeskd.Tpo"; exit 1; fi
if g++ -DHAVE_CONFIG_H -I. -I. -I.   -I/usr/X11R6/include
-I/usr/X11R6/include -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2  -MT xutil.o -MD -MP
-MF ".deps/xutil.Tpo" -c -o xutil.o xutil.cpp; \
then mv -f ".deps/xutil.Tpo" ".deps/xutil.Po"; else rm -f
".deps/xutil.Tpo"; exit 1; fi
if g++ -DHAVE_CONFIG_H -I. -I. -I.   -I/usr/X11R6/include
-I/usr/X11R6/include -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2  -MT arrange.o -MD
-MP -MF ".deps/arrange.Tpo" -c -o arrange.o arrange.cpp; \
then mv -f ".deps/arrange.Tpo" ".deps/arrange.Po"; else rm -f
".deps/arrange.Tpo"; exit 1; fi
if g++ -DHAVE_CONFIG_H -I. -I. -I.   -I/usr/X11R6/include
-I/usr/X11R6/include -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2  -MT util.o -MD -MP
-MF ".deps/util.Tpo" -c -o util.o util.cpp; \
then mv -f ".deps/util.Tpo" ".deps/util.Po"; else rm -f
".deps/util.Tpo"; exit 1; fi
if g++ -DHAVE_CONFIG_H -I. -I. -I.   -I/usr/X11R6/include
-I/usr/X11R6/include -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2  -MT win.o -MD -MP
-MF ".deps/win.Tpo" -c -o win.o win.cpp; \
then mv -f ".deps/win.Tpo" ".deps/win.Po"; else rm -f ".deps/win.Tpo";
exit 1; fi
g++ -Wall -O3 -DQT_CLEAN_NAMESPACE
-DSHAREDIR=\"/usr/local/share/3ddesktop\"
-DSYSCONFDIR=\"/usr/local/etc\" -I/usr/X11R6/include 
-I/usr/X11R6/include -I/usr/X11R6/include -g -O2    -o 3ddeskd
-L/usr/lib -lImlib2 -lfreetype -lz -lm -ldl -lXext -lXext -lX11
-L/usr/X11R6/lib -lGLU -lGL  -lSM -lICE -lSM -lICE  -lX11 -lXext -lXmu
-lXt -lXi  -lm  3ddeskd.o xutil.o arrange.o util.o win.o  -lm
-lXxf86vm -lXext   -lSM -lICE -lSM -lICE
make[1]: Leaving directory `/home/seymour/3ddesktop-0.2.8'




Below is my patch (email me if this doesn't hold up well and I'll
forward it as an attachment).

------------snip---------------
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <sys/time.h>  // for gettimeofday
 #include <time.h>
 #include <fcntl.h>
@@ -643,6 +644,7 @@
 int daemon_init (void)
 {
     pid_t pid;
+    int status;

     msgout (DEBUG, "daemon init\n");

@@ -650,8 +652,17 @@
         msgout (ERROR, "daemon_init: fork failed: %s\n", strerror(errno));
         return -1;
     } else if (pid != 0) {
-        msgout (INFO, "Daemon started.  Run 3ddesk to activate.\n");
-        exit(0);  // bye parent
+        sleep(5);
+        if (waitpid(-1, &status, WNOHANG) != -1)
+        {
+            msgout (INFO, "Daemon exited abnormally with status:
%i\n", status);
+            exit(1);
+        }
+        else
+        {
+            msgout (INFO, "Daemon started.  Run 3ddesk to activate.\n");
+            exit(0);  // bye parent
+        }
     }

     // child continues
------------snip---------------

Other related posts: