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

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