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

Re: [Libevent-users] Possible to use libevent to handle SIGTERM and SIGQUIT



Yes, I just found out that I need to call event_add before start the
message pump.

Thanks.
Kun

On Tue, Aug 30, 2011 at 10:50 AM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
> On Tue, Aug 30, 2011 at 1:46 PM, Kun Xi <kunxi@xxxxxxxxx> wrote:
>> Hello,
>>
>> I just wondered whether libevent event loop can handle the SIGTERM and
>> SIGQUIT appropriately. ÂHere is the code snippet I am trying to exit
>> the message loop gracefully and brutally:
>>
>> static void quick_shutdown(evutil_socket_t _, short what, void* ctx) {
>> Â Âstruct event_base *evb = (struct event_base*) ctx;
>> Â Âevent_base_loopbreak(evb);
>> }
>>
>> static void graceful_shutdown(evutil_socket_t _, short what, void* ctx) {
>> Â Âstruct event_base *evb = (struct event_base*) ctx;
>> Â Âevent_base_loopexit(evb, NULL);
>> }
>>
>> // main()
>> Â Â/* signal handling */
>> Â Âstruct event *quit = evsignal_new(base, SIGQUIT, graceful_shutdown, base);
>> Â Âstruct event *term = evsignal_new(base, SIGTERM, quick_shutdown, base);
>>
>> Â Â/* message loop */
>> Â Âevent_base_dispatch(base);
>>
>> Â Â/* cleanup the mess */
>> Â Âevent_free(quit);
>> Â Âevent_free(term);
>> Â Âevent_base_free(base);
>> Â Âreturn 0;
>>
>> I expect that the process exits the message loop with kill -15 or kill
>> -3. But it never happens. I wonder whether something wrong with my
>> code, or we should not use libevent to handle SIGQUIT and SIGTERM.
>
> Looks like you never called event_add() on those events.
> evsignal_new(), like event_new(), only creates a new event: you need
> to use event_add() to make the base start watching for it.
>
> cheers,
> --
> Nick
> ***********************************************************************
> To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> unsubscribe libevent-users  Âin the body.
>
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.