summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac22
-rw-r--r--src/Makefile.am7
-rw-r--r--src/interface.c6
-rw-r--r--src/unix_signal.c166
-rw-r--r--src/unix_signal.h32
5 files changed, 17 insertions, 216 deletions
diff --git a/configure.ac b/configure.ac
index 470f179..fc6ec3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,12 +28,24 @@ AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
+AC_CHECK_HEADERS([ncurses.h sys/ioctl.h sys/signalfd.h unistd.h signal.h])
+
+AC_CHECK_FUNCS([signalfd])
+
+glib_version=2.0
+if test "x$ac_cv_func_signalfd" = "xno" -o "x$ac_cv_header_sys_signalfd_h" = "xno"; then
+ # If signalfd() is not available, we want to use g_unix_signal_add()
+ # which is supported for SIGWINCH as of 2.54, see
+ # https://github.com/GNOME/glib/commit/47a02c85610f4036681c9728b7339d
+ glib_version=2.54
+fi
+
# Checks for libraries.
AC_CHECK_LIB([ncurses], [newwin], [CURSES_LIBS=-lncurses], AC_MSG_ERROR([curses required]))
PKG_CHECK_MODULES(PULSE, [libpulse], [], AC_MSG_ERROR([libpulse required]))
PKG_CHECK_MODULES(PULSE_MAINLOOP, [libpulse-mainloop-glib], [], AC_MSG_ERROR([libpulse-mainloop-glib required]))
-PKG_CHECK_MODULES(GLIB, [glib-2.0], [], AC_MSG_ERROR([glib required]))
+PKG_CHECK_MODULES(GLIB, [glib-2.0 >= $glib_version], [], AC_MSG_ERROR([glib >= $glib_version required]))
if test "x$GCC" = "xyes"; then
GCC_CFLAGS="-Wall -pedantic -std=c99 -W -Wextra -pipe -Wno-long-long -Winline -Wvla -Wno-overlength-strings -Wunsafe-loop-optimizations -Wundef -Wformat=2 -Wlogical-op -Wsign-compare -Wformat-security -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Winit-self -Wdeclaration-after-statement -Wfloat-equal -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wmissing-declarations -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align -Wstrict-aliasing=2 -Wwrite-strings -Wno-unused-parameter -ffast-math -Wp,-D_FORTIFY_SOURCE=2 -fno-common -fdiagnostics-show-option -fvisibility=hidden"
@@ -42,14 +54,6 @@ AC_SUBST(GCC_CFLAGS)
AC_SUBST(CURSES_LIBS)
-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 3579dc0..6c81c83 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,17 +1,12 @@
bin_PROGRAMS = pa-sink-ctl
pa_sink_ctl_SOURCES = interface.c command.c config.c pa-sink-ctl.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) \
-include $(top_builddir)/config.h
pa_sink_ctl_LDADD = $(GLIB_LIBS) $(PULSE_LIBS) $(PULSE_MAINLOOP_LIBS) $(CURSES_LIBS)
-noinst_HEADERS = interface.h command.h config.h pa-sink-ctl.h ctl.h unix_signal.h
+noinst_HEADERS = interface.h command.h config.h pa-sink-ctl.h ctl.h
dist_man_MANS = pa-sink-ctl.1
EXTRA_DIST = pa-sink-ctl.1.txt
diff --git a/src/interface.c b/src/interface.c
index 27c937c..c7d6d5e 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -35,7 +35,7 @@
#include <sys/signalfd.h>
#include <signal.h>
#else
-#include "unix_signal.h"
+#include <glib-unix.h>
#endif
static void
@@ -286,8 +286,8 @@ interface_init(struct interface *ifc)
}
#else
/* register event handler for resize and input */
- ifc->resize_source_id = unix_signal_add(SIGWINCH,
- interface_resize, ifc);
+ ifc->resize_source_id = g_unix_signal_add(SIGWINCH,
+ interface_resize, ifc);
#endif
input_channel = g_io_channel_unix_new(STDIN_FILENO);
if (!input_channel)
diff --git a/src/unix_signal.c b/src/unix_signal.c
deleted file mode 100644
index e2d9581..0000000
--- a/src/unix_signal.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * pa-sink-ctl - NCurses based Pulseaudio control client
- * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke@googlemail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <signal.h>
-#include <glib.h>
-#include "unix_signal.h"
-
-static GPtrArray *signal_data = NULL;
-
-typedef struct _UnixSignalData {
- guint source_id;
- GMainContext *context;
- gboolean triggered;
- gint signum;
-} UnixSignalData;
-
-typedef struct _UnixSignalSource {
- GSource source;
- UnixSignalData *data;
-} UnixSignalSource;
-
-static void
-handler(gint signum);
-
-struct sigaction act_handler = {
- .sa_handler = handler
-};
-struct sigaction act_null = {
- .sa_handler = NULL
-};
-
-static inline UnixSignalData *
-unix_signal_data(guint index)
-{
- return (UnixSignalData *) g_ptr_array_index(signal_data, index);
-}
-
-static void
-handler(gint signum)
-{
- g_assert(signal_data != NULL);
- for (guint i = 0; i < signal_data->len; ++i)
- if (unix_signal_data(i)->signum == signum)
- unix_signal_data(i)->triggered = TRUE;
- sigaction(signum, &act_handler, NULL);
-}
-
-static gboolean
-check(GSource *source)
-{
- UnixSignalSource *signal_source = (UnixSignalSource *) source;
-
- return signal_source->data->triggered;
-}
-
-static gboolean
-prepare(GSource *source, gint *timeout_)
-{
- UnixSignalSource *signal_source = (UnixSignalSource*) source;
-
- if (signal_source->data->context == NULL) {
- g_main_context_ref(signal_source->data->context =
- g_source_get_context(source));
- signal_source->data->source_id = g_source_get_id(source);
- }
-
- *timeout_ = -1;
-
- return signal_source->data->triggered;
-}
-
-static gboolean
-dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
-{
- UnixSignalSource *signal_source = (UnixSignalSource *) source;
-
- signal_source->data->triggered = FALSE;
-
- return callback(user_data) ? TRUE : FALSE;
-}
-
-static void
-finalize(GSource *source)
-{
- UnixSignalSource *signal_source = (UnixSignalSource*) source;
-
- sigaction(signal_source->data->signum, &act_null, NULL);
- g_main_context_unref(signal_source->data->context);
- g_ptr_array_remove_fast(signal_data, signal_source->data);
- if (signal_data->len == 0)
- signal_data = (GPtrArray*) g_ptr_array_free(signal_data, TRUE);
- g_free(signal_source->data);
-
-}
-static GSourceFuncs SourceFuncs =
-{
- .prepare = prepare,
- .check = check,
- .dispatch = dispatch,
- .finalize = finalize,
- .closure_callback = NULL, .closure_marshal = NULL
-};
-
-static void
-unix_signal_source_init(GSource *source, gint signum)
-{
- UnixSignalSource *signal_source = (UnixSignalSource *) source;
-
- signal_source->data = g_new(UnixSignalData, 1);
- signal_source->data->triggered = FALSE;
- signal_source->data->signum = signum;
- signal_source->data->context = NULL;
-
- if (signal_data == NULL)
- signal_data = g_ptr_array_new();
- g_ptr_array_add(signal_data, signal_source->data);
-}
-
-GSource *
-unix_signal_source_new(gint signum)
-{
- GSource *source = g_source_new(&SourceFuncs, sizeof(UnixSignalSource));
-
- unix_signal_source_init(source, signum);
- sigaction(signum, &act_handler, NULL);
-
- return source;
-}
-
-guint
-unix_signal_add_full(gint priority, gint signum, GSourceFunc function,
- gpointer data, GDestroyNotify notify)
-{
- guint id;
- GSource *source = unix_signal_source_new(signum);
- g_return_val_if_fail(function != NULL, 0);
-
- if (priority != G_PRIORITY_DEFAULT)
- g_source_set_priority (source, priority);
- g_source_set_callback(source, function, data, notify);
- id = g_source_attach(source, NULL);
- g_source_unref(source);
-
- return id;
-}
-
-guint unix_signal_add(gint signum, GSourceFunc function, gpointer data)
-{
- return unix_signal_add_full(G_PRIORITY_DEFAULT, signum,
- function, data, NULL);
-}
diff --git a/src/unix_signal.h b/src/unix_signal.h
deleted file mode 100644
index da47a99..0000000
--- a/src/unix_signal.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * pa-sink-ctl - NCurses based Pulseaudio control client
- * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke@googlemail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UNIX_SIGNAL_H
-#define UNIX_SIGNAL_H
-
-#include <glib.h>
-
-GSource *
-unix_signal_source_new(gint signum);
-guint
-unix_signal_add(gint signum, GSourceFunc function, gpointer data);
-guint
-unix_signal_add_full(gint priority, gint signum, GSourceFunc function,
- gpointer data, GDestroyNotify notify);
-
-#endif /* UNIX_SIGNAL_H */