Re: exception handling around a signal handler



Ulrich Eckhardt <doomster@xxxxxxxx> writes:
Brilte wrote:
I have some main code that performs work on an object. The object
(technically a struct), represents a child process. Currently i have a
bug within the child process that is causing it to segfault, but thats
not part of my question.

My question really is that when the child segfaults, the parent
receives a sigchld signal. This interrupts the main code which is
working with the child process and moves the object representing the
child process from one linked list into another and i lose the pointer
to the link within the main program causing it to segfault when it
tries to use a NULL pointer.

This can't work.

Of course it can, depending on the actual code being executed. The
signal handler must not use any pointer manipulated by the code it is
interrupting[*] and it must not return to the interrupted code after it
has changed some pointers this code uses to access something only by
reading their contents.

If both are given, the solution is to siglongjmp from the handler to
some place outside the code reading these pointers and that's it.
.



Relevant Pages

  • Re: exception handling around a signal handler
    ... , represents a child process. ... bug within the child process that is causing it to segfault, ... Use a dedicated thread to wait for signals. ...
    (comp.unix.programmer)
  • Re: exception handling around a signal handler
    ... , represents a child process. ... bug within the child process that is causing it to segfault, ... receives a sigchld signal. ...
    (comp.unix.programmer)
  • exception handling around a signal handler
    ... , represents a child process. ... bug within the child process that is causing it to segfault, ... receives a sigchld signal. ... tries to use a NULL pointer. ...
    (comp.unix.programmer)
  • Re: exception handling around a signal handler
    ... sigchld is performed so the main code can return with an error safely ... to indicate that a sigchld has occured against the child process is ... If the segfault is "unexpected" then the entire process should abort immediately. ... This would cause an "object fault" and then the memory was made available. ...
    (comp.unix.programmer)
  • Re: exception handling around a signal handler
    ... , represents a child process. ... bug within the child process that is causing it to segfault, ... receives a sigchld signal. ... To avoid the signal handler and the "main" processing loop to ...
    (comp.unix.programmer)