3

A signal that a process has sent to itself from within a signal handler could not get delivered for about 20 seconds and then it was delivered.

What could be the probable causes?

I would like to know the probable reasons in general.

The actual Code I am looking at is here

Sandeep
  • 18,356
  • 16
  • 68
  • 108

1 Answers1

2

Most probably, you're calling a function from within a signal handler that you mustn't call from within that signal handler.

See man 7 signal for details:

Async-signal-safe functions

A signal handler function must be very careful, since processing elsewhere may be interrupted at some arbitrary point in the execution of the program. POSIX has the concept of "safe function". If a signal interrupts the execution of an unsafe function, and handler calls an unsafe function, then the behavior of the program is undefined.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • I feel both the functions are safe functions. I have updated the source code link. Pls have a look if possible. – Sandeep Jun 04 '15 at 11:13
  • This might not be the reason in *this* particular case, but the OP asked for general advices, and this is a good advice in general. Plus one! – hek2mgl Jun 04 '15 at 11:29
  • @mk: Read *carefully* [signal(7)](http://man7.org/linux/man-pages/man7/signal.7.html). Your `SignalHandler` is indirectly calling `pthread_mutex_lock` which is *not* in the list of async-signal-safe functions. – Basile Starynkevitch Jun 04 '15 at 11:41
  • "POSIX.1-2004 (also known as POSIX.1-2001 Technical Corrigendum 2) requires an implementation to guarantee that the following functions can be safely called inside a signal handler:" I kind of dont understand this statement. "guarantee" - who should guarantee? Does it means that the listed functions are safe or unsafe? Sorry to bother you. – Sandeep Jun 05 '15 at 02:39
  • @BasileStarynkevitch The exact issue is https://code.google.com/p/android/issues/detail?id=162896&can=1&q=libbacktrace&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars#makechanges – Sandeep Jun 05 '15 at 04:38
  • 1
    @mk: it means that all the functions not listed are unsafe, ans since `pthread_mutex_lock` is not listed, you are not allowed to call it, even indirectly, inside a signal handler. – Basile Starynkevitch Jun 05 '15 at 04:50
  • @BasileStarynkevitch Thank you. But, According to what i understand, there will be a problem if the process that is blocked is inside pthread_mutex_lock() and signal handler calls it as well. But I dont see it here. The signal handler is giving the signal to itself, hence the issue in this case could be different. No? Am I getting it still wrong. – Sandeep Jun 05 '15 at 05:27
  • No, the issue *may* appear if the signal handler is using some unauthorized functions, e.g. `pthread_mutex_lock`; the point is that stricto sensu a signal handler can use (even indirectly) only a very restricted set of functions and *everything else is forbidden* – Basile Starynkevitch Jun 05 '15 at 05:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/79729/discussion-between-mk-and-basile-starynkevitch). – Sandeep Jun 05 '15 at 05:32