From 43fe926f20bd427e96a22081deace10752bb4533 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Sep 2009 15:07:11 +0200 Subject: abrt-applet: remove dbus-c++ glue. -50k of code text data bss dec hex filename 70529 2144 1528 74201 121d9 abrt.t0/UNPACKED/usr/bin/abrt-applet 22116 1688 376 24180 5e74 abrt.t1/UNPACKED/usr/bin/abrt-applet Also, we do not use dbus-c++ anymore, which is 200k of code Signed-off-by: Denys Vlasenko --- lib/Utils/abrt_dbus.cpp | 4 ++++ lib/Utils/abrt_dbus.h | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Utils/abrt_dbus.cpp b/lib/Utils/abrt_dbus.cpp index 37d6d3e..ad23d56 100644 --- a/lib/Utils/abrt_dbus.cpp +++ b/lib/Utils/abrt_dbus.cpp @@ -264,6 +264,10 @@ void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn, const char* object_path, DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data) ) { + if (g_dbus_conn) + error_msg_and_die("Internal bug: can't connect to more than one dbus"); + g_dbus_conn = conn; + //do we need this? why? //log("dbus_connection_set_dispatch_status_function"); // dbus_connection_set_dispatch_status_function(conn, diff --git a/lib/Utils/abrt_dbus.h b/lib/Utils/abrt_dbus.h index 731f1c1..09063c5 100644 --- a/lib/Utils/abrt_dbus.h +++ b/lib/Utils/abrt_dbus.h @@ -8,8 +8,43 @@ extern DBusConnection* g_dbus_conn; /* * Glib integration machinery */ + +/* Hook up to DBus and to glib main loop. + * Usage cases: + * + * - server: + * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); + * attach_dbus_conn_to_glib_main_loop(conn, "/some/path", handler_of_calls_to_some_path); + * rc = dbus_bus_request_name(conn, "server.name", DBUS_NAME_FLAG_REPLACE_EXISTING, &err); + * + * - client which does not receive signals (only makes calls and emits signals): + * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); + * // needed only if you need to use async dbus calls (not shown below): + * attach_dbus_conn_to_glib_main_loop(conn); + * // syncronous method call: + * msg = dbus_message_new_method_call("some.serv", "/path/on/serv", "optional.iface.on.serv", "method_name"); + * reply = dbus_connection_send_with_reply_and_block(conn, msg, timeout, &err); + * // emitting signal: + * msg = dbus_message_new_signal("/path/sig/emitted/from", "iface.sig.emitted.from", "sig_name"); + * // (note: "iface.sig.emitted.from" is not optional for signals!) + * dbus_message_set_destination(msg, "peer"); // optional + * dbus_connection_send(conn, msg, &serial); // &serial can be NULL + * + * - client which receives and processes signals: + * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); + * attach_dbus_conn_to_glib_main_loop(conn); + * dbus_connection_add_filter(conn, handle_message, NULL, NULL) + * dbus_bus_add_match(system_conn, "type='signal',...", &err); + * // signal is a dbus message which looks like this: + * // sender=XXX dest=YYY(or null) path=/path/sig/emitted/from interface=iface.sig.emitted.from member=sig_name + * // and handler_for_signals(conn,msg,opaque) will be called by glib + * // main loop to process received signals (and other messages + * // if you ask for them in dbus_bus_add_match[es], but this + * // would turn you into a server if you handle them too) ;] + */ void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn, - const char* object_path_to_register = NULL, /* NULL if you are just a client */ + /* NULL if you are just a client */ + const char* object_path_to_register = NULL, /* makes sense only if you use object_path_to_register: */ DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data) = NULL ); -- cgit From 64be7b89afc0822cf24aeeec588ff5f5af5fe8b4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Sep 2009 17:32:01 +0200 Subject: remove a few C++-isms where they did not buy any convenience anyway text data bss dec hex filename 182372 2624 2320 187316 2dbb4 abrt.t2/abrt-0.0.8.5/src/Daemon/.libs/abrtd 180635 2584 1968 185187 2d363 abrt.t3/abrt-0.0.8.5/src/Daemon/.libs/abrtd 34110 1340 768 36218 8d7a abrt.t2/abrt-0.0.8.5/src/CLI/.libs/abrt-cli 30202 1292 224 31718 7be6 abrt.t3/abrt-0.0.8.5/src/CLI/.libs/abrt-cli 22116 1688 376 24180 5e74 abrt.t2/abrt-0.0.8.5/src/Applet/.libs/abrt-applet 21254 1648 88 22990 59ce abrt.t3/abrt-0.0.8.5/src/Applet/.libs/abrt-applet Signed-off-by: Denys Vlasenko --- lib/Utils/DebugDump.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 03fb7c6..4d6d92c 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -106,7 +106,6 @@ static int GetAndSetLock(const char* pLockFile, const char* pPID) if (errno != EEXIST) perror_msg_and_die("Can't create lock file '%s'", pLockFile); fd = open(pLockFile, O_RDONLY); -log("opened O_RDONLY: '%s'", pLockFile); if (fd < 0) { if (errno == ENOENT) @@ -125,7 +124,6 @@ log("opened O_RDONLY: '%s'", pLockFile); continue; } pid_buf[r] = '\0'; -log("read: '%s'", pid_buf); if (strcmp(pid_buf, pPID) == 0) { log("Lock file '%s' is already locked by us", pLockFile); @@ -143,7 +141,6 @@ log("read: '%s'", pid_buf); /* The file may be deleted by now by other process. Ignore errors */ unlink(pLockFile); } -log("created O_EXCL: '%s'", pLockFile); int len = strlen(pPID); if (write(fd, pPID, len) != len) @@ -331,10 +328,8 @@ void CDebugDump::SaveKernelArchitectureRelease() void CDebugDump::SaveTime() { - std::stringstream ss; time_t t = time(NULL); - ss << t; - SaveText(FILENAME_TIME, ss.str()); + SaveText(FILENAME_TIME, to_string(t)); } static void LoadTextFile(const std::string& pPath, std::string& pData) -- cgit From 1fd810c8cc2d166602374cf898b8f86e42e651e1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Sep 2009 18:14:28 +0200 Subject: remove a few #include 's Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 1 - lib/Plugins/CCpp.cpp | 13 ++++++------- lib/Plugins/FileTransfer.cpp | 1 - lib/Plugins/Kerneloops.cpp | 28 ++++++++++++++-------------- lib/Plugins/Mailx.cpp | 5 ++--- lib/Plugins/Python.cpp | 3 +-- lib/Plugins/SOSreport.cpp | 5 +---- lib/Plugins/SQLite3.cpp | 5 ++--- lib/Plugins/TicketUploader.cpp | 2 -- lib/Utils/CrashTypesSocket.cpp | 1 - lib/Utils/DebugDump.cpp | 1 - lib/Utils/Observer.h | 1 - 12 files changed, 26 insertions(+), 40 deletions(-) (limited to 'lib') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 9c223a6..a3c70f0 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -1,6 +1,5 @@ #include -#include #include "abrtlib.h" #include "Bugzilla.h" #include "CrashTypes.h" diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 19b4895..3276b24 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -19,20 +19,19 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "abrtlib.h" -#include "CCpp.h" -#include "ABRTException.h" -#include "DebugDump.h" -#include "CommLayerInner.h" -#include "Polkit.h" #include #include #include #include #include - #include #include +#include "abrtlib.h" +#include "CCpp.h" +#include "ABRTException.h" +#include "DebugDump.h" +#include "CommLayerInner.h" +#include "Polkit.h" #define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" #define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u" diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp index 9e2ee1a..9ae6501 100644 --- a/lib/Plugins/FileTransfer.cpp +++ b/lib/Plugins/FileTransfer.cpp @@ -23,7 +23,6 @@ #include #include #include - #include "abrtlib.h" #include "FileTransfer.h" #include "DebugDump.h" diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index 8e34392..e01bb42 100644 --- a/lib/Plugins/Kerneloops.cpp +++ b/lib/Plugins/Kerneloops.cpp @@ -24,38 +24,38 @@ * Arjan van de Ven */ +#include "abrtlib.h" #include "Kerneloops.h" #include "DebugDump.h" #include "ABRTException.h" #include "CommLayerInner.h" -#include - #define FILENAME_KERNELOOPS "kerneloops" std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir) { - update_client(_("Getting local/global universal unique identification...")); + log(_("Getting local universal unique identification")); - std::string m_sOops; - std::stringstream m_sHash; - CDebugDump m_pDebugDump; - m_pDebugDump.Open(pDebugDumpDir); - m_pDebugDump.LoadText(FILENAME_KERNELOOPS, m_sOops); - m_pDebugDump.Close(); + std::string oops; + { + CDebugDump dd; + dd.Open(pDebugDumpDir); + dd.LoadText(FILENAME_KERNELOOPS, oops); + } /* An algorithm proposed by Donald E. Knuth in The Art Of Computer * Programming Volume 3, under the topic of sorting and search * chapter 6.4. */ - unsigned int m_nHash = static_cast(m_sOops.length()); - for(std::size_t i = 0; i < m_sOops.length(); i++) + unsigned len = oops.length(); + unsigned hash = len; + for (unsigned i = 0; i < len; i++) { - m_nHash = ((m_nHash << 5) ^ (m_nHash >> 27)) ^ m_sOops[i]; + hash = ((hash << 5) ^ (hash >> 27)) ^ oops[i]; } - m_sHash << (m_nHash & 0x7FFFFFFF); + hash &= 0x7FFFFFFF; - return m_sHash.str(); + return to_string(hash); } std::string CAnalyzerKerneloops::GetGlobalUUID(const std::string& pDebugDumpDir) diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp index 8d00951..f7a86fd 100644 --- a/lib/Plugins/Mailx.cpp +++ b/lib/Plugins/Mailx.cpp @@ -20,10 +20,9 @@ */ -#include "Mailx.h" -#include "abrtlib.h" #include -#include +#include "abrtlib.h" +#include "Mailx.h" #include "DebugDump.h" #include "ABRTException.h" #include "CommLayerInner.h" diff --git a/lib/Plugins/Python.cpp b/lib/Plugins/Python.cpp index 3e6926c..9be76b3 100644 --- a/lib/Plugins/Python.cpp +++ b/lib/Plugins/Python.cpp @@ -1,7 +1,6 @@ +#include #include "Python.h" #include "DebugDump.h" - -#include #include "ABRTException.h" #define FILENAME_BACKTRACE "backtrace" diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp index 0e47ff8..ab6125c 100644 --- a/lib/Plugins/SOSreport.cpp +++ b/lib/Plugins/SOSreport.cpp @@ -18,15 +18,12 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "SOSreport.h" - #include #include #include - #include #include - +#include "SOSreport.h" #include "DebugDump.h" #include "ABRTException.h" #include "CommLayerInner.h" diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index 700ac91..797ed2d 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -20,11 +20,10 @@ */ #include -#include "SQLite3.h" #include -#include -#include "ABRTException.h" #include +#include "SQLite3.h" +#include "ABRTException.h" #define ABRT_TABLE_VERSION 2 diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp index db09b88..69243cd 100644 --- a/lib/Plugins/TicketUploader.cpp +++ b/lib/Plugins/TicketUploader.cpp @@ -490,5 +490,3 @@ PLUGIN_INFO(REPORTER, "gavin@redhat.com", "https://fedorahosted.org/abtr/wiki", PLUGINS_LIB_DIR"/TicketUploader.GTKBuilder"); - - diff --git a/lib/Utils/CrashTypesSocket.cpp b/lib/Utils/CrashTypesSocket.cpp index dbbc163..7c206de 100644 --- a/lib/Utils/CrashTypesSocket.cpp +++ b/lib/Utils/CrashTypesSocket.cpp @@ -21,7 +21,6 @@ #include "abrtlib.h" #include "CrashTypesSocket.h" -#include /** * A request GET_CRASH_INFOS has the following form: diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 4d6d92c..a36594b 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include "abrtlib.h" diff --git a/lib/Utils/Observer.h b/lib/Utils/Observer.h index 421dc0c..d6ec6f3 100644 --- a/lib/Utils/Observer.h +++ b/lib/Utils/Observer.h @@ -2,7 +2,6 @@ #define OBSERVER_H_ #include -#include #include #include "DBusCommon.h" -- cgit