[prog] Signal handlers & GTK

Kathryn Hogg kjh at flyballdogs.com
Tue Oct 1 21:52:28 EST 2002


>   I'm trying to write a program that will catch segmentation faults
> and display a window saying that the program has terminated.
> I have this line in my main function :  signal(SIGSEGV,nocard);
>
> and I have a function nocard like this :
>
> void nocard(int  dummy)
> {
>
>     printf("Inside nocard\n");
>     gtk_widget_show(window);
>     sleep(5);
>    exit(1);
>
> }

There are a couple of philosophical problems with this.   First, you are
extremely restricted in what functions you can safely call in a signal
handler.  I doubt that printf() and sleep() are safe let alone any gtk
calls.  I've had problems on some Unix flavors calling waitpid() in a
SIGCLD handler and just yesterday because a signal handler was doing
malloc().

Secondly, if your program is dying with SEGV you should assume that you
memory is trashed which makes any function call suspect.  It would be
better to have some kind of driver program, exec the real program, wait
for the child, and then examine the exit status and display your dialog if
an abnormal condition resulted in the termination.

Kathryn
>
> The problem is the window isn't displayed; I added the sleep after the
> window show to make
> sure the window is displayed long enough to be seen. I even  tried
> putting gtk_init before
> gtk_window_show but it still has no effect. The sleep function works
> well. What is wrong
> here?
>
> Rgds,
> Sujita
>
>
>
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://www.linuxchix.org/mailman/listinfo/programming


-- 
Kathryn





More information about the Programming mailing list