summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-10-20 11:12:30 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-10-20 11:41:37 +0200
commit8b5641263a915d4b8ac4c9c8f84f34f09b120402 (patch)
tree0c21c6853f3fc02da1b77d424636a8a6a3765558
parent05df6eb3d1b49bd1c0f255712dac5f60f0cd4c35 (diff)
downloadpa-sink-ctl-8b5641263a915d4b8ac4c9c8f84f34f09b120402.tar.gz
pa-sink-ctl-8b5641263a915d4b8ac4c9c8f84f34f09b120402.tar.bz2
pa-sink-ctl-8b5641263a915d4b8ac4c9c8f84f34f09b120402.zip
Use signalfd if available
If kqueue can be added as well, our homegrown kinda ugly signal dispatcher could be killed.
-rw-r--r--configure.ac8
-rw-r--r--src/Makefile.am10
-rw-r--r--src/interface.c32
-rw-r--r--src/unix_signal.c1
4 files changed, 47 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 4d51963..208da52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,15 @@ AC_SUBST(GCC_CFLAGS)
AC_SUBST(CURSES_LIBS)
-AC_CHECK_HEADERS([ncurses.h sys/ioctl.h unistd.h signal.h])
+AC_CHECK_HEADERS([ncurses.h sys/ioctl.h sys/signalfd.h unistd.h signal.h])
AC_CHECK_FUNC([sigaction], [], AC_MSG_ERROR([function sigaction() not found]))
+AC_CHECK_FUNCS([signalfd])
+
+AM_CONDITIONAL([HAVE_SIGNALFD],
+ [test "x$ac_cv_func_signalfd" = "xyes" -a "x$ac_cv_header_sys_signalfd_h" = "xyes"])
+
+AC_DEFINE([_POSIX_C_SOURCE], [1], [Enable POSIX.1-1990 definitions])
AC_C_INLINE
diff --git a/src/Makefile.am b/src/Makefile.am
index 6079b35..863fea4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,14 @@
bin_PROGRAMS = pa-sink-ctl
-pa_sink_ctl_SOURCES = interface.c pa-sink-ctl.c sink.c sink_input.c unix_signal.c
+pa_sink_ctl_SOURCES = interface.c pa-sink-ctl.c sink.c sink_input.c
+EXTRA_pa_sink_ctl_SOURCES = unix_signal.c
+
+if !HAVE_SIGNALFD
+pa_sink_ctl_SOURCES += unix_signal.c
+endif
AM_CFLAGS = $(GCC_CFLAGS)
-AM_CPPFLAGS = $(PULSE_CFLAGS) $(PULSE_MAINLOOP_CFLAGS) $(GLIB_CFLAGS)
+AM_CPPFLAGS = $(PULSE_CFLAGS) $(PULSE_MAINLOOP_CFLAGS) $(GLIB_CFLAGS) \
+ -include $(top_builddir)/config.h
pa_sink_ctl_LDADD = $(GLIB_LIBS) $(PULSE_LIBS) $(PULSE_MAINLOOP_LIBS) $(CURSES_LIBS)
noinst_HEADERS = interface.h pa-sink-ctl.h sink.h sink_input.h unix_signal.h
diff --git a/src/interface.c b/src/interface.c
index 83bd3b0..74a04d3 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -10,7 +10,12 @@
#include "sink.h"
#include "pa-sink-ctl.h"
+#ifdef HAVE_SIGNALFD
+#include <sys/signalfd.h>
+#include <signal.h>
+#else
#include "unix_signal.h"
+#endif
#define H_MSG_BOX 3
@@ -24,6 +29,9 @@ static WINDOW *menu_win;
static WINDOW *msg_win;
static guint resize_source_id;
+#ifdef HAVE_SIGNALFD
+static int signal_fd;
+#endif
static guint input_source_id;
static gint chooser_sink;
@@ -329,6 +337,7 @@ interface_clear(void)
{
g_source_remove(resize_source_id);
g_source_remove(input_source_id);
+ close(signal_fd);
clear();
refresh();
endwin();
@@ -351,6 +360,14 @@ interface_set_status(const gchar *msg)
refresh();
}
+#ifdef HAVE_SIGNALFD
+static gboolean
+resize_gio(GIOChannel *source, GIOCondition condition, gpointer data)
+{
+ return interface_resize(data);
+}
+#endif
+
void
interface_init(void)
{
@@ -378,8 +395,23 @@ interface_init(void)
/* "resizing" here is for initial box positioning and layout */
interface_resize(NULL);
+#ifdef HAVE_SIGNALFD
+ {
+ GIOChannel *channel;
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGWINCH);
+
+ signal_fd = signalfd(-1, &mask, 0);
+ channel = g_io_channel_unix_new(signal_fd);
+ g_io_add_watch(channel, G_IO_IN, resize_gio, NULL);
+ g_io_channel_unref(channel);
+ }
+#else
/* register event handler for resize and input */
resize_source_id = unix_signal_add(SIGWINCH, interface_resize, NULL);
+#endif
input_channel = g_io_channel_unix_new(STDIN_FILENO);
if (!input_channel)
exit(EXIT_FAILURE);
diff --git a/src/unix_signal.c b/src/unix_signal.c
index 7577051..894b6d9 100644
--- a/src/unix_signal.c
+++ b/src/unix_signal.c
@@ -1,4 +1,3 @@
-#define _POSIX_SOURCE
#include <signal.h>
#include <glib.h>
#include "unix_signal.h"