Re: Unix signals in GLib



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.

Andy
-- 
http://wingolog.org/


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