summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-19 14:50:19 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-19 14:50:19 +0100
commite5fdb1cbef199fd48ed7615cc83383bc55a345fa (patch)
treede440078c55cce6be8d0e1f0204903949e957d8f /src
parent67a0890956d2c9878e2fdaf078c90551548b765c (diff)
downloadabrt-e5fdb1cbef199fd48ed7615cc83383bc55a345fa.tar.gz
abrt-e5fdb1cbef199fd48ed7615cc83383bc55a345fa.tar.xz
abrt-e5fdb1cbef199fd48ed7615cc83383bc55a345fa.zip
Moved dbus backend from dbus lib to daemon - better OO model.
Modified dbus policy config file to allow all users to call daemon's methods
Diffstat (limited to 'src')
-rw-r--r--src/Daemon/CrashWatcher.cpp56
-rw-r--r--src/Daemon/CrashWatcher.h17
-rw-r--r--src/Daemon/DBusCommon.h29
-rw-r--r--src/Daemon/DBusServerProxy.h131
-rw-r--r--src/Daemon/Daemon.cpp10
-rw-r--r--src/Daemon/Makefile.am8
-rw-r--r--src/Daemon/dbus-crashcatcher.conf25
7 files changed, 254 insertions, 22 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index a6eb487..bac6b2c 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -27,11 +27,21 @@
#include <fcntl.h>
#include <cstring>
#include <csignal>
+#include <sstream>
void terminate(int signal)
{
exit(0);
}
+/* just a helper function */
+template< class T >
+std::string
+to_string( T x )
+{
+ std::ostringstream o;
+ o << x;
+ return o.str();
+}
gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer daemon){
GIOError err;
@@ -61,11 +71,11 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition,
{
std::string sName = name;
CCrashWatcher *cc = (CCrashWatcher*)daemon;
- CMiddleWare::crash_info_t crashinfo;
+ crash_info_t crashinfo;
if(cc->m_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo))
{
/* send message to dbus */
- cc->m_pDbusServer->Crash(crashinfo.m_sPackage);
+ cc->Crash(crashinfo.m_sPackage);
}
}
#ifdef DEBUG
@@ -78,22 +88,16 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition,
return TRUE;
}
-CCrashWatcher::CCrashWatcher(const std::string& pPath)
+CCrashWatcher::CCrashWatcher(const std::string& pPath,DBus::Connection &connection)
+: DBus::ObjectAdaptor(connection, CC_DBUS_PATH)
{
+ m_pConn = &connection;
int watch = 0;
m_sTarget = pPath;
// middleware object
m_pMW = new CMiddleWare(PLUGINS_CONF_DIR,PLUGINS_LIB_DIR, std::string(CONF_DIR) + "/CrashCatcher.conf");
m_nMainloop = g_main_loop_new(NULL,FALSE);
- /* register on dbus */
- DBus::Glib::BusDispatcher *dispatcher;
- dispatcher = new DBus::Glib::BusDispatcher();
- dispatcher->attach(NULL);
- DBus::default_dispatcher = dispatcher;
- DBus::Connection conn = DBus::Connection::SystemBus();
-
- m_pDbusServer = new CDBusServer(conn,CC_DBUS_PATH);
- conn.request_name(CC_DBUS_NAME);
+ connection.request_name(CC_DBUS_NAME);
if((m_nFd = inotify_init()) == -1){
throw std::string("Init Failed");
//std::cerr << "Init Failed" << std::endl;
@@ -110,6 +114,34 @@ CCrashWatcher::~CCrashWatcher()
//delete dispatcher, connection, etc..
}
+dbus_vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID)
+{
+ dbus_vector_crash_infos_t retval;
+ vector_crash_infos_t crash_info;
+ m_pMW->GetCrashInfos("501");
+ for (vector_crash_infos_t::iterator it = crash_info.begin(); it!=crash_info.end(); ++it) {
+ std::cerr << it->m_sExecutable << std::endl;
+ }
+ return retval;
+}
+
+dbus_vector_map_crash_infos_t CCrashWatcher::GetCrashInfosMap(const std::string &pUID)
+{
+ dbus_vector_map_crash_infos_t retval;
+ vector_crash_infos_t crash_info;
+ std::cerr << pUID << std::endl;
+ unsigned long unix_uid = m_pConn->sender_unix_uid(pUID.c_str());
+ std::cerr << "Run by user with uid: " << unix_uid << std::endl;
+ crash_info = m_pMW->GetCrashInfos(to_string(unix_uid));
+ for (vector_crash_infos_t::iterator it = crash_info.begin(); it!=crash_info.end(); ++it) {
+ /* push the map with DB row into retval */
+ map_crash_t tmp = it->GetMap();
+ std::cout << "Time:" << tmp["Time"] << std::endl;
+ retval.push_back(it->GetMap());
+ }
+ return retval;
+}
+
void CCrashWatcher::Lock()
{
int lfp = open("crashcatcher.lock",O_RDWR|O_CREAT,0640);
diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h
index 92ef27f..bb3b3ee 100644
--- a/src/Daemon/CrashWatcher.h
+++ b/src/Daemon/CrashWatcher.h
@@ -25,7 +25,7 @@
#include <sys/inotify.h>
#include <glib.h>
//#include "DBusManager.h"
-#include "DBusServer.h"
+#include "DBusServerProxy.h"
#include "MiddleWare.h"
// 1024 simultaneous actions
@@ -33,6 +33,9 @@
class CCrashWatcher
+: public CDBusServer_adaptor,
+ public DBus::IntrospectableAdaptor,
+ public DBus::ObjectAdaptor
{
private:
static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer data);
@@ -41,21 +44,25 @@ class CCrashWatcher
void GStartWatch();
void Lock();
- //CDBusManager m_nDbus_manager;
- CDBusServer *m_pDbusServer;
int m_nFd;
GIOChannel* m_nGio;
GMainLoop *m_nMainloop;
std::string m_sTarget;
CMiddleWare *m_pMW;
+ DBus::Connection *m_pConn;
public:
- CCrashWatcher(const std::string& pPath);
- //CCrashWatcher();
+ CCrashWatcher(const std::string& pPath,DBus::Connection &connection);
~CCrashWatcher();
//run as daemon
void Daemonize();
//don't go background - for debug
void Run();
+
+ /* methods exported on dbus */
+ public:
+ dbus_vector_crash_infos_t GetCrashInfos(const std::string &pUID);
+ dbus_vector_map_crash_infos_t GetCrashInfosMap(const std::string &pUID);
+
};
#endif /*CRASHWATCHER_H_*/
diff --git a/src/Daemon/DBusCommon.h b/src/Daemon/DBusCommon.h
new file mode 100644
index 0000000..9504344
--- /dev/null
+++ b/src/Daemon/DBusCommon.h
@@ -0,0 +1,29 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 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.
+ */
+
+/* we need this to know the data structures */
+#include "MiddleWare.h"
+
+#define CC_DBUS_NAME "com.redhat.CrashCatcher"
+#define CC_DBUS_PATH "/com/redhat/CrashCatcher"
+#define CC_DBUS_IFACE "com.redhat.CrashCatcher"
+
+//typedef std::vector<crash_info_t> vector_crash_infos_t;
+typedef std::vector< std::vector<std::string> > dbus_vector_crash_infos_t;
+typedef std::vector< std::map<std::string, std::string> > dbus_vector_map_crash_infos_t;
diff --git a/src/Daemon/DBusServerProxy.h b/src/Daemon/DBusServerProxy.h
new file mode 100644
index 0000000..5b8f688
--- /dev/null
+++ b/src/Daemon/DBusServerProxy.h
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 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.
+ */
+
+#include <dbus-c++/dbus.h>
+#include <dbus-c++/glib-integration.h>
+#include "DBusCommon.h"
+
+class CDBusServer_adaptor
+: public DBus::InterfaceAdaptor
+{
+public:
+
+ CDBusServer_adaptor()
+ : DBus::InterfaceAdaptor(CC_DBUS_IFACE)
+ {
+ register_method(CDBusServer_adaptor, GetCrashInfos, _GetCrashInfos_stub);
+ register_method(CDBusServer_adaptor, GetCrashInfosMap, _GetCrashInfosMap_stub);
+ }
+/* reveal Interface introspection when we stabilize the API */
+/*
+ DBus::IntrospectedInterface *const introspect() const
+ {
+ static DBus::IntrospectedArgument GetCrashInfos_args[] =
+ {
+ //{ "uid", "i", true},
+ { "info", "a{ss}", false },
+ { 0, 0, 0 }
+ };
+ static DBus::IntrospectedArgument Crash_args[] =
+ {
+ { "package", "s", false },
+ { 0, 0, 0 }
+ };
+ static DBus::IntrospectedMethod CDBusServer_adaptor_methods[] =
+ {
+ { "GetCrashInfos", GetCrashInfos_args },
+ { 0, 0 },
+ { "GetCrashInfosMap", GetCrashInfos_args },
+ { 0, 0 }
+ };
+ static DBus::IntrospectedMethod CDBusServer_adaptor_signals[] =
+ {
+ { "Crash", Crash_args },
+ { 0, 0 }
+ };
+ static DBus::IntrospectedProperty CDBusServer_adaptor_properties[] =
+ {
+ { 0, 0, 0, 0 }
+ };
+ static DBus::IntrospectedInterface CDBusServer_adaptor_interface =
+ {
+ "com.redhat.CrashCatcher",
+ CDBusServer_adaptor_methods,
+ CDBusServer_adaptor_signals,
+ CDBusServer_adaptor_properties
+ };
+ return &CDBusServer_adaptor_interface;
+ }
+*/
+public:
+
+ /* properties exposed by this interface, use
+ * property() and property(value) to get and set a particular property
+ */
+
+public:
+
+ /* methods exported by this interface,
+ * you will have to implement them in your ObjectAdaptor
+ */
+ virtual dbus_vector_crash_infos_t GetCrashInfos(const std::string &pUID) = 0;
+ virtual dbus_vector_map_crash_infos_t GetCrashInfosMap(const std::string &pUID) = 0;
+
+public:
+
+ /* signal emitters for this interface
+ */
+ void Crash(const std::string& arg1)
+ {
+ ::DBus::SignalMessage sig("Crash");
+ ::DBus::MessageIter wi = sig.writer();
+ wi << arg1;
+ emit_signal(sig);
+ }
+
+
+private:
+
+ /* unmarshalers (to unpack the DBus message before calling the actual interface method)
+ */
+ DBus::Message _GetCrashInfos_stub(const DBus::CallMessage &call)
+ {
+ DBus::MessageIter ri = call.reader();
+
+ std::string argin1; ri >> argin1;
+ dbus_vector_crash_infos_t argout1 = GetCrashInfos(argin1);
+ DBus::ReturnMessage reply(call);
+ DBus::MessageIter wi = reply.writer();
+ wi << argout1;
+ return reply;
+ }
+
+ DBus::Message _GetCrashInfosMap_stub(const DBus::CallMessage &call)
+ {
+ DBus::MessageIter ri = call.reader();
+
+ std::string argin1; ri >> argin1;
+ dbus_vector_map_crash_infos_t argout1 = GetCrashInfosMap(call.sender());
+ DBus::ReturnMessage reply(call);
+ DBus::MessageIter wi = reply.writer();
+ wi << argout1;
+ return reply;
+ }
+};
+
diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp
index 2f0e575..2fa9823 100644
--- a/src/Daemon/Daemon.cpp
+++ b/src/Daemon/Daemon.cpp
@@ -19,12 +19,20 @@
#include "CrashWatcher.h"
#include <iostream>
+#include <cstdio>
#define daemonize 0
int main(int argc, char** argv){
+ /* connect to dbus */
+ DBus::Glib::BusDispatcher *dispatcher;
+ dispatcher = new DBus::Glib::BusDispatcher();
+ dispatcher->attach(NULL);
+ DBus::default_dispatcher = dispatcher;
+ DBus::Connection conn = DBus::Connection::SystemBus();
+
try{
- CCrashWatcher daemon(DEBUG_DUMPS_DIR);
+ CCrashWatcher daemon(DEBUG_DUMPS_DIR, conn);
//if (argc > 1){
// if (strcmp(argv[1], "-d") == 0){
// daemonize = 0;
diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am
index c562bb0..891ee26 100644
--- a/src/Daemon/Makefile.am
+++ b/src/Daemon/Makefile.am
@@ -1,9 +1,9 @@
bin_PROGRAMS = CrashCatcher
-CrashCatcher_SOURCES = CrashWatcher.cpp CrashWatcher.h Daemon.cpp
-CrashCatcher_CPPFLAGS = -I../../lib/MiddleWare\
- -I../../lib/DBus \
+CrashCatcher_SOURCES = CrashWatcher.cpp CrashWatcher.h DBusServerProxy.h DBusCommon.h Daemon.cpp
+CrashCatcher_CPPFLAGS = -I../../lib/MiddleWare \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(DBUS_GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \
-DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
-DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
-DCONF_DIR=\"$(CONF_DIR)\"
-CrashCatcher_LDADD = ../../lib/MiddleWare/libMiddleWare.la ../../lib/DBus/libDBus.la $(DL_LIBS)
+CrashCatcher_LDADD = ../../lib/MiddleWare/libMiddleWare.la $(DBUS_GLIB_LIBS) $(DBUSCPP_LIBS) $(DL_LIBS)
+
diff --git a/src/Daemon/dbus-crashcatcher.conf b/src/Daemon/dbus-crashcatcher.conf
new file mode 100644
index 0000000..d40e6c8
--- /dev/null
+++ b/src/Daemon/dbus-crashcatcher.conf
@@ -0,0 +1,25 @@
+<!-- This configuration file specifies the required security policies
+ for CrashCatcher core daemon to work. -->
+
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+
+ <!-- ../system.conf have denied everything, so we just punch some holes -->
+
+ <policy user="root">
+ <allow own="com.redhat.CrashCatcher"/>
+ <allow send_destination="com.redhat.CrashCatcher"/>
+ <allow send_interface="com.redhat.CrashCatcher"/>
+ </policy>
+
+ <policy at_console="true">
+ <allow send_destination="com.redhat.CrashCatcher"/>
+ </policy>
+
+ <!-- Allow anyone to invoke methods on CC server -->
+ <policy context="default">
+ <allow send_destination="com.redhat.CrashCatcher"/>
+ </policy>
+
+</busconfig>