Create a report with only dump_systemstate output for PID <= 0 51/253851/6
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 18 Feb 2021 11:08:55 +0000 (12:08 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 24 Feb 2021 09:21:01 +0000 (10:21 +0100)
Passing PID <= 0 to livedump_pid() API method will create a report
containing only dump_systemstate output.

Change-Id: I38dd566acb0ff2f1a0ecf0a492dbdac91343c215

packaging/crash-worker.spec
src/crash-manager/crash-manager.c
src/crash-service/crash-service.c
tests/system/CMakeLists.txt
tests/system/libcrash-service_systemstate/libcrash-service_systemstate.sh.template [new file with mode: 0755]
tests/system/utils/libcrash-servicetest.c

index 021d8f4..8d0570c 100644 (file)
@@ -269,6 +269,7 @@ fi
 %{_libexecdir}/crash-worker/system-tests/full_core/full_core.sh
 %{_libexecdir}/crash-worker/system-tests/info_file/info_file.sh
 %{_libexecdir}/crash-worker/system-tests/libcrash-service/libcrash-service.sh
+%{_libexecdir}/crash-worker/system-tests/libcrash-service_systemstate/libcrash-service_systemstate.sh
 %{_libexecdir}/crash-worker/system-tests/log_file/log_file.sh
 %{_libexecdir}/crash-worker/system-tests/output_param/output_param.sh
 %{_libexecdir}/crash-worker/system-tests/report_basic/report_basic.sh
index 80e3b69..d4fb782 100644 (file)
@@ -72,6 +72,8 @@
 #define CRASH_STACK_TIMEOUT_MS     DEFAULT_COMMAND_TIMEOUT_MS
 #define ZIP_TIMEOUT_MS             DEFAULT_COMMAND_TIMEOUT_MS
 
+#define SYSTEM_REPORT_NAME   "system"
+
 enum {
        RET_EXCEED = 1,
        NUM_EXCEED,
@@ -323,6 +325,16 @@ static bool get_cmd_info(struct crash_info *cinfo)
 {
        assert(cinfo);
 
+       if (cinfo->pid_info <= 0) {
+               cinfo->cmd_line = strdup(SYSTEM_REPORT_NAME);
+               cinfo->comm = strdup(SYSTEM_REPORT_NAME);
+               if (cinfo->cmd_line == NULL || cinfo->comm == NULL) {
+                       _E("Couldn't allocate memory\n");
+                       return false;
+               }
+               return true;
+       }
+
        char buf[PATH_MAX];
        char proc_name[PATH_MAX];
 
@@ -488,6 +500,9 @@ static bool clean_temp(const char *temp_dir)
 /* Note: caller of this function is responsible for cleaning up the cinfo on failure */
 bool set_crash_info(struct crash_info *cinfo)
 {
+       bool system_dump = cinfo->pid_info <= 0;
+       bool zip_report = system_dump || config.allow_zip;
+
        set_crash_info_defaults(cinfo);
 
        if (!get_cmd_info(cinfo)) {
@@ -509,7 +524,7 @@ bool set_crash_info(struct crash_info *cinfo)
                return false;
        }
 
-       const char *suffix = config.report_type >= REP_TYPE_FULL ? (config.allow_zip ? ".zip" : "") : ".info";
+       const char *suffix = (system_dump || config.report_type >= REP_TYPE_FULL) ? (zip_report ? ".zip" : "") : ".info";
        bool is_app = set_appinfo(cinfo->cmd_line, &cinfo->appid, &cinfo->pkgid);
        if (!cinfo->appid || !cinfo->pkgid)
                goto out_oom;
@@ -1311,11 +1326,17 @@ static void release_crashed_process()
 
 static bool run(struct crash_info *cinfo)
 {
+       /* Special PID ( <= 0) for which the report will contain only
+        * dump_systemstate output
+        */
+       bool system_dump = cinfo->pid_info <= 0;
+       bool zip_report = system_dump || config.allow_zip;
+
        /* Execute processes in parallel */
        static pid_t dump_state_pid = 0, extra_script_pid = 0;
        int debug_mode = access(DEBUGMODE_PATH, F_OK) == 0;
 
-       if (config.report_type >= REP_TYPE_FULL) {
+       if (system_dump || config.report_type >= REP_TYPE_FULL) {
                /* Exec dump_systemstate */
                if (!dump_system_state(cinfo, &dump_state_pid)) {
                        _E("Failed to get system state report");
@@ -1329,32 +1350,36 @@ static bool run(struct crash_info *cinfo)
        _I("Creating report for pid %d, tid %d, cmdline %s, pkgid %s",
           cinfo->pid_info, cinfo->tid_info, cinfo->cmd_line, cinfo->pkgid);
 
-       /* Exec crash modules */
-       if (!execute_crash_modules(cinfo)) {
-               _E("Failed to get basic crash information");
-               return false;
-       }
+       if (!system_dump) {
+               /* Exec crash modules */
+               if (!execute_crash_modules(cinfo)) {
+                       _E("Failed to get basic crash information");
+                       return false;
+               }
 
-       if (!cinfo->livedump && config.release_early)
-               release_crashed_process();
+               if (!cinfo->livedump && config.release_early)
+                       release_crashed_process();
+       }
 
        char *temp_report;
-       if (config.report_type >= REP_TYPE_FULL) {
-               /* Save shared objects info (file names, bulid IDs, rpm package names) */
-               if (config.dump_so_info)
-                       save_so_info(cinfo);
-               else
-                       _I("Not saving .so_info (disabled in configuration)");
+       if (system_dump || config.report_type >= REP_TYPE_FULL) {
+               if (!system_dump) {
+                       /* Save shared objects info (file names, bulid IDs, rpm package names) */
+                       if (config.dump_so_info)
+                               save_so_info(cinfo);
+                       else
+                               _I("Not saving .so_info (disabled in configuration)");
+               }
 
                /* Wait misc. pids */
                wait_for_pid(dump_state_pid, NULL);
                if (extra_script_pid > 0)
                        wait_for_pid(extra_script_pid, NULL);
 
-               if (config.allow_zip)
+               if (zip_report)
                        compress(cinfo);
 
-               temp_report = config.allow_zip ? cinfo->zip_path : cinfo->pfx;
+               temp_report = (zip_report) ? cinfo->zip_path : cinfo->pfx;
        } else
                temp_report = cinfo->info_path;
 
@@ -1364,17 +1389,19 @@ static bool run(struct crash_info *cinfo)
        if (cinfo->print_result_path)
                printf("REPORT_PATH=%s\n", cinfo->result_path);
 
-       if (!cinfo->livedump) {
-               if (!config.release_early)
-                       release_crashed_process();
+       if (!system_dump) {
+               if (!cinfo->livedump) {
+                       if (!config.release_early)
+                               release_crashed_process();
 
-               launch_dbus_notify(cinfo);
+                       launch_dbus_notify(cinfo);
 
-               /* launch crash-popup only if the .debugmode file exists */
-               if (debug_mode)
-                       launch_crash_popup(cinfo);
-       } else if (cinfo->kill) {
-               kill_pid(cinfo->pid_info, SIGKILL, false);
+                       /* launch crash-popup only if the .debugmode file exists */
+                       if (debug_mode)
+                               launch_crash_popup(cinfo);
+               } else if (cinfo->kill) {
+                       kill_pid(cinfo->pid_info, SIGKILL, false);
+               }
        }
 
        return true;
index e156653..b254940 100644 (file)
@@ -136,7 +136,7 @@ static bool data_ready(int fd)
 static gboolean read_result_cb(gpointer data)
 {
        struct livedump_cb_data *cb_data = (struct livedump_cb_data*)data;
-       char report_path[PATH_MAX];
+       char report_path[PATH_MAX] = {0};
 
        if (!data_ready(cb_data->read_fd)) {
                _I("Report is not ready after %d seconds.", TIMEOUT_LIVEDUMP_SEC);
index e8661a1..54c2ede 100644 (file)
@@ -31,6 +31,7 @@ configure_test("extra_script")
 configure_test("full_core")
 configure_test("info_file")
 configure_test("libcrash-service")
+configure_test("libcrash-service_systemstate")
 configure_test("livedumper")
 configure_test("log_file")
 configure_test("output_param")
diff --git a/tests/system/libcrash-service_systemstate/libcrash-service_systemstate.sh.template b/tests/system/libcrash-service_systemstate/libcrash-service_systemstate.sh.template
new file mode 100755 (executable)
index 0000000..2f23b71
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# Test --output parameter
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+    CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+rm -rf ${LIVE_DUMP_PATH}/*
+REASON="some reason"
+${CRASH_WORKER_SYSTEM_TESTS}/utils/libcrash-servicetest -r "${REASON}" 0
+
+wait_for_file ${LIVE_DUMP_PATH}/system_0_*zip
+
+pushd ${LIVE_DUMP_PATH}
+
+unzip system_0_*zip
+cd system_0_*
+
+if [ ! -f *dump_reason ]; then
+    fail "dump_reason file doesn't exist"
+fi
+
+if [ ! -f *log ]; then
+    fail "log file doesn't exist"
+fi
+
+if [ "$(cat *dump_reason)" != "${REASON}" ]; then
+    fail "Dump reason didn't match"
+fi
+
+exit_ok
index c83a2fc..f06c534 100644 (file)
@@ -7,7 +7,13 @@
 
 void help(char *argv_0)
 {
-       printf("Usage: %s [-r dump_reason] pid\n", argv_0);
+       printf("\n");
+       printf("Usage: %s [-r <dump_reason>] num\n", argv_0);
+       printf("    Options:\n");
+       printf("        -r <dump_reason>   Set dump reason\n\n");
+       printf("    Arguments:\n");
+       printf("        num:               PID for livedumper report\n");
+       printf("                           0 for systemstate report\n\n");
 }
 
 int main(int argc, char *argv[])
@@ -34,11 +40,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
        pid_t pid = strtol(argv[optind], NULL, 10);
-       if (pid == 0) {
-               printf("ERROR: pid must be a number\n");
-               help(argv[0]);
-               return EXIT_FAILURE;
-       }
 
        char BUFF[PATH_MAX];
        bool res = livedump_pid(pid, dump_reason, BUFF, PATH_MAX);