#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include "mainloop-signal.h"
#include "util.h"
struct pa_signal_event {
int sig;
+#ifdef HAVE_SIGACTION
struct sigaction saved_sigaction;
+#else
+ void (*saved_handler)(int sig);
+#endif
void (*callback) (struct pa_mainloop_api*a, struct pa_signal_event *e, int signal, void *userdata);
void *userdata;
void (*destroy_callback) (struct pa_mainloop_api*a, struct pa_signal_event*e, void *userdata);
static struct pa_signal_event *signals = NULL;
static void signal_handler(int sig) {
+#ifndef HAVE_SIGACTION
+ signal(sig, signal_handler);
+#endif
write(signal_pipe[1], &sig, sizeof(sig));
}
pa_signal_free(signals);
- api->io_free(io_event);
+ api->io_free(io_event);
io_event = NULL;
close(signal_pipe[0]);
struct pa_signal_event* pa_signal_new(int sig, void (*callback) (struct pa_mainloop_api *api, struct pa_signal_event*e, int sig, void *userdata), void *userdata) {
struct pa_signal_event *e = NULL;
+
+#ifdef HAVE_SIGACTION
struct sigaction sa;
+#endif
+
assert(sig > 0 && callback);
for (e = signals; e; e = e->next)
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;
else
signals = e->next;
+#ifdef HAVE_SIGACTION
sigaction(e->sig, &e->saved_sigaction, NULL);
+#else
+ signal(e->sig, e->saved_handler);
+#endif
if (e->destroy_callback)
e->destroy_callback(api, e, e->userdata);
/* Print a warning messages in case that the given signal is not
* blocked or trapped */
void pa_check_signal_is_blocked(int sig) {
+#ifdef HAVE_SIGACTION
struct sigaction sa;
sigset_t set;
return;
pa_log(__FILE__": WARNING: %s is not trapped. This might cause malfunction!\n", pa_strsignal(sig));
+#else /* HAVE_SIGACTION */
+ pa_log(__FILE__": WARNING: %s might not be trapped. This might cause malfunction!\n", pa_strsignal(sig));
+#endif
}
/* The following function is based on an example from the GNU libc