Related to #657
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/daemon/abrtd.c | 25 ++++---------------------
src/dbus/abrt-dbus.c | 2 +-
src/include/abrt-dbus.h | 4 ----
src/lib/Makefile.am | 1 +
src/lib/abrt_glib.c | 20 +++++++++++++++++++-
src/lib/abrt_glib.h | 30 ++++++++++++++++++++++++++++++
src/lib/problem_api_dbus.c | 1 +
7 files changed, 56 insertions(+), 27 deletions(-)
create mode 100644 src/lib/abrt_glib.h
diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c
index 2af55a5..124421a 100644
--- a/src/daemon/abrtd.c
+++ b/src/daemon/abrtd.c
@@ -24,6 +24,7 @@
#include <sys/inotify.h>
#include <sys/ioctl.h> /* ioctl(FIONREAD) */
+#include "abrt_glib.h"
#include "libabrt.h"
@@ -71,24 +72,6 @@ static guint add_watch_or_die(GIOChannel *channel, unsigned condition,
GIOFunc f
return r;
}
-static GIOChannel *my_io_channel_unix_new(int fd)
-{
- GIOChannel *ch = g_io_channel_unix_new(fd);
-
- /* Need to set the encoding otherwise we get:
- * "Invalid byte sequence in conversion input".
- * According to manual "NULL" is safe for binary data.
- */
- GError *error = NULL;
- g_io_channel_set_encoding(ch, NULL, &error);
- if (error)
- perror_msg_and_die("Can't set encoding on gio channel: %s",
error->message);
-
- g_io_channel_set_close_on_unref(ch, TRUE);
-
- return ch;
-}
-
static void increment_child_count(void)
{
if (++child_count >= MAX_CLIENT_COUNT)
@@ -427,7 +410,7 @@ static void dumpsocket_init(void)
if (chmod(SOCKET_FILE, SOCKET_PERMISSION) != 0)
perror_msg_and_die("chmod '%s'", SOCKET_FILE);
- channel_socket = my_io_channel_unix_new(socketfd);
+ channel_socket = abrt_gio_channel_unix_new(socketfd);
channel_id_socket = add_watch_or_die(channel_socket, G_IO_IN | G_IO_PRI | G_IO_HUP,
server_socket_cb);
}
@@ -753,7 +736,7 @@ int main(int argc, char** argv)
* on inotify read forever. Must set fd to non-blocking:
*/
ndelay_on(inotify_fd);
- channel_inotify = my_io_channel_unix_new(inotify_fd);
+ channel_inotify = abrt_gio_channel_unix_new(inotify_fd);
/*
* glib's read buffering must be disabled, or else
* FIONREAD-reported "available data" sizes and sizes of reads
@@ -767,7 +750,7 @@ int main(int argc, char** argv)
/* Add an event source which waits for INT/TERM signal */
VERB1 log("Adding signal pipe watch to glib main loop");
- channel_signal = my_io_channel_unix_new(s_signal_pipe[0]);
+ channel_signal = abrt_gio_channel_unix_new(s_signal_pipe[0]);
channel_id_signal_event = add_watch_or_die(channel_signal,
G_IO_IN | G_IO_PRI | G_IO_HUP,
handle_signal_cb);
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
index ab48d1c..6dce3cb 100644
--- a/src/dbus/abrt-dbus.c
+++ b/src/dbus/abrt-dbus.c
@@ -5,7 +5,7 @@
#include <grp.h>
#include "libabrt.h"
#include "abrt-polkit.h"
-#include "abrt-dbus.h"
+#include "abrt_glib.h"
#include <libreport/dump_dir.h>
#include "problem_api.h"
diff --git a/src/include/abrt-dbus.h b/src/include/abrt-dbus.h
index 93f5fb1..898dd94 100644
--- a/src/include/abrt-dbus.h
+++ b/src/include/abrt-dbus.h
@@ -5,8 +5,4 @@
#define ABRT_DBUS_OBJECT "/org/freedesktop/problems"
#define ABRT_DBUS_IFACE "org.freedesktop.problems"
-GList *string_list_from_variant(GVariant *variant);
-
-GVariant *variant_from_string_list(const GList *strings);
-
#endif /* ABRTDBUS_H_ */
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index b75cc23..c5a6e2f 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -11,6 +11,7 @@ libabrt_la_SOURCES = \
notify_new_path.c \
kernel.c \
abrt_glib.c \
+ abrt_glib.h \
migrate_dirs.c \
check_recent_crash_file.c \
problem_api.c \
diff --git a/src/lib/abrt_glib.c b/src/lib/abrt_glib.c
index bf88d4c..1104ca2 100644
--- a/src/lib/abrt_glib.c
+++ b/src/lib/abrt_glib.c
@@ -16,7 +16,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <glib-2.0/glib.h>
+#include "abrt_glib.h"
#include "libabrt.h"
GList *string_list_from_variant(GVariant *variant)
@@ -54,3 +54,21 @@ GVariant *variant_from_string_list(const GList *strings)
return variant;
}
+
+GIOChannel *abrt_gio_channel_unix_new(int fd)
+{
+ GIOChannel *ch = g_io_channel_unix_new(fd);
+
+ /* Need to set the encoding otherwise we get:
+ * "Invalid byte sequence in conversion input".
+ * According to manual "NULL" is safe for binary data.
+ */
+ GError *error = NULL;
+ g_io_channel_set_encoding(ch, NULL, &error);
+ if (error)
+ perror_msg_and_die("Can't set encoding on gio channel: %s",
error->message);
+
+ g_io_channel_set_close_on_unref(ch, TRUE);
+
+ return ch;
+}
diff --git a/src/lib/abrt_glib.h b/src/lib/abrt_glib.h
new file mode 100644
index 0000000..5c1fe4f
--- /dev/null
+++ b/src/lib/abrt_glib.h
@@ -0,0 +1,30 @@
+/*
+ Copyright (C) 2013 ABRT team
+ Copyright (C) 2013 RedHat Inc
+
+ 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 2 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef _ABRT_GLIB_H_
+#define _ABRT_GLIB_H_
+
+#include <glib-2.0/glib.h>
+
+GList *string_list_from_variant(GVariant *variant);
+
+GVariant *variant_from_string_list(const GList *strings);
+
+GIOChannel *abrt_gio_channel_unix_new(int fd);
+
+#endif /*_ABRT_GLIB_H_*/
diff --git a/src/lib/problem_api_dbus.c b/src/lib/problem_api_dbus.c
index 04f4069..784a43f 100644
--- a/src/lib/problem_api_dbus.c
+++ b/src/lib/problem_api_dbus.c
@@ -17,6 +17,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "abrt_glib.h"
#include "libabrt.h"
static GDBusProxy *get_dbus_proxy(void)
--
1.8.3.1