Commit 1caa8c2d authored by David Zeuthen's avatar David Zeuthen
Browse files

Use g_unix_signal_add() from GLib 2.30



... instead of the one I wrote myself.
Signed-off-by: default avatarDavid Zeuthen <davidz@redhat.com>
parent 587deddf
......@@ -123,7 +123,7 @@ if test "x$GCC" = "xyes"; then
changequote([,])dnl
fi
PKG_CHECK_MODULES(GLIB, [gio-2.0 >= 2.28.0])
PKG_CHECK_MODULES(GLIB, [gio-2.0 >= 2.30.0])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
......
......@@ -19,7 +19,6 @@ libpriv_PROGRAMS = polkitd
polkitd_SOURCES = \
main.c \
gposixsignal.h gposixsignal.c \
$(NULL)
polkitd_CFLAGS = \
......
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#include "config.h"
#include "gposixsignal.h"
#if defined(__linux__)
#include <unistd.h>
#include <sys/signalfd.h>
#include <signal.h>
typedef struct
{
GSource source;
GPollFD pollfd;
gint signum;
} _GPosixSignalSource;
static gboolean
_g_posix_signal_source_prepare (GSource *_source,
gint *timeout)
{
*timeout = -1;
return FALSE;
}
static gboolean
_g_posix_signal_source_check (GSource *_source)
{
_GPosixSignalSource *source = (_GPosixSignalSource *) _source;
return source->pollfd.revents != 0;
}
static gboolean
_g_posix_signal_source_dispatch (GSource *_source,
GSourceFunc callback,
gpointer user_data)
{
_GPosixSignalWatchFunc func = (_GPosixSignalWatchFunc) callback;
g_warn_if_fail (func != NULL);
return (*func) (user_data);
}
static void
_g_posix_signal_source_finalize (GSource *_source)
{
_GPosixSignalSource *source = (_GPosixSignalSource *) _source;
close (source->pollfd.fd);
}
static GSourceFuncs _g_posix_signal_source_funcs =
{
_g_posix_signal_source_prepare,
_g_posix_signal_source_check,
_g_posix_signal_source_dispatch,
_g_posix_signal_source_finalize
};
GSource *
_g_posix_signal_source_new (gint signum)
{
sigset_t sigset;
gint fd;
GSource *_source;
_GPosixSignalSource *source;
_source = NULL;
sigemptyset (&sigset);
sigaddset (&sigset, signum);
if (sigprocmask (SIG_BLOCK, &sigset, NULL) == -1)
g_assert_not_reached ();
fd = signalfd (-1, &sigset, SFD_NONBLOCK | SFD_CLOEXEC);
_source = g_source_new (&_g_posix_signal_source_funcs, sizeof (_GPosixSignalSource));
source = (_GPosixSignalSource *) _source;
source->pollfd.fd = fd;
source->pollfd.events = G_IO_IN;
g_source_add_poll (_source, &source->pollfd);
source->signum = signum;
return _source;
}
guint
_g_posix_signal_watch_add (gint signum,
gint priority,
_GPosixSignalWatchFunc function,
gpointer user_data,
GDestroyNotify notify)
{
GSource *source;
guint id;
g_return_val_if_fail (function != NULL, 0);
source = _g_posix_signal_source_new (signum);
if (priority != G_PRIORITY_DEFAULT_IDLE)
g_source_set_priority (source, priority);
g_source_set_callback (source, (GSourceFunc) function, user_data, notify);
id = g_source_attach (source, NULL);
g_source_unref (source);
return id;
}
#else /* __linux__ */
GSource *
_g_posix_signal_source_new (gint signum)
{
return NULL;
}
guint
_g_posix_signal_watch_add (gint signum,
gint priority,
_GPosixSignalWatchFunc function,
gpointer user_data,
GDestroyNotify notify)
{
return 0;
}
#endif /* __linux__ */
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#ifndef ___G_POSIX_SIGNAL_H__
#define ___G_POSIX_SIGNAL_H__
#include <glib.h>
G_BEGIN_DECLS
typedef gboolean (*_GPosixSignalWatchFunc) (gpointer user_data);
GSource *_g_posix_signal_source_new (gint signum);
guint _g_posix_signal_watch_add (gint signum,
gint priority,
_GPosixSignalWatchFunc function,
gpointer user_data,
GDestroyNotify notify);
G_END_DECLS
#endif /* ___G_POSIX_SIGNAL_H__ */
......@@ -28,8 +28,6 @@
#include <polkit/polkit.h>
#include <polkitbackend/polkitbackend.h>
#include "gposixsignal.h"
/* ---------------------------------------------------------------------------------------------------- */
static PolkitBackendAuthority *authority = NULL;
......@@ -147,11 +145,9 @@ main (int argc,
loop = g_main_loop_new (NULL, FALSE);
sigint_id = _g_posix_signal_watch_add (SIGINT,
G_PRIORITY_DEFAULT,
on_sigint,
NULL,
NULL);
sigint_id = g_unix_signal_add (SIGINT,
on_sigint,
NULL);
name_owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
"org.freedesktop.PolicyKit1",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment