Add report types 21/185421/12
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 20 Jul 2018 09:00:49 +0000 (11:00 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 22 Aug 2018 05:51:37 +0000 (07:51 +0200)
Depending on report type we save all zip archive with coredump, logs,
so_info and info file, or just only the *.info file. Report type can be set in
crash-manager.conf:

    [CrashManager]
    ...
    ReportType=INFO
    ...

Available report types:

* INFO - Save *.info file
* FULL - Save coredump, *.log, *.so_info and *info file as a ZIP archive (default)

Change-Id: I486049ac8eb928ebdc6ac513bdeac3c98aa4adcc

src/crash-manager/crash-manager.c
src/crash-manager/crash-manager.conf

index 80dd82ddf8dd5d0fa70cc6bbbb48658f8ec7d2cb..6ee58f87344ed4bc6270dfb31eb7e82b7e8b2281 100644 (file)
@@ -82,6 +82,16 @@ enum {
        USAGE_EXCEED
 };
 
+enum {
+       REP_TYPE_INFO = 0,
+       REP_TYPE_FULL
+};
+
+#define REP_DEFAULT_TYPE REP_TYPE_FULL
+
+#define REP_TYPE_FULL_STR "FULL"
+#define REP_TYPE_INFO_STR "INFO"
+
 struct file_info {
        bool   isdir;
        int    size;
@@ -98,6 +108,7 @@ static bool allow_zip;
 static char* crash_root_path;
 static char* crash_crash_path;
 static char* crash_temp_path;
+static int report_type;
 
 /* Paths and variables */
 static struct crash_info {
@@ -231,6 +242,33 @@ static int prepare_paths(void)
        return 1;
 }
 
+static const char* report_type_to_str(const int report_type)
+{
+       switch (report_type) {
+       case REP_TYPE_INFO:
+               return REP_TYPE_INFO_STR;
+               break;
+       case REP_TYPE_FULL:
+               return REP_TYPE_FULL_STR;
+       default:
+               return NULL;
+               break;
+       }
+}
+
+static int report_type_from_str(const char* report_type_str)
+{
+       if (report_type_str == NULL)
+               return -1;
+
+       if (strncmp(report_type_str, REP_TYPE_FULL_STR, strlen(REP_TYPE_FULL_STR)) == 0)
+               return REP_TYPE_FULL;
+       else if (strncmp(report_type_str, REP_TYPE_INFO_STR, strlen(REP_TYPE_INFO_STR)) == 0)
+               return REP_TYPE_INFO;
+
+       return -1;
+}
+
 static int get_config(void)
 {
        dictionary *ini = NULL;
@@ -248,6 +286,7 @@ static int get_config(void)
                _E("strdup error: %m\n");
                return -1;
        }
+       report_type = REP_DEFAULT_TYPE;
 
        ini = iniparser_load(CRASH_CONF_FILE);
        if (!ini) {
@@ -321,6 +360,22 @@ static int get_config(void)
                }
        }
 
+       snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "ReportType");
+       value_str = iniparser_getstring(ini, key, NULL);
+       if (value_str == NULL) {
+               _D("Invalid value for ReportType. Use default value [ %s ]",
+                               report_type_to_str(report_type));
+       } else {
+               _D("ReportType [ %s ]", value_str);
+               report_type = report_type_from_str(value_str);
+
+               if (report_type < 0) {
+                       _E("Unknown ReportType %s. Fallback to default: %s",
+                          value_str, report_type_to_str(REP_DEFAULT_TYPE));
+                       report_type = REP_DEFAULT_TYPE;
+               }
+       }
+
        iniparser_freedict(ini);
        return 1;
 }
@@ -814,7 +869,8 @@ static void execute_crash_modules(int argc, char *argv[])
        _D("Execute crash module: ");
 
 #ifdef TIZEN_ENABLE_COREDUMP
-       execute_crash_pipe(argc, argv);
+       if (report_type >= REP_TYPE_FULL)
+               execute_crash_pipe(argc, argv);
 #endif
 
 #ifdef TIZEN_ENABLE_MINICOREDUMP
@@ -1118,6 +1174,27 @@ static void move_dump_dir(void)
                _E("Failed to delete temp directory");
 }
 
+static void move_info_file(void)
+{
+       int lock_fd;
+
+       if ((lock_fd = lock_dumpdir()) < 0)
+               return;
+
+       char dest_path[PATH_MAX];
+       snprintf(dest_path, sizeof(dest_path), "%s/%s.info",
+                        crash_crash_path, crash_info.name);
+       if (!rename(crash_info.info_path, dest_path))
+               clean_dump();
+       else
+               _E("Failed to move %s to %s",
+                  crash_info.info_path, dest_path);
+
+       unlock_dumpdir(lock_fd);
+       if (remove_dir(crash_info.temp_dir, 1) < 0)
+               _E("Failed to delete temp directory");
+}
+
 static int wait_for_opt(unsigned int timeout)
 {
        unsigned int count = 0;
@@ -1185,27 +1262,32 @@ int main(int argc, char *argv[])
        get_sysassert_cs();
 #endif
 
-       /* Exec dump_systemstate */
-       dump_state_pid = dump_system_state();
-
-       /* Copy maps file to temp dir */
-       copy_maps();
+       if (report_type >= REP_TYPE_FULL) {
+               /* Exec dump_systemstate */
+               dump_state_pid = dump_system_state();
 
+               /* Copy maps file to temp dir */
+               copy_maps();
+       }
        /* Exec crash modules */
        execute_crash_modules(argc, argv);
 
-       /* Save shared objects info (file names, bulid IDs, rpm package names) */
-       save_so_info();
-       remove_maps();
+       if (report_type >= REP_TYPE_FULL) {
+               /* Save shared objects info (file names, bulid IDs, rpm package names) */
+               save_so_info();
+               remove_maps();
 
-       /* Wait dump_system_state */
-       wait_system_command(dump_state_pid);
+               /* Wait dump_system_state */
+               wait_system_command(dump_state_pid);
 
-       /* Tar compression */
-       if (allow_zip)
-               compress();
-       else
-               move_dump_dir();
+               /* Tar compression */
+               if (allow_zip)
+                       compress();
+               else
+                       move_dump_dir();
+       } else {
+               move_info_file();
+       }
 #if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_ENABLE_MINICOREDUMP)
        /* launch crash-popup only if the .debugmode file is exist*/
        if (debug_mode)
index 08131cc0836f0338a5a54ca2a5d0427991be0296..98e8690510a66559ea7f25717c349f8e95214807 100644 (file)
@@ -7,3 +7,6 @@ AllowZip=yes
 
 # Crash report path must exist for the reports to be created
 # CrashRootPath=/usr/opt/share/crash/
+
+# Report type can be FULL (.zip) or INFO (.info only)
+# ReportType=FULL