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

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