summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-05-24 19:48:13 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-05-24 19:48:13 +0200
commit128381fc93e56cefb2b02b973a2ef3380594c91f (patch)
treed8a15bc542594c1e040c58f37b4504c02d819909
parent2e1d04e7dd85551e9d33c51bbd6008ac9b1b84c1 (diff)
downloadabrt-128381fc93e56cefb2b02b973a2ef3380594c91f.tar.gz
abrt-128381fc93e56cefb2b02b973a2ef3380594c91f.tar.xz
abrt-128381fc93e56cefb2b02b973a2ef3380594c91f.zip
include/report/report.h: change API from having more functions to having more flags
Now we have three functions instead of four: int report_problem_in_dir(const char *dirname, int flags); int report_problem_in_memory(problem_data_t *pd, int flags); int report_problem(problem_data_t *pd); (third one is a trivial wrapper around report_problem_in_memory), and two new flags LIBREPORT_ANALYZE and LIBREPORT_RELOAD_DATA. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--src/applet/applet_gtk.c4
-rw-r--r--src/gui-gtk/abrt-gtk.c11
-rw-r--r--src/include/report/report.h29
-rw-r--r--src/lib/report.c103
4 files changed, 47 insertions, 100 deletions
diff --git a/src/applet/applet_gtk.c b/src/applet/applet_gtk.c
index 74347963..9e3c68f7 100644
--- a/src/applet/applet_gtk.c
+++ b/src/applet/applet_gtk.c
@@ -86,7 +86,8 @@ static void action_report(NotifyNotification *notification, gchar *action, gpoin
struct applet *applet = (struct applet *)user_data;
if (applet->ap_daemon_running)
{
- analyze_and_report_dir(applet->ap_last_crash_id, LIBREPORT_NOWAIT);
+ report_problem_in_dir(applet->ap_last_crash_id, LIBREPORT_ANALYZE | LIBREPORT_NOWAIT);
+
GError *err = NULL;
notify_notification_close(notification, &err);
if (err != NULL)
@@ -94,6 +95,7 @@ static void action_report(NotifyNotification *notification, gchar *action, gpoin
error_msg("%s", err->message);
g_error_free(err);
}
+
hide_icon(applet);
stop_animate_icon(applet);
}
diff --git a/src/gui-gtk/abrt-gtk.c b/src/gui-gtk/abrt-gtk.c
index f6e9c5c2..a3bf1cab 100644
--- a/src/gui-gtk/abrt-gtk.c
+++ b/src/gui-gtk/abrt-gtk.c
@@ -108,8 +108,8 @@ static void on_row_activated_cb(GtkTreeView *treeview, GtkTreePath *path, GtkTre
GValue d_dir = { 0 };
gtk_tree_model_get_value(store, &iter, COLUMN_DUMP_DIR, &d_dir);
- const char *dirname= g_value_get_string(&d_dir);
- analyze_and_report_dir(dirname, LIBREPORT_NOWAIT);
+ const char *dirname = g_value_get_string(&d_dir);
+ report_problem_in_dir(dirname, LIBREPORT_ANALYZE | LIBREPORT_NOWAIT);
}
}
}
@@ -203,8 +203,11 @@ static void on_button_send_cb(GtkWidget *button, gpointer data)
/* why it doesn't want to hide before report ends? */
gtk_widget_destroy(s_report_window);
- int status = report(pd);
- VERB1 log("Reporting finished with status: %i", status);
+//TODO: LIBREPORT_WAIT is used here only because we don't want to leave temp dir.
+//Change to LIBREPORT_NOWAIT when libreport is taught to
+//properly delete temp dir even with LIBREPORT_NOWAIT.
+ int status = report_problem_in_memory(pd, LIBREPORT_WAIT);
+ VERB1 log("Reporting finished with status %i", status);
free_problem_data(pd);
}
diff --git a/src/include/report/report.h b/src/include/report/report.h
index e441875b..269866b2 100644
--- a/src/include/report/report.h
+++ b/src/include/report/report.h
@@ -22,28 +22,21 @@
#include "problem_data.h"
enum {
- LIBREPORT_NOWAIT = 0,
- LIBREPORT_WAIT = (1 << 0), /* wait for report to finish and reload the problem data */
+ LIBREPORT_NOWAIT = 0,
+ LIBREPORT_WAIT = (1 << 0), /* wait for report to finish and reload the problem data */
+ LIBREPORT_ANALYZE = (1 << 1), /* run analyzers? */
+ /* ("run reporters" is always on, has no flag (for now?)) */
+ LIBREPORT_RELOAD_DATA = (1 << 3), /* reload problem data after run (needs WAIT) */
};
+int report_problem_in_dir(const char *dirname, int flags);
-/* analyzes AND reports a problem saved on disk
- * - takes user through all the steps in reporting wizard
+/* Reports a problem stored in problem_data_t.
+ * It's first saved to /tmp and then processed as a dump dir.
*/
-int analyze_and_report_dir(const char* dirname, int flags);
+int report_problem_in_memory(problem_data_t *pd, int flags);
-/* analyzes AND reports a problem stored in problem_data_t
- * it's first saved to /tmp and then processed as a dump_dir
- * - takes user through all the steps in reporting wizard
- */
-int analyze_and_report(problem_data_t *pd, int flags);
-
-/* reports a problem saved on disk
- * - shows only reporter selector and progress
-*/
-int report_dir(const char* dirname);
-
-/* to report a problem stored in memory */
-int report(problem_data_t *pd);
+/* Simple wrapper for trivial uses */
+int report_problem(problem_data_t *pd);
#endif /* REPORT_H_ */
diff --git a/src/lib/report.c b/src/lib/report.c
index 99a3f919..07299e48 100644
--- a/src/lib/report.c
+++ b/src/lib/report.c
@@ -20,7 +20,7 @@
#include "abrtlib.h"
#include "report.h"
-static int run_reporter_ui(char **args, int flags)
+int report_problem_in_dir(const char *dirname, int flags)
{
const char *path;
/*
@@ -29,6 +29,15 @@ static int run_reporter_ui(char **args, int flags)
path = "cli"
*/
+ char *args[5], **pp;
+ pp = args;
+ *pp++ = (char *)"bug-reporting-wizard";
+ if (!(flags & LIBREPORT_ANALYZE))
+ *pp++ = (char *)"--report-only";
+ *pp++ = (char *)"--";
+ *pp++ = (char *)dirname;
+ *pp++ = NULL;
+
pid_t pid = vfork();
if (pid < 0) /* error */
{
@@ -79,22 +88,7 @@ static int run_reporter_ui(char **args, int flags)
return 0;
}
-int analyze_and_report_dir(const char* dirname, int flags)
-{
- char *args[4];
-
- args[0] = (char *)"bug-reporting-wizard";
- args[1] = (char *)"--";
- args[2] = (char *)dirname;
- args[3] = NULL;
-
- return run_reporter_ui(args, flags);
-}
-
-/* analyzes AND reports a problem saved on disk
- * - takes user through all the steps in reporting wizard
- */
-int analyze_and_report(problem_data_t *pd, int flags)
+int report_problem_in_memory(problem_data_t *pd, int flags)
{
int result = 0;
struct dump_dir *dd = create_dump_dir_from_problem_data(pd, "/tmp"/* /var/tmp ?? */);
@@ -103,78 +97,33 @@ int analyze_and_report(problem_data_t *pd, int flags)
char *dir_name = xstrdup(dd->dd_dirname);
dd_close(dd);
VERB2 log("Temp problem dir: '%s'", dir_name);
- result = analyze_and_report_dir(dir_name, flags);
- /* if we wait for reporter to finish, we can clean the tmp dir
- * and we should reload the problem data, so caller doesn't see the stalled
- * data
- */
+// TODO: if !LIBREPORT_WAIT pass LIBREPORT_DEL_DIR, and teach bug-reporting-wizard
+// an option to delete directory after reporting?
+// It will make !LIBREPORT_WAIT reporting possible
+ result = report_problem_in_dir(dir_name, flags);
+
+ /* If we wait for reporter to finish, we should clean the tmp dir.
+ * We can also reload the problem data if requested.
+ */
if (flags & LIBREPORT_WAIT)
{
- g_hash_table_remove_all(pd);
+ if (flags & LIBREPORT_RELOAD_DATA)
+ g_hash_table_remove_all(pd);
dd = dd_opendir(dir_name, 0);
if (dd)
{
- load_problem_data_from_dump_dir(pd, dd);
+ if (flags & LIBREPORT_RELOAD_DATA)
+ load_problem_data_from_dump_dir(pd, dd);
dd_delete(dd);
}
}
+
free(dir_name);
return result;
}
-/* report() and report_dir() don't take flags, because in all known use-cases
- * it doesn't make sense to not wait for the result
- *
-*/
-
-/* reports a problem saved on disk
- * - shows only reporter selector and progress
-*/
-int report_dir(const char* dirname)
+int report_problem(problem_data_t *pd)
{
- char *args[5];
-
- args[0] = (char *)"bug-reporting-wizard";
- args[1] = (char *)"--report-only";
- args[2] = (char *)"--";
- args[3] = (char *)dirname;
- args[4] = NULL;
-
- int flags = LIBREPORT_WAIT;
- int status = run_reporter_ui(args, flags);
- return status;
-}
-
-int report(problem_data_t *pd)
-{
- /* adds:
- * analyzer:libreport
- * executable:readlink(/proc/<pid>/exe)
- * tries to guess component
- */
- add_basics_to_problem_data(pd);
- struct dump_dir *dd = create_dump_dir_from_problem_data(pd, "/tmp"/* /var/tmp ?? */);
- if (!dd)
- return -1;
- dd_create_basic_files(dd, getuid());
- char *dir_name = xstrdup(dd->dd_dirname);
- dd_close(dd);
- VERB2 log("Temp problem dir: '%s'", dir_name);
- int result = report_dir(dir_name);
-
- /* here we always wait for reporter to finish, we can clean the tmp dir
- * and we should reload the problem data, so caller doesn't see the stalled
- * data
- */
- g_hash_table_remove_all(pd); //what if something fails? is it ok to return empty pd rather then stalled pd?
- dd = dd_opendir(dir_name, 0);
- if (dd)
- {
- load_problem_data_from_dump_dir(pd, dd);
- dd_delete(dd);
- }
- free(dir_name);
-
- return result;
+ return report_problem_in_memory(pd, LIBREPORT_WAIT);
}