diff options
-rw-r--r-- | src/applet/applet.c | 1 | ||||
-rw-r--r-- | src/cli/CLI.cpp | 15 | ||||
-rw-r--r-- | src/cli/Makefile.am | 3 | ||||
-rw-r--r-- | src/cli/dbus.cpp | 160 | ||||
-rw-r--r-- | src/cli/dbus.h | 30 | ||||
-rw-r--r-- | src/cli/report.cpp | 1 | ||||
-rw-r--r-- | src/daemon/CommLayerServerDBus.cpp | 6 | ||||
-rw-r--r-- | src/gui-gtk/Makefile.am | 6 | ||||
-rw-r--r-- | src/gui-gtk/abrt-gtk.c | 23 | ||||
-rw-r--r-- | src/gui-gtk/main.c | 30 | ||||
-rw-r--r-- | src/include/Makefile.am | 1 | ||||
-rw-r--r-- | src/include/dbus_common.h | 28 | ||||
-rw-r--r-- | src/lib/abrt_dbus.c | 177 | ||||
-rw-r--r-- | src/lib/abrt_dbus.h | 23 |
14 files changed, 261 insertions, 243 deletions
diff --git a/src/applet/applet.c b/src/applet/applet.c index 6f349160..1a2bf5c0 100644 --- a/src/applet/applet.c +++ b/src/applet/applet.c @@ -24,7 +24,6 @@ #include <dbus/dbus-glib-lowlevel.h> #include "abrtlib.h" #include "abrt_dbus.h" -#include "dbus_common.h" #include "applet_gtk.h" diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index e322e7cd..0e902b9e 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -21,9 +21,7 @@ #include <getopt.h> #include "abrtlib.h" #include "abrt_dbus.h" -#include "dbus_common.h" #include "report.h" -#include "dbus.h" /** Creates a localized string from crash time. */ static char *localize_crash_time(const char *timestr) @@ -410,11 +408,6 @@ int main(int argc, char** argv) print_usage_and_die(argv[0]); } - DBusError err; - dbus_error_init(&err); - s_dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); - handle_dbus_err(s_dbus_conn == NULL, &err); - /* Do the selected operation. */ int exitcode = 0; switch (op) @@ -469,12 +462,10 @@ int main(int argc, char** argv) } dd_close(dd); } + /* Ask abrtd to do it for us */ - exitcode = call_DeleteDebugDump(dump_dir_name); - if (exitcode == ENOENT) - error_msg_and_die("Crash '%s' not found", dump_dir_name); - if (exitcode != 0) - error_msg_and_die("Can't delete debug dump '%s'", dump_dir_name); + exitcode = connect_to_abrtd_and_call_DeleteDebugDump(dump_dir_name); + break; } case OPT_INFO: diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 41a600c6..0a5c6e1a 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -3,8 +3,7 @@ bin_PROGRAMS = abrt-cli abrt_cli_SOURCES = \ CLI.cpp \ run-command.h run-command.c \ - report.h report.cpp \ - dbus.h dbus.cpp + report.h report.cpp abrt_cli_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ diff --git a/src/cli/dbus.cpp b/src/cli/dbus.cpp deleted file mode 100644 index 9c2bfbd6..00000000 --- a/src/cli/dbus.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - 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.h" -#include "dbus_common.h" - -DBusConnection* s_dbus_conn; - -/* - * DBus member calls - */ - -/* helpers */ -static DBusMessage* new_call_msg(const char* method) -{ - DBusMessage* msg = dbus_message_new_method_call(ABRTD_DBUS_NAME, ABRTD_DBUS_PATH, ABRTD_DBUS_IFACE, method); - if (!msg) - die_out_of_memory(); - return msg; -} - -static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) -{ - dbus_uint32_t serial; - if (TRUE != dbus_connection_send(s_dbus_conn, msg, &serial)) - error_msg_and_die("Error sending DBus message"); - dbus_message_unref(msg); - - while (true) - { - DBusMessage *received = dbus_connection_pop_message(s_dbus_conn); - if (!received) - { - if (FALSE == dbus_connection_read_write(s_dbus_conn, -1)) - error_msg_and_die("dbus connection closed"); - continue; - } - - int tp = dbus_message_get_type(received); - const char *error_str = dbus_message_get_error_name(received); -#if 0 - /* Debugging */ - printf("type:%u (CALL:%u, RETURN:%u, ERROR:%u, SIGNAL:%u)\n", tp, - DBUS_MESSAGE_TYPE_METHOD_CALL, - DBUS_MESSAGE_TYPE_METHOD_RETURN, - DBUS_MESSAGE_TYPE_ERROR, - DBUS_MESSAGE_TYPE_SIGNAL - ); - const char *sender = dbus_message_get_sender(received); - if (sender) - printf("sender: %s\n", sender); - const char *path = dbus_message_get_path(received); - if (path) - printf("path: %s\n", path); - const char *member = dbus_message_get_member(received); - if (member) - printf("member: %s\n", member); - const char *interface = dbus_message_get_interface(received); - if (interface) - printf("interface: %s\n", interface); - const char *destination = dbus_message_get_destination(received); - if (destination) - printf("destination: %s\n", destination); - if (error_str) - printf("error: '%s'\n", error_str); -#endif - - DBusError err; - dbus_error_init(&err); - - if (dbus_message_is_signal(received, ABRTD_DBUS_IFACE, "Update")) - { - const char *update_msg; - if (!dbus_message_get_args(received, &err, - DBUS_TYPE_STRING, &update_msg, - DBUS_TYPE_INVALID)) - { - error_msg_and_die("dbus Update message: arguments mismatch"); - } - printf(">> %s\n", update_msg); - } - else if (dbus_message_is_signal(received, ABRTD_DBUS_IFACE, "Warning")) - { - const char *warning_msg; - if (!dbus_message_get_args(received, &err, - DBUS_TYPE_STRING, &warning_msg, - DBUS_TYPE_INVALID)) - { - error_msg_and_die("dbus Warning message: arguments mismatch"); - } - log(">! %s\n", warning_msg); - } - else - if (tp == DBUS_MESSAGE_TYPE_METHOD_RETURN - && dbus_message_get_reply_serial(received) == serial - ) { - return received; - } - else - if (tp == DBUS_MESSAGE_TYPE_ERROR - && dbus_message_get_reply_serial(received) == serial - ) { - error_msg_and_die("dbus call returned error: '%s'", error_str); - } - - dbus_message_unref(received); - } -} - -void handle_dbus_err(bool error_flag, DBusError *err) -{ - if (dbus_error_is_set(err)) - { - error_msg("dbus error: %s", err->message); - /* dbus_error_free(&err); */ - error_flag = true; - } - if (!error_flag) - return; - error_msg_and_die( - "error requesting DBus name %s, possible reasons: " - "abrt run by non-root; dbus config is incorrect; " - "or dbus daemon needs to be restarted to reload dbus config", - ABRTD_DBUS_NAME); -} - -int32_t call_DeleteDebugDump(const char* crash_id) -{ - DBusMessage* msg = new_call_msg(__func__ + 5); - dbus_message_append_args(msg, - DBUS_TYPE_STRING, &crash_id, - DBUS_TYPE_INVALID); - - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - int32_t result; - int r = load_val(&in_iter, result); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return result; -} diff --git a/src/cli/dbus.h b/src/cli/dbus.h deleted file mode 100644 index efaceca8..00000000 --- a/src/cli/dbus.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - 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 ABRT_CLI_DBUS_H -#define ABRT_CLI_DBUS_H - -#include "abrt_dbus.h" -#include "abrt_crash_data.h" - -extern DBusConnection* s_dbus_conn; - -int32_t call_DeleteDebugDump(const char* crash_id); - -void handle_dbus_err(bool error_flag, DBusError *err); - -#endif diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 5c85fa28..7f317f05 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -17,7 +17,6 @@ */ #include "report.h" #include "run-command.h" -#include "dbus.h" #include "abrtlib.h" /* Field separator for the crash report file that is edited by user. */ diff --git a/src/daemon/CommLayerServerDBus.cpp b/src/daemon/CommLayerServerDBus.cpp index 84c2ea15..2a02b051 100644 --- a/src/daemon/CommLayerServerDBus.cpp +++ b/src/daemon/CommLayerServerDBus.cpp @@ -20,7 +20,6 @@ #include "abrtlib.h" #include "abrt_dbus.h" #include "comm_layer_inner.h" -#include "dbus_common.h" #include "MiddleWare.h" #include "Settings.h" #include "CommLayerServerDBus.h" @@ -524,6 +523,9 @@ int init_dbus() void deinit_dbus() { - if(g_dbus_conn != NULL) + if (g_dbus_conn != NULL) + { dbus_connection_unref(g_dbus_conn); + g_dbus_conn = NULL; + } } diff --git a/src/gui-gtk/Makefile.am b/src/gui-gtk/Makefile.am index 4a77b3f3..a0d0de40 100644 --- a/src/gui-gtk/Makefile.am +++ b/src/gui-gtk/Makefile.am @@ -14,9 +14,9 @@ abrt_gtk_CFLAGS = \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ -DICON_DIR=\"${datadir}/abrt/icons/hicolor/48x48/status\" \ $(GTK_CFLAGS) \ + $(DBUS_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror -# $(DBUS_CFLAGS) # -I/usr/include/glib-2.0 # -I/usr/lib/glib-2.0/include # $(LIBNOTIFY_CFLAGS) @@ -26,8 +26,8 @@ abrt_gtk_LDADD = \ ../lib/libabrt_dbus.la \ -lglib-2.0 \ -lgthread-2.0 \ - $(GTK_LIBS) -# $(DBUS_LIBS) + $(GTK_LIBS) \ + $(DBUS_LIBS) # $(LIBNOTIFY_LIBS) #test_report_SOURCES = \ diff --git a/src/gui-gtk/abrt-gtk.c b/src/gui-gtk/abrt-gtk.c index 42b18fb4..47e0277b 100644 --- a/src/gui-gtk/abrt-gtk.c +++ b/src/gui-gtk/abrt-gtk.c @@ -1,6 +1,7 @@ #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> #include "abrtlib.h" +#include "abrt_dbus.h" #include "abrt-gtk.h" static GtkListStore *dumps_list_store; @@ -91,7 +92,27 @@ static gint on_key_press_event_cb(GtkTreeView *treeview, GdkEventKey *key, gpoin { GValue d_dir = { 0 }; gtk_tree_model_get_value(store, &iter, COLUMN_DUMP_DIR, &d_dir); - g_print("CALL: del_event(%s)\n", g_value_get_string(&d_dir)); + const char *dump_dir_name = g_value_get_string(&d_dir); + + g_print("CALL: del_event(%s)\n", dump_dir_name); + + /* Try to delete it ourselves */ + struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); + if (dd) + { + if (dd->locked) /* it is not readonly */ + { + dd_delete(dd); + return TRUE; + } + dd_close(dd); + } + + /* Ask abrtd to do it for us */ + connect_to_abrtd_and_call_DeleteDebugDump(dump_dir_name); + +//TODO: refresh the list of crashes + } } diff --git a/src/gui-gtk/main.c b/src/gui-gtk/main.c index b18f854f..c933ac86 100644 --- a/src/gui-gtk/main.c +++ b/src/gui-gtk/main.c @@ -5,6 +5,8 @@ #define PROGNAME "abrt-gtk" +static DBusConnection* s_dbus_conn; + static void scan_directory_and_add_to_dirlist(const char *path) { DIR *dp = opendir(path); @@ -30,6 +32,34 @@ static void scan_directory_and_add_to_dirlist(const char *path) closedir(dp); } +void delete_dump_dir_possibly_via_dbus(const char *dump_dir_name) +{ + /* Try to delete it ourselves */ + struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); + if (dd) + { + if (dd->locked) /* it is not readonly */ + { + dd_delete(dd); + break; + } + dd_close(dd); + } + + /* Ask abrtd to do it for us */ + DBusError err; + dbus_error_init(&err); + s_dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + handle_dbus_err(s_dbus_conn == NULL, &err); + + exitcode = call_DeleteDebugDump(dump_dir_name); + if (exitcode == ENOENT) + error_msg_and_die("Crash '%s' not found", dump_dir_name); + if (exitcode != 0) + error_msg_and_die("Can't delete debug dump '%s'", dump_dir_name); + break; +} + int main(int argc, char **argv) { /* I18n */ diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 84e56d6d..477963c3 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -9,5 +9,4 @@ libabrt_include_HEADERS = \ abrtlib.h \ abrt_types.h \ abrt_crash_data.h \ - dbus_common.h \ xfuncs.h diff --git a/src/include/dbus_common.h b/src/include/dbus_common.h deleted file mode 100644 index 4e980d34..00000000 --- a/src/include/dbus_common.h +++ /dev/null @@ -1,28 +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 DBUSCOMMON_H_ -#define DBUSCOMMON_H_ - -#include "abrt_crash_data.h" - -#define ABRTD_DBUS_NAME "com.redhat.abrt" -#define ABRTD_DBUS_PATH "/com/redhat/abrt" -#define ABRTD_DBUS_IFACE "com.redhat.abrt" - -#endif diff --git a/src/lib/abrt_dbus.c b/src/lib/abrt_dbus.c index d1717636..28c2d0da 100644 --- a/src/lib/abrt_dbus.c +++ b/src/lib/abrt_dbus.c @@ -598,8 +598,29 @@ static void unregister_vtable(DBusConnection *conn, void* data) VERB3 log("%s()", __func__); } + +/* + * Simple logging handler for dbus errors. + */ +int log_dbus_error(const char *msg, DBusError *err) +{ + int ret = 0; + if (dbus_error_is_set(err)) + { + error_msg("dbus error: %s", err->message); + ret = 1; + } + if (msg) + { + error_msg(msg); + ret = 1; + } + return ret; +} + + /* - * Initialization works as follows: + * Initialization. Works as follows: * * we have a DBusConnection* (say, obtained with dbus_bus_get) * we call dbus_connection_set_watch_functions @@ -673,3 +694,157 @@ void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn, } } } + + +/* + * Support functions for clients + */ + +/* helpers */ +static DBusMessage* new_call_msg(const char* method) +{ + DBusMessage* msg = dbus_message_new_method_call(ABRTD_DBUS_NAME, ABRTD_DBUS_PATH, ABRTD_DBUS_IFACE, method); + if (!msg) + die_out_of_memory(); + return msg; +} + +static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) +{ + dbus_uint32_t serial; + if (TRUE != dbus_connection_send(g_dbus_conn, msg, &serial)) + error_msg_and_die("Error sending DBus message"); + dbus_message_unref(msg); + + while (true) + { + DBusMessage *received = dbus_connection_pop_message(g_dbus_conn); + if (!received) + { + if (FALSE == dbus_connection_read_write(g_dbus_conn, -1)) + error_msg_and_die("dbus connection closed"); + continue; + } + + int tp = dbus_message_get_type(received); + const char *error_str = dbus_message_get_error_name(received); +#if 0 + /* Debugging */ + printf("type:%u (CALL:%u, RETURN:%u, ERROR:%u, SIGNAL:%u)\n", tp, + DBUS_MESSAGE_TYPE_METHOD_CALL, + DBUS_MESSAGE_TYPE_METHOD_RETURN, + DBUS_MESSAGE_TYPE_ERROR, + DBUS_MESSAGE_TYPE_SIGNAL + ); + const char *sender = dbus_message_get_sender(received); + if (sender) + printf("sender: %s\n", sender); + const char *path = dbus_message_get_path(received); + if (path) + printf("path: %s\n", path); + const char *member = dbus_message_get_member(received); + if (member) + printf("member: %s\n", member); + const char *interface = dbus_message_get_interface(received); + if (interface) + printf("interface: %s\n", interface); + const char *destination = dbus_message_get_destination(received); + if (destination) + printf("destination: %s\n", destination); + if (error_str) + printf("error: '%s'\n", error_str); +#endif + + DBusError err; + dbus_error_init(&err); + + if (dbus_message_is_signal(received, ABRTD_DBUS_IFACE, "Update")) + { + const char *update_msg; + if (!dbus_message_get_args(received, &err, + DBUS_TYPE_STRING, &update_msg, + DBUS_TYPE_INVALID)) + { + error_msg_and_die("dbus Update message: arguments mismatch"); + } + printf(">> %s\n", update_msg); + } + else if (dbus_message_is_signal(received, ABRTD_DBUS_IFACE, "Warning")) + { + const char *warning_msg; + if (!dbus_message_get_args(received, &err, + DBUS_TYPE_STRING, &warning_msg, + DBUS_TYPE_INVALID)) + { + error_msg_and_die("dbus Warning message: arguments mismatch"); + } + log(">! %s\n", warning_msg); + } + else + if (tp == DBUS_MESSAGE_TYPE_METHOD_RETURN + && dbus_message_get_reply_serial(received) == serial + ) { + return received; + } + else + if (tp == DBUS_MESSAGE_TYPE_ERROR + && dbus_message_get_reply_serial(received) == serial + ) { + error_msg_and_die("dbus call returned error: '%s'", error_str); + } + + dbus_message_unref(received); + } +} + +int32_t call_DeleteDebugDump(const char *dump_dir_name) +{ + DBusMessage* msg = new_call_msg(__func__ + 5); + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &dump_dir_name, + DBUS_TYPE_INVALID); + + DBusMessage *reply = send_get_reply_and_unref(msg); + + DBusMessageIter in_iter; + dbus_message_iter_init(reply, &in_iter); + + int32_t result; + int r = load_int32(&in_iter, &result); + if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ + error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); + + dbus_message_unref(reply); + return result; +} + +int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name) +{ + DBusError err; + dbus_error_init(&err); + g_dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (log_dbus_error( + g_dbus_conn ? NULL : + "error requesting system DBus, possible reasons: " + "dbus config is incorrect; dbus-daemon is not running, " + "or dbus daemon needs to be restarted to reload dbus config", + &err + ) + ) { + if (g_dbus_conn) + dbus_connection_unref(g_dbus_conn); + g_dbus_conn = NULL; + return 1; + } + + int ret = call_DeleteDebugDump(dump_dir_name); + if (ret == ENOENT) + error_msg("Dump directory '%s' is not found", dump_dir_name); + else if (ret != 0) + error_msg("Can't delete dump directory '%s'", dump_dir_name); + + dbus_connection_unref(g_dbus_conn); + g_dbus_conn = NULL; + + return ret; +} diff --git a/src/lib/abrt_dbus.h b/src/lib/abrt_dbus.h index 09d69b39..dd07cb0c 100644 --- a/src/lib/abrt_dbus.h +++ b/src/lib/abrt_dbus.h @@ -23,6 +23,11 @@ #include "abrtlib.h" +#define ABRTD_DBUS_NAME "com.redhat.abrt" +#define ABRTD_DBUS_PATH "/com/redhat/abrt" +#define ABRTD_DBUS_IFACE "com.redhat.abrt" + + #ifdef __cplusplus extern "C" { #endif @@ -53,6 +58,7 @@ extern DBusConnection* g_dbus_conn; * // (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 + * dbus_connection_unref(conn); // if you don't want to *stay* connected * * - client which receives and processes signals: * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); @@ -73,6 +79,18 @@ void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn, DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data) ); +/* Log dbus error if err has it set. Then log msg if it's !NULL. + * In both cases return 1. Otherwise return 0. + */ +int log_dbus_error(const char *msg, DBusError *err); + +/* Perform "DeleteDebugDump" call over g_dbus_conn */ +int32_t call_DeleteDebugDump(const char *dump_dir_name); + +/* Connect to system bus, find abrtd, perform "DeleteDebugDump" call, close g_dbus_conn */ +int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name); + + /* * Helpers for building DBus messages */ @@ -114,7 +132,10 @@ int load_vector_of_crash_data(DBusMessageIter* iter, vector_of_crash_data_t **va #endif -/* C++ style stuff */ +/* + * C++ style stuff + */ + #ifdef __cplusplus #include <map> |