Re: SEGV when dlopen()ing Gnome code



OK, not sure if I'm totally getting this - you're loading a library (GNOME)
with dlopen(), then trying to dlclose() the library without unintializing
it first, so that all the functions/data setup in memory for the X server,
signal handlers, and atexit() calls are no longer loaded into memory when
the callbacks start occuring?

I think you need to shutdown the GNOME libraries before you close them.  I
don't know if the GNOME libraries have a way of completely closing/removing
all their callbacks.  If not, you can always use atexit() to set a callback
that will dlclose() the library.  Make sure that it is last in the atexit()
function queue, so that is called after GNOME shuts down.

Of course, I could be entirely wrong. ^,^  But I've been working
extensively with the dl* functions lately, for an extension loader in my
MUD server, so I certainly hope I've obtained a firm grasp of this stuff by
now.  Of course, given my past track records, that still may not be the
case.  ^,^

On 2001.02.10 00:06:20 -0500 Samuel Hocevar wrote:
> 
>    I am developing an application which loads its UI through dlopen()
> so that the main application doesn't directly depend on the Gnome
> libraries. However, when I load the Gnome UI, I get a segfault on exit
> if dlclose() was called before exit.
> 
>    Here is some sample code which illustrates the problem:
> 
> -----8<----- gnome.c -----8<-----
> #include <gnome.h>
> 
> static gint timeout(gpointer p_data) { gtk_main_quit(); return(FALSE); }
> 
> int main (void) {
>     char *p_args[] = { };
>     printf("WAZAAA\n");
>     gnome_init("gnome", "42", 1, p_args);
>     gtk_timeout_add(1, timeout, NULL);
>     gtk_main();
>     return(0);
> }
> -----8<----- gnome.c -----8<-----
> 
>    This program, when compiled with the following command line, works
> flawlessly :
> 
> $ gcc `gnome-config --cflags gnomeui` -o gnome gnome.c \
>       `gnome-config --libs gnomeui
> $ ./gnome
> WAZAAA
> $
> 
>    However, if I use the following program to dlopen() the first one:
> 
> -----8<----- dlgnome.c -----8<-----
> #include <dlfcn.h>
> 
> int main(void) {
>     void * lib; int (*gnome_main) (void);
>     lib = dlopen("./gnome.so", RTLD_LAZY);
>     gnome_main = dlsym(lib, "main");
>     gnome_main();
>     dlclose(lib);
>     return(0);
> }
> -----8<----- dlgnome.c -----8<-----
> 
>    When compiling with the following compilation options:
> 
> $ gcc `gnome-config --cflags gnomeui` -fPIC -shared -o gnome.so gnome.c \
>       `gnome-config --libs gnomeui | sed 's,-rdynamic,,'`
> $ gcc dlgnome.c -o dlgnome -ldl
> $ ./dlgnome
> WAZAAA
> zsh: 8266 segmentation fault (core dumped)  ./dlgnome
> $
> 
>    It segfaults and I could not find out the reason for this. I can
> imagine it may be due to some signal handlers, but fiddling around with
> sigaction() and gnome_client_disable_master_connection() didn't show
> much. And gdb's backtrace is stuck in libc.
> 
>    I notice that omitting the last dlclose(lib); line makes the
> application exit cleanly, so it really looks like some registered
> callbacks are not cleaned when returning from gtk_main(), but I have no
> idea what they may be.
> 
>    Has anyone ever went through such a problem ? Or does anyone know
> of an application that successfully dlopen()s a Gnome library and then
> flawlessly dlclose()s it ?
> 
>    Or am I maybe missing something obvious ?
> 
> Many thanks for any pointers or documentation about this,
> Sam.
> -- 
> Samuel Hocevar <sam zoy org> <http://sam.zoy.org/>
> for DVDs in Linux screw the MPAA and ; do dig $DVDs.z.zoy.org ; done | \
>       perl -ne 's/\.//g; print pack("H224",$1) if(/^x([^z]*)/)' | gunzip
> 
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-devel-list
> 
-- 
Sean Middleditch
  of
AwesomePlay Productions, Inc.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]