Mercurial > audlegacy
changeset 4690:cd1e4d4aa0b9
Take advantage of signalfd if available.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sat, 05 Jul 2008 16:55:24 -0500 |
parents | 7453f5365b8c |
children | 5db8a7848565 |
files | configure.ac src/audacious/signals.c |
diffstat | 2 files changed, 55 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Thu Jul 03 01:07:07 2008 +0200 +++ b/configure.ac Sat Jul 05 16:55:24 2008 -0500 @@ -67,7 +67,7 @@ dnl Check for headers and functions dnl =============================== AC_CHECK_HEADERS([unistd.h fcntl.h sys/ioctl.h fnmatch.h limits.h wchar.h fts.h execinfo.h]) -AC_CHECK_FUNCS([mkdtemp getmntinfo statvfs strtoul lrintf]) +AC_CHECK_FUNCS([mkdtemp getmntinfo statvfs strtoul lrintf signalfd]) ### ---------------------------------------------------------------------------
--- a/src/audacious/signals.c Thu Jul 03 01:07:07 2008 +0200 +++ b/src/audacious/signals.c Sat Jul 05 16:55:24 2008 -0500 @@ -85,6 +85,8 @@ abort(); } +#ifndef HAVE_SIGNALFD + static void * signal_process_signals (void *data) { @@ -172,6 +174,58 @@ linuxthread_signal_number = signal_number; } +#else + +#include <sys/signalfd.h> + +static gpointer +signal_process_signals(gpointer data) +{ + struct signalfd_siginfo d; + sigset_t waitset; + int sigfd; + + sigemptyset(&waitset); + sigaddset(&waitset, SIGPIPE); + sigaddset(&waitset, SIGSEGV); + sigaddset(&waitset, SIGINT); + sigaddset(&waitset, SIGTERM); + + sigfd = signalfd(-1, &waitset, 0); + + while (read(sigfd, &d, sizeof(struct signalfd_siginfo)) > 0) + { + switch(d.ssi_signo) + { + case SIGPIPE: + /* + * do something. + */ + break; + + case SIGSEGV: + signal_process_segv(); + break; + + case SIGINT: + g_print("Audacious has received SIGINT and is shutting down.\n"); + aud_quit(); + break; + + case SIGTERM: + g_print("Audacious has received SIGTERM and is shutting down.\n"); + aud_quit(); + break; + } + } + + close(sigfd); + + return NULL; +} + +#endif + static SignalHandler signal_install_handler_full (gint signal_number, SignalHandler handler,