Fix handling CrashRootPath from the config file 11/319711/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 30 Oct 2024 15:36:45 +0000 (16:36 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 30 Oct 2024 17:00:17 +0000 (18:00 +0100)
Change-Id: Idc79c221c78f3ee5c84828fc07b7b0442102b543

packaging/crash-worker.spec
src/bugreport-service/diagnostics/diagnostics_dump.c
src/bugreport-service/systemdump.c

index a38a3fa7a3950f096d022005f89a945735ca01ad..c4bfba3b6e463681c616675d67c5551e7c9054ac 100644 (file)
@@ -16,7 +16,7 @@
 
 Name:           crash-worker
 Summary:        Coredump handler and report generator for Tizen
-Version:        9.0.2
+Version:        9.0.3
 Release:        1
 Group:          Framework/system
 License:        MIT
index 93258e339ffeb1708842fd2673d01caa868e6d92..8daed4e92695cb37b6c6e1e8347461ae24ce8df3 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "diagnostics/diagnostics.h"
 #include "diagnostics/diagnostics_dump.h"
+#include "shared/config.h"
 #include "shared/log.h"
 #include "shared/util.h"
 
@@ -139,9 +140,20 @@ static struct report_file* get_reports(size_t *count)
        struct report_file *list = NULL;
        *count = 0;
 
+       config_t config;
+       char *crash_root_path = NULL;
+       if (config_init(&config, CRASH_MANAGER_CONFIG_PATH))
+               crash_root_path = config.crash_root_path;
+       else
+               crash_root_path = CRASH_ROOT_PATH;
+
+       char crash_path[PATH_MAX];
+       char live_path[PATH_MAX];
+       snprintf(crash_path, sizeof(crash_path)-1, "%s%s", crash_root_path, CRASH_PATH_SUBDIR);
+       snprintf(live_path, sizeof(live_path)-1, "%s%s", crash_root_path, LIVE_PATH_SUBDIR);
        const char *dirs[] = {
-               CRASH_ROOT_PATH CRASH_PATH_SUBDIR,
-               CRASH_ROOT_PATH LIVE_PATH_SUBDIR
+               crash_path,
+               live_path
        };
 
        for (int i = 0; i < ARRAY_SIZE(dirs); i++) {
index df3e146a57e8544a4719eb72898d2ce84b33e268..0aca439a124572cc364ac2b372b3e877937b7f27 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "systemdump.h"
 #include "defs.h"
+#include "shared/config.h"
 #include "shared/spawn.h"
 #include "shared/util.h"
 #include "shared/log.h"
@@ -73,11 +74,22 @@ static bool prepare_paths(struct systemstate_info *sinfo)
        time_t time_info = time(NULL);
        localtime_r(&time_info, &loc_tm);
        strftime(date, sizeof(date), "%Y%m%d%H%M%S", &loc_tm);
+       config_t config;
+       const char *crash_root_path;
+       if (config_init(&config, CRASH_MANAGER_CONFIG_PATH))
+               crash_root_path = config.crash_root_path;
+       else
+               crash_root_path = CRASH_ROOT_PATH;
+
+       char *crash_temp_path;
+       if (asprintf(&crash_temp_path, "%s/temp", crash_root_path) == -1) {
+               goto out_of_memory;
+       }
 
-       if (!make_dir(CRASH_TEMP, DEFAULT_CRASH_DIR_PERM))
+       if (!make_dir(crash_temp_path, DEFAULT_CRASH_DIR_PERM))
                return false;
 
-       if (asprintf(&sinfo->temp_path, "%s/crash.XXXXXX", CRASH_TEMP) == -1)
+       if (asprintf(&sinfo->temp_path, "%s/crash.XXXXXX", crash_temp_path) == -1)
                goto out_of_memory;
 
        if (mkdtemp(sinfo->temp_path) == NULL || access(sinfo->temp_path, F_OK)) {
@@ -88,7 +100,7 @@ static bool prepare_paths(struct systemstate_info *sinfo)
        if (asprintf(&sinfo->report_name, "system_0_%s", date) == -1 ||
            asprintf(&sinfo->temp_report_dir, "%s/%s", sinfo->temp_path, sinfo->report_name) == -1 ||
            asprintf(&sinfo->log_path, "%s/%s.log", sinfo->temp_report_dir, sinfo->report_name) == -1 ||
-           asprintf(&sinfo->reports_dir, "%s%s", CRASH_ROOT_PATH, LIVE_PATH_SUBDIR) == -1 ||
+           asprintf(&sinfo->reports_dir, "%s%s", crash_root_path, LIVE_PATH_SUBDIR) == -1 ||
            asprintf(&sinfo->zip_path, "%s/report.zip", sinfo->temp_path) == -1 ||
            asprintf(&sinfo->report_path, "%s%s.%s", sinfo->reports_dir, sinfo->report_name, "zip") == -1)
                goto out_of_memory;