[prog] Signal handlers & GTK
Sujita Purushothaman
sujita at mimos.my
Wed Oct 2 11:05:20 EST 2002
Kathryn Hogg wrote:
> 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.
I do know that this isn't a good way to handle seg faults... :-D
This program assumes that a card is inserted into a reader attached
to the pc. For any reason, if that device is absent, or card is not running
or daemon polling the card is not running, it gives a segfault. The ideal
way would be to first detect if the device is installed, give error msg
otherwise,
detect if daemon is running, give error message otherwise, detect if card is
inserted,
give error message otherwise etc. But I need to learn how to do all that and
I need to finish this program in a day or two ,which is not possible, so
I opted
for catching segfaults and displaying the error message : "Card not
inserted/device
not installed - call for help " :-D and I'm terminating the program after
displaying the
error msg anyway. Just that since this program is meant for non-technical
users
I have to display the error message in a window. I've thought of a
roundabout
way to solve the problem, by using system() to run a program that just
displays
the error window. Is this a better solution?
Thanks!
Rgds,
Sujita
More information about the Programming
mailing list