Blame SOURCES/0072-applet-ensure-writable-dump-directory-before-reporti.patch

44797e
From a169b05a10f242b19beab749458e86d7d7aa4f7b Mon Sep 17 00:00:00 2001
44797e
From: Jakub Filak <jfilak@redhat.com>
44797e
Date: Tue, 21 Oct 2014 14:57:10 +0200
44797e
Subject: [ABRT PATCH 72/72] applet: ensure writable dump directory before
44797e
 reporting
44797e
44797e
Related to rhbz#1084027
44797e
44797e
Signed-off-by: Jakub Filak <jfilak@redhat.com>
44797e
44797e
Conflicts:
44797e
	src/applet/applet.c
44797e
---
44797e
 src/applet/applet.c | 62 ++++++++++++++++++++++++++++++++++-------------------
44797e
 1 file changed, 40 insertions(+), 22 deletions(-)
44797e
44797e
diff --git a/src/applet/applet.c b/src/applet/applet.c
44797e
index bd95666..8c339a4 100644
44797e
--- a/src/applet/applet.c
44797e
+++ b/src/applet/applet.c
44797e
@@ -309,6 +309,7 @@ typedef struct problem_info {
44797e
     bool incomplete;
44797e
     bool reported;
44797e
     bool was_announced;
44797e
+    bool is_writable;
44797e
 } problem_info_t;
44797e
 
44797e
 static void push_to_deferred_queue(problem_info_t *pi)
44797e
@@ -326,6 +327,36 @@ static void problem_info_set_dir(problem_info_t *pi, const char *dir)
44797e
     problem_data_add_text_noteditable(pi->problem_data, CD_DUMPDIR, dir);
44797e
 }
44797e
 
44797e
+static bool problem_info_ensure_writable(problem_info_t *pi)
44797e
+{
44797e
+    if (pi->is_writable)
44797e
+        return true;
44797e
+
44797e
+    /* chown the directory in any case, because kernel oopses are not foreign */
44797e
+    /* but their dump directories are not writable without chowning them or */
44797e
+    /* stealing them. The stealing is deprecated as it breaks the local */
44797e
+    /* duplicate search and root cannot see them */
44797e
+    const int res = chown_dir_over_dbus(problem_info_get_dir(pi));
44797e
+    if (pi->foreign && res != 0)
44797e
+    {
44797e
+        error_msg(_("Can't take ownership of '%s'"), problem_info_get_dir(pi));
44797e
+        return false;
44797e
+    }
44797e
+    pi->foreign = false;
44797e
+
44797e
+    struct dump_dir *dd = open_directory_for_writing(problem_info_get_dir(pi), /* don't ask */ NULL);
44797e
+    if (!dd)
44797e
+    {
44797e
+        error_msg(_("Can't open directory for writing '%s'"), problem_info_get_dir(pi));
44797e
+        return false;
44797e
+    }
44797e
+
44797e
+    problem_info_set_dir(pi, dd->dd_dirname);
44797e
+    pi->is_writable = true;
44797e
+    dd_close(dd);
44797e
+    return true;
44797e
+}
44797e
+
44797e
 static problem_info_t *problem_info_new(const char *dir)
44797e
 {
44797e
     problem_info_t *pi = xzalloc(sizeof(*pi));
44797e
@@ -601,8 +632,13 @@ static pid_t spawn_event_handler_child(const char *dump_dir_name, const char *ev
44797e
     return child;
44797e
 }
44797e
 
44797e
-static void run_report_from_applet(const char *dirname)
44797e
+static void run_report_from_applet(problem_info_t *pi)
44797e
 {
44797e
+    if (!problem_info_ensure_writable(pi))
44797e
+        return;
44797e
+
44797e
+    const char *dirname = problem_info_get_dir(pi);
44797e
+
44797e
     fflush(NULL); /* paranoia */
44797e
     pid_t pid = fork();
44797e
     if (pid < 0)
44797e
@@ -642,7 +678,7 @@ static void action_report(NotifyNotification *notification, gchar *action, gpoin
44797e
         if (strcmp(A_REPORT_REPORT, action) == 0)
44797e
         {
44797e
 #endif//RHBZ_1067114_NO_UREPORT
44797e
-            run_report_from_applet(problem_info_get_dir(pi));
44797e
+            run_report_from_applet(pi);
44797e
             problem_info_free(pi);
44797e
 #ifndef RHBZ_1067114_NO_UREPORT
44797e
         }
44797e
@@ -1113,7 +1149,7 @@ static gboolean handle_event_output_cb(GIOChannel *gio, GIOCondition condition,
44797e
         if (pi->known || !(state->flags & REPORT_UNKNOWN_PROBLEM_IMMEDIATELY))
44797e
             notify_problem(pi);
44797e
         else
44797e
-            run_report_from_applet(problem_info_get_dir(pi));
44797e
+            run_report_from_applet(pi);
44797e
     }
44797e
     else
44797e
     {
44797e
@@ -1174,29 +1210,11 @@ static void export_event_configuration(const char *event_name)
44797e
 
44797e
 static void run_event_async(problem_info_t *pi, const char *event_name, int flags)
44797e
 {
44797e
-    /* chown the directory in any case, because kernel oopses are not foreign */
44797e
-    /* but their dump directories are not writable without chowning them or */
44797e
-    /* stealing them. The stealing is deprecated as it breaks the local */
44797e
-    /* duplicate search and root cannot see them */
44797e
-    const int res = chown_dir_over_dbus(problem_info_get_dir(pi));
44797e
-    if (pi->foreign && res != 0)
44797e
+    if (!problem_info_ensure_writable(pi))
44797e
     {
44797e
-        error_msg(_("Can't take ownership of '%s'"), problem_info_get_dir(pi));
44797e
         problem_info_free(pi);
44797e
         return;
44797e
     }
44797e
-    pi->foreign = false;
44797e
-
44797e
-    struct dump_dir *dd = open_directory_for_writing(problem_info_get_dir(pi), /* don't ask */ NULL);
44797e
-    if (!dd)
44797e
-    {
44797e
-        error_msg(_("Can't open directory for writing '%s'"), problem_info_get_dir(pi));
44797e
-        problem_info_free(pi);
44797e
-        return;
44797e
-    }
44797e
-
44797e
-    problem_info_set_dir(pi, dd->dd_dirname);
44797e
-    dd_close(dd);
44797e
 
44797e
     export_event_configuration(event_name);
44797e
 
44797e
-- 
44797e
1.8.3.1
44797e