diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Applet/Applet.cpp | 250 | ||||
| -rw-r--r-- | src/Applet/CCApplet.cpp | 113 | ||||
| -rw-r--r-- | src/Applet/CCApplet.h | 22 | ||||
| -rw-r--r-- | src/Applet/DBusClientProxy.cpp | 252 | ||||
| -rw-r--r-- | src/Applet/DBusClientProxy.h | 109 | ||||
| -rw-r--r-- | src/Applet/Makefile.am | 9 | ||||
| -rw-r--r-- | src/CLI/CLI.cpp | 51 | ||||
| -rw-r--r-- | src/Daemon/CommLayerServerDBus.cpp | 7 | ||||
| -rw-r--r-- | src/Daemon/CommLayerServerSocket.cpp | 6 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 2 | ||||
| -rw-r--r-- | src/Daemon/Daemon.cpp | 1 | ||||
| -rw-r--r-- | src/Daemon/PluginManager.cpp | 15 | ||||
| -rw-r--r-- | src/Daemon/Settings.cpp | 2 | ||||
| -rw-r--r-- | src/Makefile.am | 2 |
14 files changed, 268 insertions, 573 deletions
diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp index cf58c7d..4d46e2d 100644 --- a/src/Applet/Applet.cpp +++ b/src/Applet/Applet.cpp @@ -17,95 +17,255 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "CCApplet.h" -#include <iostream> #include <dbus/dbus-shared.h> - +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-lowlevel.h> #if HAVE_CONFIG_H #include <config.h> #endif - #if HAVE_LOCALE_H #include <locale.h> #endif - #if ENABLE_NLS #include <libintl.h> #define _(S) gettext(S) #else #define _(S) (S) #endif +#include "abrtlib.h" +#include "abrt_dbus.h" +#include "DBusCommon.h" +#include "CCApplet.h" + -//@@global applet object -CApplet *applet; +static CApplet* applet; -static void -crash_notify_cb(const char* progname) + +static void Crash(DBusMessage* signal) { - const char *message = _("A crash in package %s has been detected!"); -#ifdef DEBUG - std::cerr << "Application " << progname << " has crashed!" << std::endl; -#endif - //applet->AddEvent(uid, std::string(progname)); + int r; + DBusMessageIter in_iter; + if (!dbus_message_iter_init(signal, &in_iter)) + { + /* signal has no parameters */ + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + const char* progname; + r = load_val(&in_iter, progname); + if (r != ABRT_DBUS_MORE_FIELDS) + { + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + const char* uid_str; + r = load_val(&in_iter, uid_str); + if (r != ABRT_DBUS_LAST_FIELD) + { + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + + //if (m_pSessionDBus->has_name("com.redhat.abrt.gui")) + // return; + uid_t uid_num = atoi(uid_str); + + if (uid_num != getuid()) + return; + + const char* message = _("A crash in package %s has been detected"); + //applet->AddEvent(uid, progname); applet->SetIconTooltip(message, progname); applet->ShowIcon(); applet->CrashNotify(message, progname); } -static void -quota_exceed_cb(const char* str) +static void QuotaExceed(DBusMessage* signal) { + int r; + DBusMessageIter in_iter; + if (!dbus_message_iter_init(signal, &in_iter)) + { + /* signal has no parameters */ + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + const char* str; + r = load_val(&in_iter, str); + if (r != ABRT_DBUS_LAST_FIELD) + { + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + + //if (m_pSessionDBus->has_name("com.redhat.abrt.gui")) + // return; applet->ShowIcon(); applet->CrashNotify("%s", str); } -int main(int argc, char **argv) +static void NameOwnerChanged(DBusMessage* signal) +{ + int r; + DBusMessageIter in_iter; + if (!dbus_message_iter_init(signal, &in_iter)) + { + /* signal has no parameters */ + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + const char* name; + r = load_val(&in_iter, name); + if (r != ABRT_DBUS_MORE_FIELDS) + { + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + + /* We are only interested in (dis)appearances of our daemon */ + if (strcmp(name, "com.redhat.abrt") != 0) + return; + + const char* old_owner; + r = load_val(&in_iter, old_owner); + if (r != ABRT_DBUS_MORE_FIELDS) + { + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + const char* new_owner; + r = load_val(&in_iter, new_owner); + if (r != ABRT_DBUS_LAST_FIELD) + { + error_msg("dbus signal %s: parameter type mismatch", __func__); + return; + } + + if (new_owner[0]) + applet->Enable(_("ABRT service has been started")); + else + applet->Disable(_("ABRT service is not running")); +} + +static DBusHandlerResult handle_message(DBusConnection* conn, DBusMessage* msg, void* user_data) +{ + const char* member = dbus_message_get_member(msg); + log("%s(member:'%s')", __func__, member); + + int type = dbus_message_get_type(msg); + if (type != DBUS_MESSAGE_TYPE_SIGNAL) + { + log("The message is not a signal. ignoring"); + return DBUS_HANDLER_RESULT_HANDLED; + } + + if (strcmp(member, "NameOwnerChanged") == 0) + NameOwnerChanged(msg); + else if (strcmp(member, "Crash") == 0) + Crash(msg); + else if (strcmp(member, "QuotaExceed") == 0) + QuotaExceed(msg); + + return DBUS_HANDLER_RESULT_HANDLED; +} + +//TODO: move to abrt_dbus.cpp +static void die_if_dbus_error(bool error_flag, DBusError* err, const char* msg) { - setlocale(LC_ALL,""); + if (dbus_error_is_set(err)) + { + error_msg("dbus error: %s", err->message); + /*dbus_error_free(&err); - why bother, we will exit in a microsecond */ + error_flag = true; + } + if (!error_flag) + return; + error_msg_and_die("%s", msg); +} +int main(int argc, char** argv) +{ + /* I18n */ + setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif - /* need to be thread safe */ + /* Need to be thread safe */ g_thread_init(NULL); gdk_threads_init(); gdk_threads_enter(); - gtk_init(&argc,&argv); - /* prevent zombies when we spawn abrt-gui */ - signal(SIGCHLD, SIG_IGN); - /* move to the DBusClient::connect */ - DBus::Glib::BusDispatcher dispatcher; - /* this should bind the dispatcher with mainloop */ - dispatcher.attach(NULL); - DBus::default_dispatcher = &dispatcher; - DBus::Connection session = DBus::Connection::SessionBus(); - //FIXME: possible race, but the dbus-c++ API won't let us check return value of request_name :( - if(session.has_name("com.redhat.abrt.applet")) + /* Parse options */ + int opt; + while ((opt = getopt(argc, argv, "dv")) != -1) { - //applet is already running - std::cerr << _("Applet is already running.") << std::endl; - return -1; - } - else - { - //applet is not running, so claim the name on the session bus - session.request_name("com.redhat.abrt.applet"); + switch (opt) + { + case 'v': + g_verbose++; + break; + default: + error_msg_and_die( + "Usage: abrt-applet [-v]\n" + "\nOptions:" + "\n\t-v\tVerbose" + ); + } } + gtk_init(&argc, &argv); + + /* Prevent zombies when we spawn abrt-gui */ + signal(SIGCHLD, SIG_IGN); + + /* Initialize our (dbus_abrt) machinery: hook _system_ dbus to glib main loop. + * (session bus is left to be handled by libnotify, see below) */ + DBusError err; + dbus_error_init(&err); + DBusConnection* system_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + die_if_dbus_error(system_conn == NULL, &err, "Can't connect to system dbus"); + attach_dbus_conn_to_glib_main_loop(system_conn); + if (!dbus_connection_add_filter(system_conn, handle_message, NULL, NULL)) + error_msg_and_die("Can't add dbus filter"); + /* which messages do we want to be fed to handle_message()? */ + //signal sender=org.freedesktop.DBus -> path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged + // string "com.redhat.abrt" + // string "" + // string ":1.70" + dbus_bus_add_match(system_conn, "type='signal',member='NameOwnerChanged'", &err); + die_if_dbus_error(false, &err, "Can't add dbus match"); + //signal sender=:1.73 -> path=/com/redhat/abrt; interface=com.redhat.abrt; member=Crash + // string "coreutils-7.2-3.fc11" + // string "0" + dbus_bus_add_match(system_conn, "type='signal',path='/com/redhat/abrt'", &err); + die_if_dbus_error(false, &err, "Can't add dbus match"); - DBus::Connection conn = DBus::Connection::SystemBus(); - applet = new CApplet(conn, session, CC_DBUS_PATH, CC_DBUS_NAME); - applet->ConnectCrashHandler(crash_notify_cb); - applet->ConnectQuotaExceedHandler(quota_exceed_cb); - if(!conn.has_name(CC_DBUS_NAME)) + /* Initialize GUI stuff. + * Note: inside CApplet ctor, libnotify hooks session dbus + * to glib main loop */ + applet = new CApplet; + /* dbus_abrt cannot handle more than one bus, and we don't really need to. + * The only thing we want to do is to announce ourself on session dbus */ + DBusConnection* session_conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + die_if_dbus_error(session_conn == NULL, &err, "Can't connect to session dbus"); + int r = dbus_bus_request_name(session_conn, + "com.redhat.abrt.applet", + /* flags */ DBUS_NAME_FLAG_DO_NOT_QUEUE, &err); + die_if_dbus_error(r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER, &err, + "Problem connecting to dbus, or applet is already running"); + + /* Show disabled icon if daemon is not running */ + if (!dbus_bus_name_has_owner(system_conn, CC_DBUS_NAME, &err)) { - std::cout << _("ABRT service is not running") << std::endl; - applet->Disable(_("ABRT service is not running")); + const char* msg = _("ABRT service is not running"); + puts(msg); + applet->Disable(msg); } + /* Enter main loop */ gtk_main(); + gdk_threads_leave(); delete applet; return 0; diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp index 7b1a7f1..6d841a5 100644 --- a/src/Applet/CCApplet.cpp +++ b/src/Applet/CCApplet.cpp @@ -17,31 +17,19 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "abrtlib.h" -#include "CCApplet.h" -#include <iostream> -#include <cstdarg> -#include <sstream> -#include <cstdio> -#include <unistd.h> - - - #if HAVE_CONFIG_H #include <config.h> #endif - #if ENABLE_NLS #include <libintl.h> #define _(S) gettext(S) #else #define _(S) (S) #endif +#include "abrtlib.h" +#include "CCApplet.h" - -static const char *DBUS_SERVICE_NAME = "org.freedesktop.DBus"; -static const char *DBUS_SERVICE_PATH = "/org/freedesktop/DBus"; const gchar *CApplet::menu_xml = "<?xml version=\"1.0\"?>\ <interface>\ @@ -118,12 +106,8 @@ You should have received a copy of the GNU General Public License along with thi </object>\ </interface>"; -CApplet::CApplet(DBus::Connection &system, DBus::Connection &session, const char *path, const char *name) -: DBus::ObjectProxy(system, path, name) +CApplet::CApplet() { - m_pSessionDBus = &session; - m_pDaemonWatcher = new DaemonWatcher(system, DBUS_SERVICE_PATH, DBUS_SERVICE_NAME); - m_pDaemonWatcher->ConnectStateChangeHandler(DaemonStateChange_cb, this); m_pStatusIcon = gtk_status_icon_new_from_stock(GTK_STOCK_DIALOG_WARNING); m_bDaemonRunning = true; notify_init("ABRT"); @@ -153,87 +137,17 @@ CApplet::CApplet(DBus::Connection &system, DBus::Connection &session, const char m_pAboutDialog = gtk_builder_get_object(m_pBuilder, "aboutdialog"); m_pmiAbout = gtk_builder_get_object(m_pBuilder, "miAbout"); { - g_signal_connect(m_pmiAbout,"activate",G_CALLBACK(CApplet::onAbout_cb),m_pAboutDialog); + g_signal_connect(m_pmiAbout, "activate", G_CALLBACK(CApplet::onAbout_cb),m_pAboutDialog); } } else { - fprintf(stderr,_("Can't create menu from the description, popup won't be available!\n")); + fprintf(stderr, _("Can't create menu from the description, popup won't be available!\n")); } } CApplet::~CApplet() { - delete m_pDaemonWatcher; -} - -/* dbus related */ -void CApplet::Crash(const std::string& progname, const std::string& uid ) -{ - if (m_pSessionDBus->has_name("com.redhat.abrt.gui")) - { - return; - } - else - { - if (m_pCrashHandler) - { - std::istringstream input_string(uid); - uid_t num; - input_string >> num; - - if (num == getuid()) - m_pCrashHandler(progname.c_str()); - } - else - { - std::cout << _("This is default handler, you should register your own with ConnectCrashHandler") << std::endl; - std::cout.flush(); - } - } -} - -void CApplet::QuotaExceed(const char* str) -{ - if (m_pSessionDBus->has_name("com.redhat.abrt.gui")) - { - return; - } - else - { - if(m_pQuotaExceedHandler) - { - m_pQuotaExceedHandler(str); - } - else - { - std::cout << _("This is default handler, you should register your own with ConnectQuotaExceedHandler") << std::endl; - std::cout.flush(); - } - } -} - -void CApplet::DaemonStateChange_cb(bool running, void* data) -{ - CApplet *applet = (CApplet *)data; - if (!running) - { - applet->Disable(_("ABRT service is not running")); - } - else - { - applet->Enable(_("ABRT service has been started")); - } -} - -void CApplet::ConnectCrashHandler(void (*pCrashHandler)(const char *progname)) -{ - m_pCrashHandler = pCrashHandler; -} - -void CApplet::ConnectQuotaExceedHandler(void (*pQuotaExceedHandler)(const char *progname)) -{ - m_pQuotaExceedHandler = pQuotaExceedHandler; } void CApplet::SetIconTooltip(const char *format, ...) @@ -251,10 +165,8 @@ void CApplet::SetIconTooltip(const char *format, ...) gtk_status_icon_set_tooltip_text(m_pStatusIcon, buf); free(buf); } - else - { - gtk_status_icon_set_tooltip_text(m_pStatusIcon, _("Out of memory")); - } + /* else: out of memory. Let's not do anything, + * or else it may only get worse */ } void CApplet::CrashNotify(const char *format, ...) @@ -270,7 +182,7 @@ void CApplet::CrashNotify(const char *format, ...) va_end(args); notify_notification_update(m_pNotification, _("Warning"), buf, NULL); - if (gtk_status_icon_is_embedded (m_pStatusIcon)) + if (gtk_status_icon_is_embedded(m_pStatusIcon)) notify_notification_show(m_pNotification, &err); if (err != NULL) g_print(err->message); @@ -283,7 +195,7 @@ void CApplet::OnAppletActivate_CB(GtkStatusIcon *status_icon,gpointer user_data) { pid_t pid = vfork(); if (pid < 0) - std::cerr << "vfork failed\n"; + perror_msg("vfork"); if (pid == 0) { /* child */ signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ @@ -291,8 +203,7 @@ void CApplet::OnAppletActivate_CB(GtkStatusIcon *status_icon,gpointer user_data) /* Did not find abrt-gui in installation directory. Oh well */ /* Trying to find it in PATH */ execlp("abrt-gui", "abrt-gui", (char*) NULL); - std::cerr << "can't exec abrt-gui\n"; - exit(1); + perror_msg_and_die("Can't exec abrt-gui"); } gtk_status_icon_set_visible(applet->m_pStatusIcon, false); } @@ -313,7 +224,7 @@ void CApplet::ShowIcon() { gtk_status_icon_set_visible(m_pStatusIcon, true); //Active wait for icon to be REALLY visible in status area - //while(!gtk_status_icon_is_embedded (m_pStatusIcon)); + //while(!gtk_status_icon_is_embedded(m_pStatusIcon)) continue; } void CApplet::onHide_cb(GtkMenuItem *menuitem, gpointer applet) @@ -348,7 +259,7 @@ void CApplet::Disable(const char *reason) gtk_status_icon_set_from_pixbuf(m_pStatusIcon, gray_scaled); } else - std::cerr << "Cannot load icon!" << std::endl; + error_msg("Can't load icon"); SetIconTooltip(reason); ShowIcon(); } diff --git a/src/Applet/CCApplet.h b/src/Applet/CCApplet.h index 6c020e1..285511a 100644 --- a/src/Applet/CCApplet.h +++ b/src/Applet/CCApplet.h @@ -23,13 +23,9 @@ #include <gtk/gtk.h> #include <map> #include <string> -#include <DBusClientProxy.h> #include <libnotify/notify.h> class CApplet -: public CDBusClient_proxy, - public DBus::IntrospectableProxy, - public DBus::ObjectProxy { private: static const gchar *menu_xml; @@ -44,11 +40,10 @@ class CApplet NotifyNotification *m_pNotification; std::map<int, std::string> m_mapEvents; - DaemonWatcher *m_pDaemonWatcher; bool m_bDaemonRunning; - DBus::Connection *m_pSessionDBus; + public: - CApplet(DBus::Connection &system, DBus::Connection &session, const char *path, const char *name); + CApplet(); ~CApplet(); void ShowIcon(); void HideIcon(); @@ -64,9 +59,6 @@ class CApplet // map:: int AddEvent(int pUUID, const std::string& pProgname); int RemoveEvent(int pUUID); - void ConnectCrashHandler(void (*pCrashHandler)(const char *progname)); - void ConnectQuotaExceedHandler(void (*pQuotaExeedHandler)(const char *str)); - static void DaemonStateChange_cb(bool running, void* data); protected: //@@TODO applet menus @@ -77,14 +69,6 @@ class CApplet gpointer user_data); static void onHide_cb(GtkMenuItem *menuitem, gpointer applet); static void onAbout_cb(GtkMenuItem *menuitem, gpointer applet); - private: - /* dbus stuff */ - void Crash(const std::string& progname, const std::string& uid); - void QuotaExceed(const char* str); - - /* the real signal handler called to handle the signal */ - void (*m_pCrashHandler)(const char *progname); - void (*m_pQuotaExceedHandler)(const char *str); }; -#endif /*CC_APPLET_H_*/ +#endif diff --git a/src/Applet/DBusClientProxy.cpp b/src/Applet/DBusClientProxy.cpp deleted file mode 100644 index afa89fc..0000000 --- a/src/Applet/DBusClientProxy.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - 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 "DBusClientProxy.h" -#include <iostream> - -namespace org { -namespace freedesktop { -namespace DBus { - -/* class DaemonWatcher_proxy */ - -/* public: */ - -DaemonWatcher_proxy::DaemonWatcher_proxy() -: ::DBus::InterfaceProxy("org.freedesktop.DBus") -{ - m_pStateChangeHandler_cb_data = NULL; - m_pStateChangeHandler = NULL; - connect_signal(DaemonWatcher_proxy, NameOwnerChanged, _DaemonStateChanged); -} - -void DaemonWatcher_proxy::ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data) -{ - m_pStateChangeHandler_cb_data = cb_data; - m_pStateChangeHandler = pStateChangeHandler; -} - -/* private: */ - -/* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ -void DaemonWatcher_proxy::_DaemonStateChanged(const ::DBus::SignalMessage &sig) -{ - ::DBus::MessageIter ri = sig.reader(); - std::string name; - std::string old_owner; - std::string new_owner; - ri >> name; - ri >> old_owner; - ri >> new_owner; - if(name.compare("com.redhat.abrt") == 0) - { - if(new_owner.length() > 0) - { - if(m_pStateChangeHandler) - { - m_pStateChangeHandler(true,m_pStateChangeHandler_cb_data); - } - else - { - std::cout << "Daemon appeared!" << std::endl; - } - } - if(new_owner.length() == 0) - { - if(m_pStateChangeHandler) - { - m_pStateChangeHandler(false, m_pStateChangeHandler_cb_data); - } - else - { - std::cout << "Daemon dissapeared!" << std::endl; - } - } - } -} - -} } } /* closing namespaces */ - - -/* class DaemonWatcher */ - -/* public: */ - -DaemonWatcher::DaemonWatcher(DBus::Connection &connection, const char *path, const char *name) -: ::DBus::ObjectProxy(connection, path, name) -{ -} -DaemonWatcher::~DaemonWatcher() -{ - std::cout << "~DaemonWatcher" << std::endl; -} - - -/* class CDBusClient_proxy */ - -/* public: */ - -CDBusClient_proxy::CDBusClient_proxy() -: DBus::InterfaceProxy(CC_DBUS_IFACE) -{ - connect_signal(CDBusClient_proxy, Crash, _Crash_stub); - connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); - connect_signal(CDBusClient_proxy, QuotaExceed, _QuotaExceed_stub); - m_sConnName = ""; -} - -CDBusClient_proxy::CDBusClient_proxy(::DBus::Connection &pConnection) -: DBus::InterfaceProxy(CC_DBUS_IFACE) -{ - gloop = g_main_loop_new(NULL, false); - //# define connect_signal(interface, signal, callback) - connect_signal(CDBusClient_proxy, Crash, _Crash_stub); - connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); - connect_signal(CDBusClient_proxy, QuotaExceed, _QuotaExceed_stub); - m_sConnName = pConnection.unique_name(); -} - -/* methods exported by this interface, - * this functions will invoke the corresponding methods on the remote objects - */ - /* - - < - <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> - <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> - <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> - ... - > - */ -vector_crash_infos_t CDBusClient_proxy::GetCrashInfos() -{ - DBus::CallMessage call; - DBus::MessageIter wi = call.writer(); - - call.member("GetCrashInfos"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - - vector_crash_infos_t argout; - ri >> argout; - return argout; -} - -bool CDBusClient_proxy::DeleteDebugDump(const std::string& pUUID) -{ - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pUUID; - call.member("DeleteDebugDump"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - - bool argout; - ri >> argout; - return argout; -} - -map_crash_report_t CDBusClient_proxy::CreateReport(const std::string& pUUID) -{ - m_bJobDone = false; - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pUUID; - call.member("CreateReport"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - ri >> m_iPendingJobID; - //FIXME: what if the report is created before we start the loop? (we miss the signal and get stuck in the loop) - g_main_loop_run(gloop); - return GetJobResult(m_iPendingJobID); -}; - -void CDBusClient_proxy::Report(const map_crash_report_t& pReport) -{ - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pReport; - call.member("Report"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); -} - -map_crash_report_t CDBusClient_proxy::GetJobResult(uint64_t pJobID) -{ - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pJobID; - call.member("GetJobResult"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - map_crash_report_t argout; - ri >> argout; - return argout; -} - -/* signal handlers for this interface - */ -void CDBusClient_proxy::Crash(const std::string& progname, const std::string& uid) -{ -} - -void CDBusClient_proxy::QuotaExceed(const char* str) -{ -} -/* private: */ - -/* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ -void CDBusClient_proxy::_Crash_stub(const ::DBus::SignalMessage &sig) -{ - DBus::MessageIter ri = sig.reader(); - - std::string progname; ri >> progname; - std::string uid; ri >> uid; - Crash(progname, uid); -} - -void CDBusClient_proxy::_JobDone_stub(const ::DBus::SignalMessage &sig) -{ - DBus::MessageIter ri = sig.reader(); - std::string dest; - ri >> dest; - if(m_sConnName == dest) - { - ri >> m_iPendingJobID; - g_main_loop_quit(gloop); - } -} - -void CDBusClient_proxy::_QuotaExceed_stub(const ::DBus::SignalMessage &sig) -{ - DBus::MessageIter ri = sig.reader(); - std::string str; - ri >> str; - QuotaExceed(str.c_str()); -} diff --git a/src/Applet/DBusClientProxy.h b/src/Applet/DBusClientProxy.h deleted file mode 100644 index 8cf5155..0000000 --- a/src/Applet/DBusClientProxy.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - 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. - */ -#ifndef DBUSCLIENTPROXY_H_ -#define DBUSCLIENTPROXY_H_ - -#include <dbus-c++/dbus.h> -#include <dbus-c++/glib-integration.h> -#include "DBusCommon.h" - -#define ABRT_NOT_RUNNING 0 -#define ABRT_RUNNING 1 - -namespace org { -namespace freedesktop { -namespace DBus { - -class DaemonWatcher_proxy -: public ::DBus::InterfaceProxy -{ -private: - void *m_pStateChangeHandler_cb_data; - void (*m_pStateChangeHandler)(bool running, void* data); - -public: - DaemonWatcher_proxy(); - void ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data); - -private: - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ - void _DaemonStateChanged(const ::DBus::SignalMessage &sig); -}; - -} } } - - -class DaemonWatcher -: public org::freedesktop::DBus::DaemonWatcher_proxy, - public DBus::IntrospectableProxy, - public DBus::ObjectProxy -{ -public: - - DaemonWatcher(DBus::Connection &connection, const char *path, const char *name); - ~DaemonWatcher(); -}; - - -class CDBusClient_proxy -: public DBus::InterfaceProxy -{ -private: - bool m_bJobDone; - uint64_t m_iPendingJobID; - GMainLoop *gloop; - std::string m_sConnName; - -public: - CDBusClient_proxy(); - CDBusClient_proxy(::DBus::Connection &pConnection); - -public: - /* methods exported by this interface, - * this functions will invoke the corresponding methods on the remote objects - */ - /* - < - <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> - <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> - <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> - ... - > - */ - vector_crash_infos_t GetCrashInfos(); - bool DeleteDebugDump(const std::string& pUUID); - map_crash_report_t CreateReport(const std::string& pUUID); - void Report(const map_crash_report_t& pReport); - map_crash_report_t GetJobResult(uint64_t pJobID); - -public: - /* signal handlers for this interface - */ - virtual void Crash(const std::string& progname, const std::string& uid); - virtual void QuotaExceed(const char* str); -private: - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ - void _Crash_stub(const ::DBus::SignalMessage &sig); - void _JobDone_stub(const ::DBus::SignalMessage &sig); - void _QuotaExceed_stub(const ::DBus::SignalMessage &sig); -}; - -#endif diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am index 67c1776..d098044 100644 --- a/src/Applet/Makefile.am +++ b/src/Applet/Makefile.am @@ -2,8 +2,7 @@ bin_PROGRAMS = abrt-applet abrt_applet_SOURCES = \ Applet.cpp \ - CCApplet.h CCApplet.cpp \ - DBusClientProxy.h DBusClientProxy.cpp + CCApplet.h CCApplet.cpp abrt_applet_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../../inc \ @@ -17,15 +16,15 @@ abrt_applet_CPPFLAGS = \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ $(GTK_CFLAGS) \ - $(DBUSCPP_CFLAGS) \ + $(DBUS_CFLAGS) \ -D_GNU_SOURCE # $(LIBNOTIFY_CFLAGS) -# $(DBUS_CFLAGS) # $(DBUS_GLIB_CFLAGS) abrt_applet_LDADD = \ + ../../lib/Utils/libABRTUtils.la \ -lglib-2.0 \ -lgthread-2.0 \ - $(DBUSCPP_LIBS) \ + $(DBUS_LIBS) \ $(LIBNOTIFY_LIBS) # ../../lib/Utils/libABRTUtils.la # $(DL_LIBS) diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp index 319bd0e..1fd0930 100644 --- a/src/CLI/CLI.cpp +++ b/src/CLI/CLI.cpp @@ -1,4 +1,3 @@ -#include <iostream> #include <getopt.h> #include "ABRTException.h" #include "ABRTSocket.h" @@ -18,20 +17,29 @@ enum static DBusConnection* s_dbus_conn; -static void print_crash_infos(const vector_crash_infos_t& pCrashInfos, int pMode) +static void print_crash_infos(vector_crash_infos_t& pCrashInfos, int pMode) { unsigned int ii; for (ii = 0; ii < pCrashInfos.size(); ii++) { - if (pCrashInfos[ii].find(CD_REPORTED)->second[CD_CONTENT] != "1" || pMode == GET_LIST_FULL) + map_crash_info_t& info = pCrashInfos[ii]; + if (pMode == GET_LIST_FULL || info.find(CD_REPORTED)->second[CD_CONTENT] != "1") { - std::cout << ii << ".\n"; - std::cout << "\tUID : " << pCrashInfos[ii].find(CD_UID)->second[CD_CONTENT] << std::endl; - std::cout << "\tUUID : " << pCrashInfos[ii].find(CD_UUID)->second[CD_CONTENT] << std::endl; - std::cout << "\tPackage : " << pCrashInfos[ii].find(CD_PACKAGE)->second[CD_CONTENT] << std::endl; - std::cout << "\tExecutable: " << pCrashInfos[ii].find(CD_EXECUTABLE)->second[CD_CONTENT] << std::endl; - std::cout << "\tCrash time: " << pCrashInfos[ii].find(CD_TIME)->second[CD_CONTENT] << std::endl; - std::cout << "\tCrash Rate: " << pCrashInfos[ii].find(CD_COUNT)->second[CD_CONTENT] << std::endl; + printf("%u.\n" + "\tUID : %s\n" + "\tUUID : %s\n" + "\tPackage : %s\n" + "\tExecutable: %s\n" + "\tCrash time: %s\n" + "\tCrash Rate: %s\n", + ii, + info[CD_UID][CD_CONTENT].c_str(), + info[CD_UUID][CD_CONTENT].c_str(), + info[CD_PACKAGE][CD_CONTENT].c_str(), + info[CD_EXECUTABLE][CD_CONTENT].c_str(), + info[CD_TIME][CD_CONTENT].c_str(), + info[CD_COUNT][CD_CONTENT].c_str() + ); } } } @@ -43,9 +51,9 @@ static void print_crash_report(const map_crash_report_t& pCrashReport) { if (it->second[CD_TYPE] != CD_SYS) { - std::cout << std::endl << it->first << std::endl; - std::cout << "-----" << std::endl; - std::cout << it->second[CD_CONTENT] << std::endl; + printf("\n%s\n" + "-----\n" + "%s\n", it->first.c_str(), it->second[CD_CONTENT].c_str()); } } } @@ -69,7 +77,7 @@ static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) DBusMessage *reply = dbus_connection_send_with_reply_and_block(s_dbus_conn, msg, /*timeout*/ -1, &err); if (reply == NULL) { -//analyse error +//TODO: analyse err error_msg_and_die("Error sending DBus message"); } dbus_message_unref(msg); @@ -205,12 +213,13 @@ int main(int argc, char** argv) else progname = argv[0]; /* note: message has embedded tabs */ - std::cout << "Usage: " << progname << " [OPTION]\n\n" + printf("Usage: %s [OPTION]\n\n" " --get-list print list of crashes which are not reported\n" " --get-list-full print list of all crashes\n" " --report UUID create and send a report\n" " --report-always UUID create and send a report without asking\n" - " --delete UUID delete crash\n"; + " --delete UUID delete crash\n", + progname); return 1; } if (c == -1) @@ -240,11 +249,11 @@ int main(int argc, char** argv) { map_crash_report_t cr = call_CreateReport(uuid); print_crash_report(cr); - std::cout << "\nDo you want to send the report? [y/n]: "; - std::flush(std::cout); - std::string answer = "n"; - std::cin >> answer; - if (answer == "Y" || answer == "y") + printf("\nDo you want to send the report? [y/n]: "); + fflush(NULL); + char answer[16] = "n"; + fgets(answer, sizeof(answer), stdin); + if (answer[0] == 'Y' || answer[0] == 'y') { call_Report(cr); } diff --git a/src/Daemon/CommLayerServerDBus.cpp b/src/Daemon/CommLayerServerDBus.cpp index 08cd3d5..f710fd9 100644 --- a/src/Daemon/CommLayerServerDBus.cpp +++ b/src/Daemon/CommLayerServerDBus.cpp @@ -430,7 +430,7 @@ static int handle_SetSettings(DBusMessage* call, DBusMessage* reply) */ /* Callback: "a message is received to a registered object path" */ -static DBusHandlerResult message_received(DBusConnection *conn, DBusMessage *msg, void* data) +static DBusHandlerResult message_received(DBusConnection* conn, DBusMessage* msg, void* data) { const char* member = dbus_message_get_member(msg); log("%s(method:'%s')", __func__, member); @@ -499,7 +499,7 @@ static void handle_dbus_err(bool error_flag, DBusError *err) if (!error_flag) return; error_msg_and_die( - "error requesting DBus name %s, possible reasons: " + "Error requesting DBus name %s, possible reasons: " "abrt run by non-root; dbus config is incorrect", CC_DBUS_NAME); } @@ -511,13 +511,14 @@ CCommLayerServerDBus::CCommLayerServerDBus() dbus_error_init(&err); VERB3 log("dbus_bus_get"); - g_dbus_conn = conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); handle_dbus_err(conn == NULL, &err); attach_dbus_conn_to_glib_main_loop(conn, "/com/redhat/abrt", message_received); VERB3 log("dbus_bus_request_name"); int rc = dbus_bus_request_name(conn, CC_DBUS_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err); +//maybe check that r == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER instead? handle_dbus_err(rc < 0, &err); VERB3 log("dbus init done"); } diff --git a/src/Daemon/CommLayerServerSocket.cpp b/src/Daemon/CommLayerServerSocket.cpp index b643aaa..6b62928 100644 --- a/src/Daemon/CommLayerServerSocket.cpp +++ b/src/Daemon/CommLayerServerSocket.cpp @@ -1,7 +1,5 @@ #include <sys/socket.h> #include <sys/un.h> -#include <iostream> -#include <sstream> #include "abrtlib.h" #include "CommLayerInner.h" #include "ABRTException.h" @@ -44,9 +42,7 @@ std::string CCommLayerServerSocket::GetSenderUID(int pSenderSocket) { throw CABRTException(EXCEP_ERROR, "CCommLayerServerSocket::GetSenderUID(): Error can get sender uid."); } - std::stringstream ss; - ss << creds.uid; - return ss.str(); + return to_string(creds.uid); } gboolean CCommLayerServerSocket::client_socket_cb(GIOChannel *source, GIOCondition condition, gpointer data) diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 826dc9e..5cc9dc7 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -17,8 +17,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include <iostream> -#include <sstream> #include "abrtlib.h" #include "Daemon.h" #include "ABRTException.h" diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 70f471c..3c48627 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -21,7 +21,6 @@ #include <sys/inotify.h> #include <glib.h> #include <pthread.h> -#include <iostream> #include <string> #if HAVE_CONFIG_H #include <config.h> diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp index be14f4b..a36d5a8 100644 --- a/src/Daemon/PluginManager.cpp +++ b/src/Daemon/PluginManager.cpp @@ -103,17 +103,16 @@ bool LoadPluginSettings(const std::string& pPath, map_plugin_settings_t& pSettin */ static bool SavePluginSettings(const std::string& pPath, const map_plugin_settings_t& pSettings) { - std::ofstream fOut; - fOut.open(pPath.c_str()); - if (fOut.is_open()) + FILE* fOut = fopen(pPath.c_str(), "w"); + if (fOut) { - fOut << "# Settings were written by abrt." << std::endl; - map_plugin_settings_t::const_iterator it; - for (it = pSettings.begin(); it != pSettings.end(); it++) + fprintf(fOut, "# Settings were written by abrt\n"); + map_plugin_settings_t::const_iterator it = pSettings.begin(); + for (; it != pSettings.end(); it++) { - fOut << it->first << " = " << it->second << std::endl; + fprintf(fOut, "%s = %s\n", it->first.c_str(), it->second.c_str()); } - fOut.close(); + fclose(fOut); return true; } return false; diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp index 90c8916..1eb4226 100644 --- a/src/Daemon/Settings.cpp +++ b/src/Daemon/Settings.cpp @@ -1,8 +1,8 @@ +#include <fstream> #include "Settings.h" #include "abrtlib.h" #include "abrt_types.h" #include "Polkit.h" -#include <fstream> #define SECTION_COMMON "Common" #define SECTION_ANALYZER_ACTIONS_AND_REPORTERS "AnalyzerActionsAndReporters" diff --git a/src/Makefile.am b/src/Makefile.am index 9269edb..2eb6c79 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1 @@ -SUBDIRS = Hooks Daemon Applet Gui CLI
\ No newline at end of file +SUBDIRS = Hooks Daemon Applet Gui CLI |
