summaryrefslogtreecommitdiffstats
path: root/src/CLI
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2009-12-14 10:41:51 +0100
committerKarel Klic <kklic@redhat.com>2009-12-14 10:41:51 +0100
commita24d2906c51e3740e6e0acf8f0093827b4e35bc3 (patch)
tree1022bf70766a88d45dc71d6ea413ccd0fa14d07c /src/CLI
parentb7ea0e53e3375de6298b2f510302f75ebef4be4e (diff)
parent42f0375d09931903965b36c87f17f805def956bf (diff)
Merge branch 'master' of git://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/CLI')
-rw-r--r--src/CLI/ABRTSocket.h8
-rw-r--r--src/CLI/CLI.cpp15
-rw-r--r--src/CLI/dbus.cpp73
-rw-r--r--src/CLI/dbus.h14
-rw-r--r--src/CLI/report.cpp150
-rw-r--r--src/CLI/report.h2
6 files changed, 149 insertions, 113 deletions
diff --git a/src/CLI/ABRTSocket.h b/src/CLI/ABRTSocket.h
index 5d5383fa..c3a63e51 100644
--- a/src/CLI/ABRTSocket.h
+++ b/src/CLI/ABRTSocket.h
@@ -10,20 +10,20 @@ class CABRTSocket
private:
int m_nSocket;
- void Send(const std::string& pMessage);
+ void Send(const char *pMessage);
void Recv(std::string& pMessage);
public:
CABRTSocket();
~CABRTSocket();
- void Connect(const std::string& pPath);
+ void Connect(const char *pPath);
void Disconnect();
vector_crash_infos_t GetCrashInfos();
- map_crash_report_t CreateReport(const std::string& pUUID);
+ map_crash_report_t CreateReport(const char *pUUID);
void Report(const map_crash_report_t& pReport);
- void DeleteDebugDump(const std::string& pUUID);
+ int32_t DeleteDebugDump(const char *pUUID);
};
#endif /* ABRTSOCKET_H_ */
diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp
index 9f2db3f0..1ea3a5d6 100644
--- a/src/CLI/CLI.cpp
+++ b/src/CLI/CLI.cpp
@@ -131,7 +131,7 @@ int main(int argc, char** argv)
char* uuid = NULL;
int op = -1;
- setlocale(LC_ALL,"");
+ setlocale(LC_ALL, "");
#if ENABLE_NLS
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -183,6 +183,7 @@ int main(int argc, char** argv)
ABRTDaemon.Connect(VAR_RUN"/abrt.socket");
#endif
+ int exitcode = 0;
switch (op)
{
case OPT_GET_LIST:
@@ -193,14 +194,18 @@ int main(int argc, char** argv)
break;
}
case OPT_REPORT:
- report(uuid, false);
+ exitcode = report(uuid, false);
break;
case OPT_REPORT_ALWAYS:
- report(uuid, true);
+ exitcode = report(uuid, true);
break;
case OPT_DELETE:
{
- call_DeleteDebugDump(uuid);
+ if (call_DeleteDebugDump(uuid) != 0)
+ {
+ log("Can't delete debug dump with UUID '%s'", uuid);
+ exitcode = 1;
+ }
break;
}
}
@@ -209,5 +214,5 @@ int main(int argc, char** argv)
ABRTDaemon.Disconnect();
#endif
- return 0;
+ return exitcode;
}
diff --git a/src/CLI/dbus.cpp b/src/CLI/dbus.cpp
index 67c489e0..b2186798 100644
--- a/src/CLI/dbus.cpp
+++ b/src/CLI/dbus.cpp
@@ -106,79 +106,99 @@ static DBusMessage* send_get_reply_and_unref(DBusMessage* msg)
vector_crash_infos_t call_GetCrashInfos()
{
- DBusMessage* msg = new_call_msg("GetCrashInfos");
+ DBusMessage* msg = new_call_msg(__func__ + 5);
DBusMessage *reply = send_get_reply_and_unref(msg);
- vector_crash_infos_t argout;
DBusMessageIter in_iter;
dbus_message_iter_init(reply, &in_iter);
+
+ vector_crash_infos_t argout;
int r = load_val(&in_iter, argout);
if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */
- error_msg_and_die("dbus call %s: return type mismatch", "GetCrashInfos");
+ error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5);
+
dbus_message_unref(reply);
return argout;
}
map_crash_report_t call_CreateReport(const char* uuid)
{
- DBusMessage* msg = new_call_msg("CreateReport");
+ DBusMessage* msg = new_call_msg(__func__ + 5);
dbus_message_append_args(msg,
DBUS_TYPE_STRING, &uuid,
DBUS_TYPE_INVALID);
DBusMessage *reply = send_get_reply_and_unref(msg);
- map_crash_report_t argout;
DBusMessageIter in_iter;
dbus_message_iter_init(reply, &in_iter);
+
+ map_crash_report_t argout;
int r = load_val(&in_iter, argout);
if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */
- error_msg_and_die("dbus call %s: return type mismatch", "CreateReport");
+ error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5);
+
dbus_message_unref(reply);
return argout;
}
-void call_Report(const map_crash_report_t& report)
+report_status_t call_Report(const map_crash_report_t& report)
{
- DBusMessage* msg = new_call_msg("Report");
+ DBusMessage* msg = new_call_msg(__func__ + 5);
DBusMessageIter out_iter;
dbus_message_iter_init_append(msg, &out_iter);
store_val(&out_iter, report);
DBusMessage *reply = send_get_reply_and_unref(msg);
- //it returns a single value of report_status_t type,
- //but we don't use it (yet?)
+
+ DBusMessageIter in_iter;
+ dbus_message_iter_init(reply, &in_iter);
+
+ report_status_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;
}
-void call_DeleteDebugDump(const char* uuid)
+int32_t call_DeleteDebugDump(const char* uuid)
{
- DBusMessage* msg = new_call_msg("DeleteDebugDump");
+ DBusMessage* msg = new_call_msg(__func__ + 5);
dbus_message_append_args(msg,
DBUS_TYPE_STRING, &uuid,
DBUS_TYPE_INVALID);
DBusMessage *reply = send_get_reply_and_unref(msg);
- //it returns a single boolean value,
- //but we don't use it (yet?)
+
+ 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;
}
vector_map_string_t call_GetPluginsInfo()
{
- DBusMessage *msg = new_call_msg("GetPluginsInfo");
- DBusMessage *reply = send_get_reply_and_unref(msg);
-
- vector_map_string_t argout;
- DBusMessageIter in_iter;
- dbus_message_iter_init(reply, &in_iter);
- int r = load_val(&in_iter, argout);
- if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */
- error_msg_and_die("dbus call GetPluginsInfo: return type mismatch");
- dbus_message_unref(reply);
- return argout;
+ DBusMessage *msg = new_call_msg(__func__ + 5);
+ DBusMessage *reply = send_get_reply_and_unref(msg);
+
+ DBusMessageIter in_iter;
+ dbus_message_iter_init(reply, &in_iter);
+
+ vector_map_string_t argout;
+ int r = load_val(&in_iter, argout);
+ 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 argout;
}
void handle_dbus_err(bool error_flag, DBusError *err)
@@ -193,6 +213,7 @@ void handle_dbus_err(bool error_flag, DBusError *err)
return;
error_msg_and_die(
"error requesting DBus name %s, possible reasons: "
- "abrt run by non-root; dbus config is incorrect",
+ "abrt run by non-root; dbus config is incorrect; "
+ "or dbus daemon needs to be restarted to reload dbus config",
ABRTD_DBUS_NAME);
}
diff --git a/src/CLI/dbus.h b/src/CLI/dbus.h
index 48d391e6..3c157c01 100644
--- a/src/CLI/dbus.h
+++ b/src/CLI/dbus.h
@@ -23,21 +23,21 @@
extern DBusConnection* s_dbus_conn;
-extern vector_crash_infos_t call_GetCrashInfos();
-extern map_crash_report_t call_CreateReport(const char *uuid);
-extern void call_Report(const map_crash_report_t& report);
-extern void call_DeleteDebugDump(const char* uuid);
+vector_crash_infos_t call_GetCrashInfos();
+map_crash_report_t call_CreateReport(const char *uuid);
+report_status_t call_Report(const map_crash_report_t& report);
+int32_t call_DeleteDebugDump(const char* uuid);
/* Gets basic data about all installed plugins.
*/
-extern vector_map_string_t call_GetPluginsInfo();
+vector_map_string_t call_GetPluginsInfo();
/** Gets default plugin settings.
* @param name
* Corresponds to name obtained from call_GetPluginsInfo.
*/
-extern map_plugin_settings_t call_GetPluginSettings(const char *name);
+map_plugin_settings_t call_GetPluginSettings(const char *name);
-extern void handle_dbus_err(bool error_flag, DBusError *err);
+void handle_dbus_err(bool error_flag, DBusError *err);
#endif
diff --git a/src/CLI/report.cpp b/src/CLI/report.cpp
index ac80e481..bc8f9008 100644
--- a/src/CLI/report.cpp
+++ b/src/CLI/report.cpp
@@ -332,88 +332,98 @@ int report(const char *uuid, bool always)
{
// Ask for an initial report.
map_crash_report_t cr = call_CreateReport(uuid);
+//TODO: error check?
- if (always)
+ if (!always)
{
- // Send the report immediately.
- call_Report(cr);
- return 0;
- }
-
- /* Open a temporary file and write the crash report to it. */
- char filename[] = "/tmp/abrt-report.XXXXXX";
- int fd = mkstemp(filename);
- if (fd == -1)
- {
- error_msg("can't generate temporary file name");
- return 1;
- }
+ /* Open a temporary file and write the crash report to it. */
+ char filename[] = "/tmp/abrt-report.XXXXXX";
+ int fd = mkstemp(filename);
+ if (fd == -1)
+ {
+ error_msg("can't generate temporary file name");
+ return 1;
+ }
- FILE *fp = fdopen(fd, "w");
- if (!fp)
- {
- error_msg("can't open '%s' to save the crash report", filename);
- return 1;
- }
+ FILE *fp = fdopen(fd, "w");
+ if (!fp)
+ {
+ error_msg("can't open '%s' to save the crash report", filename);
+ return 1;
+ }
- write_crash_report(cr, fp);
+ write_crash_report(cr, fp);
- if (fclose(fp))
- {
- error_msg("can't close '%s'", filename);
- return 2;
- }
+ if (fclose(fp))
+ {
+ error_msg("can't close '%s'", filename);
+ return 2;
+ }
- // Start a text editor on the temporary file.
- launch_editor(filename);
+ // Start a text editor on the temporary file.
+ launch_editor(filename);
- // Read the file back and update the report from the file.
- fp = fopen(filename, "r");
- if (!fp)
- {
- error_msg("can't open '%s' to read the crash report", filename);
- return 1;
- }
+ // Read the file back and update the report from the file.
+ fp = fopen(filename, "r");
+ if (!fp)
+ {
+ error_msg("can't open '%s' to read the crash report", filename);
+ return 1;
+ }
- fseek(fp, 0, SEEK_END);
- long size = ftell(fp);
- fseek(fp, 0, SEEK_SET);
+ fseek(fp, 0, SEEK_END);
+ long size = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
- char *text = (char*)xmalloc(size + 1);
- if (fread(text, 1, size, fp) != size)
- {
- error_msg("can't read '%s'", filename);
- return 1;
+ char *text = (char*)xmalloc(size + 1);
+ if (fread(text, 1, size, fp) != size)
+ {
+ error_msg("can't read '%s'", filename);
+ return 1;
+ }
+ text[size] = '\0';
+ fclose(fp);
+
+ remove_comments_and_unescape(text);
+ // Updates the crash report from the file text.
+ int report_changed = read_crash_report(cr, text);
+ if (report_changed)
+ puts(_("\nThe report has been updated."));
+ else
+ puts(_("\nNo changes were detected in the report."));
+
+ free(text);
+
+ if (unlink(filename) != 0) // Delete the tempfile.
+ perror_msg("can't unlink %s", filename);
+
+ // Report only if the user is sure.
+ printf(_("Do you want to send the report? [y/N]: "));
+ fflush(NULL);
+ char answer[16] = "n";
+ fgets(answer, sizeof(answer), stdin);
+ if ((answer[0] | 0x20) != 'y')
+ {
+ puts(_("Crash report was not sent."));
+ return 0;
+ }
}
- text[size] = '\0';
- fclose(fp);
-
- remove_comments_and_unescape(text);
- // Updates the crash report from the file text.
- int report_changed = read_crash_report(cr, text);
- if (report_changed)
- puts(_("\nThe report has been updated."));
- else
- puts(_("\nNo changes were detected in the report."));
- free(text);
-
- if (unlink(filename) != 0) // Delete the tempfile.
- perror_msg("can't unlink %s", filename);
-
- // Report only if the user is sure.
- printf(_("Do 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')
+ int errors = 0;
+ int plugins = 0;
+ puts(_("Reporting..."));
+ report_status_t r = call_Report(cr);
+ report_status_t::iterator it = r.begin();
+ while (it != r.end())
{
- puts(_("Reporting..."));
- call_Report(cr);
- puts(_("Crash report was successfully sent."));
+ vector_string_t &v = it->second;
+ printf("%s: %s\n", it->first.c_str(), v[REPORT_STATUS_IDX_MSG].c_str());
+ plugins++;
+ if (v[REPORT_STATUS_IDX_FLAG] != "0")
+ errors++;
+ it++;
}
- else
- puts(_("Crash report was not sent."));
+ printf(_("Crash reported via %d plugins (%d errors)\n"), plugins, errors);
- return 0;
+ return errors != 0;
}
diff --git a/src/CLI/report.h b/src/CLI/report.h
index 888babf3..2969b650 100644
--- a/src/CLI/report.h
+++ b/src/CLI/report.h
@@ -19,6 +19,6 @@
#define ABRT_CLI_REPORT_H
/* Reports the crash with corresponding uuid over DBus. */
-extern int report(const char *uuid, bool always);
+int report(const char *uuid, bool always);
#endif