On Fri, 2011-05-20 at 14:08 +0200, Jiri Moskovcak wrote:
I pushed the proposed changes, the only thing which has left to fix
is
getting the component name (problem_data.c: 129). I need to ask rpm for
it and there are few possible solution:
1. call abrt-action-save-package-data
2. $ rpm -qf executable
3. use librpm
Suggestions?
I propose to add two more flags: LIBREPORT_ANALYZE and
LIBREPORT_RELOAD_DATA, but reduce the number of functions from four to
two:
int report_problem_in_dir(const char *dirname, int flags);
int report_problem_data_t(problem_data_t *pd, int flags);
Patch is below.
A further possible improvement is to add
"bug-reporting-wizard --delete-dir" option. It will make this work:
report_problem_data_t(pd, LIBREPORT_NOWAIT);
without leaving stray temp dir in /tmp.
--
vda
diff -x '*.po' -d -urpN abrt.1/src/applet/applet_gtk.c
abrt.2/src/applet/applet_gtk.c
--- abrt.1/src/applet/applet_gtk.c 2011-05-22 19:57:24.585074781 +0200
+++ abrt.2/src/applet/applet_gtk.c 2011-05-22 20:32:34.057268077 +0200
@@ -86,7 +86,8 @@ static void action_report(NotifyNotifica
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(NotifyNotifica
error_msg("%s", err->message);
g_error_free(err);
}
+
hide_icon(applet);
stop_animate_icon(applet);
}
diff -x '*.po' -d -urpN abrt.1/src/gui-gtk/abrt-gtk.c
abrt.2/src/gui-gtk/abrt-gtk.c
--- abrt.1/src/gui-gtk/abrt-gtk.c 2011-05-22 19:43:25.700265109 +0200
+++ abrt.2/src/gui-gtk/abrt-gtk.c 2011-05-22 21:23:29.627200241 +0200
@@ -108,8 +108,8 @@ static void on_row_activated_cb(GtkTreeV
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
/* 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_data_t(pd, LIBREPORT_WAIT);
+ VERB1 log("Reporting finished with status %i", status);
free_problem_data(pd);
}
diff -x '*.po' -d -urpN abrt.1/src/include/report/report.h
abrt.2/src/include/report/report.h
--- abrt.1/src/include/report/report.h 2011-05-22 19:43:35.170217759 +0200
+++ abrt.2/src/include/report/report.h 2011-05-22 21:24:08.187128625 +0200
@@ -22,28 +22,18 @@
#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
- */
-int analyze_and_report_dir(const char* dirname, 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
+/* 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(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);
+int report_problem_data_t(problem_data_t *pd, int flags);
#endif /* REPORT_H_ */
diff -x '*.po' -d -urpN abrt.1/src/lib/report.c abrt.2/src/lib/report.c
--- abrt.1/src/lib/report.c 2011-05-22 20:24:58.854708453 +0200
+++ abrt.2/src/lib/report.c 2011-05-22 21:17:55.303033565 +0200
@@ -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,
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,
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_data_t(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,28 @@ int analyze_and_report(problem_data_t *p
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)
-{
- 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;
}