Re: Unix signals in GLib



On 2010-04-30 03:56, Andy Wingo wrote:
> On Fri 30 Apr 2010 10:23, Xavier Bestel <xavier bestel free fr> writes:
> 
>> On Fri, 2010-04-30 at 09:18 +0100, Richard Hughes wrote:
>>> I'm writing for comments. Making my daemons (upower, PackageKit, etc)
>>> quit nicely after receiving SIGTERM or SIGINT is _really_ hard to do
>>> correctly. The fact that I can only do a few things (write, etc) in
>>> the signal handler makes otherwise quite nice GLib code very quickly
>>> descend into l33t UNIX #ifdef code which is quite unportable and
>>> really hard to get right.
>>
>> Can't you just signal your mainloop to quit from the signal handler, and
>> do the heavyweight work from there ?
> 
> g_main_context_wakeup () is not signal-safe.
> 
> The correct thing to do is to make a socketpair, and write on it from
> the signal handler, and tie the read side to a GSource.

Remember that this doesn't work correctly in threaded apps, as we found
in gnome-keyring-daemon. You have to do the strange
signal-handling-thread-thing.

Cheers,

Stef


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]