Blob Blame History Raw
From 89e0a7d0a195605585b80157ce23be1fb03f04a2 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Wed, 13 May 2015 10:45:32 +0200
Subject: [PATCH] abrt: refactorize unwinding from core hook

ABRT needs to save files from its core hook with O_EXCL and with right
mode and owner and there might be more constraints ABRT needs to
respect in future.

This patch breaks granularity of the abrt functions to allow ABRT to save the
core backtrace data in the way it need by providing a function returning
the data instead of directly saving the data to a file.

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 include/abrt.h |  6 ++++++
 lib/abrt.c     | 29 ++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/abrt.h b/include/abrt.h
index 5116446..ca0748c 100644
--- a/include/abrt.h
+++ b/include/abrt.h
@@ -44,6 +44,12 @@ sr_abrt_create_core_stacktrace_from_gdb(const char *directory,
                                         bool hash_fingerprints,
                                         char **error_message);
 
+char *
+sr_abrt_get_core_stacktrace_from_core_hook(pid_t thread_id,
+                                           const char *executable,
+                                           int signum,
+                                           char **error_message);
+
 bool
 sr_abrt_create_core_stacktrace_from_core_hook(const char *directory,
                                               pid_t thread_id,
diff --git a/lib/abrt.c b/lib/abrt.c
index 86e9082..4599e2c 100644
--- a/lib/abrt.c
+++ b/lib/abrt.c
@@ -162,12 +162,11 @@ sr_abrt_create_core_stacktrace(const char *directory,
                                   error_message);
 }
 
-bool
-sr_abrt_create_core_stacktrace_from_core_hook(const char *directory,
-                                              pid_t thread_id,
-                                              const char *executable,
-                                              int signum,
-                                              char **error_message)
+char *
+sr_abrt_get_core_stacktrace_from_core_hook(pid_t thread_id,
+                                           const char *executable,
+                                           int signum,
+                                           char **error_message)
 {
 
     struct sr_core_stacktrace *core_stacktrace;
@@ -180,12 +179,29 @@ sr_abrt_create_core_stacktrace_from_core_hook(const char *directory,
     fulfill_missing_values(core_stacktrace);
 
     char *json = sr_core_stacktrace_to_json(core_stacktrace);
+    sr_core_stacktrace_free(core_stacktrace);
 
     // Add newline to the end of core stacktrace file to make text
     // editors happy.
     json = sr_realloc(json, strlen(json) + 2);
     strcat(json, "\n");
 
+    return json;
+;
+}
+
+bool
+sr_abrt_create_core_stacktrace_from_core_hook(const char *directory,
+                                              pid_t thread_id,
+                                              const char *executable,
+                                              int signum,
+                                              char **error_message)
+{
+    char *json = sr_abrt_get_core_stacktrace_from_core_hook(thread_id,
+                                                            executable,
+                                                            signum,
+                                                            error_message);
+
     char *core_backtrace_filename = sr_build_path(directory, "core_backtrace", NULL);
     bool success = sr_string_to_file(core_backtrace_filename,
                                     json,
@@ -193,7 +209,6 @@ sr_abrt_create_core_stacktrace_from_core_hook(const char *directory,
 
     free(core_backtrace_filename);
     free(json);
-    sr_core_stacktrace_free(core_stacktrace);
     return success;
 }
 
-- 
2.4.3