Logo Search packages:      
Sourcecode: pulseaudio version File versions

pa_signal_event* pa_signal_new ( int  sig,
pa_signal_cb_t  callback,
void *  userdata 
)

Create a new UNIX signal event source object

Definition at line 159 of file mainloop-signal.c.

References pa_xnew.

                                                                                  {
    pa_signal_event *e = NULL;

#ifdef HAVE_SIGACTION
    struct sigaction sa;
#endif

    pa_assert(sig > 0);
    pa_assert(_callback);

    pa_init_i18n();

    for (e = signals; e; e = e->next)
        if (e->sig == sig)
            goto fail;

    e = pa_xnew(pa_signal_event, 1);
    e->sig = sig;
    e->callback = _callback;
    e->userdata = userdata;
    e->destroy_callback = NULL;

#ifdef HAVE_SIGACTION
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = signal_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;

    if (sigaction(sig, &sa, &e->saved_sigaction) < 0)
#else
    if ((e->saved_handler = signal(sig, signal_handler)) == SIG_ERR)
#endif
        goto fail;

    e->previous = NULL;
    e->next = signals;
    signals = e;

    return e;
fail:
    if (e)
        pa_xfree(e);
    return NULL;
}


Generated by  Doxygen 1.6.0   Back to index