signal handlers and X

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

2 posts / 0 new
Last post
signal handlers and X

Submitted by Anonymous on Thu, 12/27/2001 - 17:34. General Questions
I have been reading that it is a very bad idea to put X calls in signal handlers because if a signal was received in the middle of an X call, and then the signal handler makes an X call, it can get confused and cause symptoms such as core dumps or the screen will not refresh. I have software that is doing exactly this. The Motif manual suggested using a work procedure. I could not get this to work, however, and submitted the problem to Sun (I`m running on Solaris 2.6). They recommended using XtAppAddSignal and XtNoticeSignal because the work procedure method is not longer valid (this was my understanding) for X11 Release 6 (which is what Solaris 2.6 uses). However, those do not seem to solve the problem of the software just core dumping. It always core dumps in the very first X call after a signal is received. Does anyone have any suggestions?

ICS_support

The work procedure was always questionable, because it involves memory allocation, which isn`t one of the valid things to do in a signal handler -- there is a small list of valid operations which are considered safe.

One way to work around the problem is to have your signal handler simply flip a flag, as you might do even in an application which is not X-based or Motif-based. The handler sets someGlobalSignalFlag to True. And here is the trick -- you have *already* installed a timer or a work procedure which checks intermittently for that flag being set to True, and responds appropriately. In this way, your application notices when the flag is set, without performing questionable operations in the signal handler.

With X11R6, in any case, Xt-based applications should use the mechanisms for signal handlers. These internally operate as above; Xt is already set to notice the flag`s flipping, and your signal handler simply flips the flag via Xt calls.

If this is not working, then you need to examine the core dump using a debugger. You can also run sychronously (-sync or _Xdebug=1) to resolve timing issues.