From 7edac02bfe151c62922fe913c33211f63f0f7f89 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 12 Mar 2020 13:34:30 +0100 Subject: [PATCH 01/16] Release 6.0.12 Notable features & changes: - dump_systemstate: move information about most of the programs to config files - dump_systemstate: add cmdflag= and order= support - crash-manager, service: add information about C# libraries to package info file (.so_info) - whole codebase: reduce default log level to INFO - drop separate spec for system-tests Change-Id: If47fc36e26954309a2c18262f32a69053bab2eb3 --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index a58bc51..7c75698 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -13,7 +13,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 6.0.11 +Version: 6.0.12 Release: 1 Group: Framework/system License: Apache-2.0 and BSD-2-Clause and MIT -- 2.7.4 From ed4989aeb03a3ce0bdb8fd34041ed967294dd26b Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 19 Mar 2020 15:06:45 +0100 Subject: [PATCH 02/16] Allow disabling so_info generation via config file Change-Id: I89d3b687225a7a85498344c9dd84c17ba4f3e33b --- packaging/crash-worker.spec | 1 + src/crash-manager/crash-manager.c | 5 ++- src/crash-manager/crash-manager.conf | 9 +++++ src/shared/config.c | 4 +++ src/shared/config.h | 2 ++ tests/system/CMakeLists.txt | 1 + .../without_so_info_file.sh.template | 40 ++++++++++++++++++++++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/system/without_so_info_file/without_so_info_file.sh.template diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 7c75698..f40ad8c 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -268,6 +268,7 @@ mkdir -p %{buildroot}%{crash_temp} %{_libdir}/crash-worker/system-tests/utils/libcrash-servicetest %{_libdir}/crash-worker/system-tests/utils/minicore-utils.sh %{_libdir}/crash-worker/system-tests/wait_for_opt_usr/wait_for_opt_usr.sh +%{_libdir}/crash-worker/system-tests/without_so_info_file/without_so_info_file.sh %{_libdir}/crash-worker/system-tests/without_core/without_core.sh %if %{with livedumper} diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 7e88660..0f4cdae 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -1066,7 +1066,10 @@ static bool run(struct crash_info *cinfo) char *temp_report; if (config.report_type >= REP_TYPE_FULL) { /* Save shared objects info (file names, bulid IDs, rpm package names) */ - save_so_info(cinfo); + 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); diff --git a/src/crash-manager/crash-manager.conf b/src/crash-manager/crash-manager.conf index dfa2d1b..09f3926 100644 --- a/src/crash-manager/crash-manager.conf +++ b/src/crash-manager/crash-manager.conf @@ -15,6 +15,15 @@ AllowZip=yes # This option applies to ReportType=FULL only! # DumpCore=1 +# DumpSharedObjectInfo - 1 to enable (default), 0 to disable +# This option controls creation of .so_info file +# +# Note! When set to 0 report will not include information about packages that were +# mapped into process memory. This information is normally needed to re-create +# sysroot for the use with debugger. +# +# DumpSharedObjectInfo=1 + # Use Legacy ProcessCrashed DBus signal # When '0' (default), crash worker emits new-style signal with extensive data: # 1. cmd name, diff --git a/src/shared/config.c b/src/shared/config.c index a35d191..60f168e 100644 --- a/src/shared/config.c +++ b/src/shared/config.c @@ -151,6 +151,7 @@ static bool config_load_from_dict(config_t *c, const dictionary *ini) UPDATE(c->max_retention_sec, int, "MaxRetentionSec"); UPDATE(c->max_crash_dump, int, "MaxCrashDump"); UPDATE(c->dump_core, boolean, "DumpCore"); + UPDATE(c->dump_so_info, boolean, "DumpSharedObjectInfo"); UPDATE(c->allow_zip, boolean, "AllowZip"); UPDATE(c->legacy_notification, boolean, "UseLegacyNotification"); @@ -247,6 +248,7 @@ static bool config_apply_defaults(config_t *c) c->max_retention_sec = MAX_RETENTION_SEC; c->max_crash_dump = MAX_CRASH_DUMP; c->dump_core = DUMP_CORE; + c->dump_so_info = DUMP_SO_INFO; c->allow_zip = ALLOW_ZIP; c->legacy_notification = LEGACY_NOTIFICATION; @@ -265,6 +267,7 @@ static void config_dump(config_t *c) "config: max_retention_sec = %d\n" "config: max_crash_dump = %d\n" "config: dump_core = %d\n" + "config: dump_so_info = %d\n" "config: allow_zip = %d\n" "config: legacy_notification = %d\n", c->crash_root_path, @@ -275,6 +278,7 @@ static void config_dump(config_t *c) c->max_retention_sec, c->max_crash_dump, c->dump_core, + c->dump_so_info, c->allow_zip, c->legacy_notification); } diff --git a/src/shared/config.h b/src/shared/config.h index f32d7f0..00b71b7 100644 --- a/src/shared/config.h +++ b/src/shared/config.h @@ -26,6 +26,7 @@ #define MAX_RETENTION_SEC 0 #define MAX_CRASH_DUMP 0 #define DUMP_CORE 1 +#define DUMP_SO_INFO 1 #define ALLOW_ZIP 1 #define LEGACY_NOTIFICATION 0 @@ -42,6 +43,7 @@ enum ReportType { typedef struct config { bool allow_zip; bool dump_core; + bool dump_so_info; bool legacy_notification; enum ReportType report_type; int system_max_use; diff --git a/tests/system/CMakeLists.txt b/tests/system/CMakeLists.txt index eace3ef..4039b25 100644 --- a/tests/system/CMakeLists.txt +++ b/tests/system/CMakeLists.txt @@ -28,6 +28,7 @@ configure_test("so_info_file") configure_test("report_basic") configure_test("report_type_info") configure_test("without_core") +configure_test("without_so_info_file") configure_test("crash_root_path") configure_test("dump_systemstate_extras") configure_test("livedumper") diff --git a/tests/system/without_so_info_file/without_so_info_file.sh.template b/tests/system/without_so_info_file/without_so_info_file.sh.template new file mode 100644 index 0000000..038e773 --- /dev/null +++ b/tests/system/without_so_info_file/without_so_info_file.sh.template @@ -0,0 +1,40 @@ +#!/bin/bash + +# Checks ability to disable .so_info + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +CONF_DIR=/etc/crash-manager.conf.d +CONF_FILE=${CONF_DIR}/crash-worker-without-so-info.conf + +mount -o rw,remount / + +mkdir -p $CONF_DIR +rm -f $CONF_FILE || : +cat <$CONF_FILE +[CrashManager] +DumpSharedObjectInfo=0 +EOF + +clean_crash_dump + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +wait_for_app crash-manager + +rm -f ${CONF_FILE} || : + +test -f ${CRASH_DUMP_PATH}/kenny*zip || fail "crash report not created" +unzip -l ${CRASH_DUMP_PATH}/kenny*zip | egrep 'kenny*/kenny*.so_info$' && fail ".so_info file found despite being disabled in config" + +exit_ok -- 2.7.4 From ca31ab97dfb95b6bd3603f91ff9886064b346533 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 19 Mar 2020 15:31:38 +0100 Subject: [PATCH 03/16] system tests: Sort entries Change-Id: I8b5fea6bcd1a9cc50b9efdf96820b444a96d534f --- tests/system/CMakeLists.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/system/CMakeLists.txt b/tests/system/CMakeLists.txt index 4039b25..c17c517 100644 --- a/tests/system/CMakeLists.txt +++ b/tests/system/CMakeLists.txt @@ -18,27 +18,27 @@ macro(CONFIGURE_TEST test_name) endmacro() configure_test("check_minicore_mem") -configure_test("time_test") configure_test("cmp_backtraces" "cp") +configure_test("crash_root_path") configure_test("critical_process") -configure_test("wait_for_opt_usr") +configure_test("dbus_notify") +configure_test("dbus_notify_legacy") +configure_test("dump_systemstate_extras") +configure_test("exclude_paths") +configure_test("extra_script") +configure_test("full_core") configure_test("info_file") +configure_test("libcrash-service") +configure_test("livedumper") configure_test("log_file") -configure_test("so_info_file") +configure_test("output_param") configure_test("report_basic") configure_test("report_type_info") +configure_test("so_info_file") +configure_test("time_test") +configure_test("wait_for_opt_usr") configure_test("without_core") configure_test("without_so_info_file") -configure_test("crash_root_path") -configure_test("dump_systemstate_extras") -configure_test("livedumper") -configure_test("exclude_paths") -configure_test("extra_script") -configure_test("dbus_notify") -configure_test("dbus_notify_legacy") -configure_test("output_param") -configure_test("libcrash-service") -configure_test("full_core") configure_file("run.sh.template" "run.sh" @ONLY) INSTALL(FILES "run.sh" DESTINATION bin RENAME crash-worker-system-tests-run -- 2.7.4 From 73b4576ad1381d6af34737f020f380359496e409 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 20 Mar 2020 16:12:50 +0100 Subject: [PATCH 04/16] Release 6.0.13 This release introduces ability to disable creation of .so_info files. Change-Id: I6bbc308e0d15b1872e43fd5c5f89142d76b9943d --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index f40ad8c..56a358a 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -13,7 +13,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 6.0.12 +Version: 6.0.13 Release: 1 Group: Framework/system License: Apache-2.0 and BSD-2-Clause and MIT -- 2.7.4 From a40c8c5611eb05341f081394574fa07767db44e2 Mon Sep 17 00:00:00 2001 From: Dongkyun Son Date: Mon, 30 Mar 2020 21:23:37 +0900 Subject: [PATCH 05/16] packaging: remove libebl dependency libebl is not needed anymore. Change-Id: If88fa16b361c70c9155e5240a03cbede3e235074 Signed-off-by: Dongkyun Son --- packaging/crash-worker.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 56a358a..5717544 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -29,7 +29,6 @@ BuildRequires: cmake BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(libunwind-generic) BuildRequires: libelf-devel libelf -BuildRequires: libebl-devel libebl BuildRequires: libdw-devel libdw BuildRequires: libcap-devel -- 2.7.4 From e7b5394c65076a7e91476446e33f4f52962f4eb7 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 2 Apr 2020 10:55:30 +0200 Subject: [PATCH 06/16] dump_systemstate: Also list files when reporting /tmp disk usage Change-Id: I0ea99ca0a05a7d620a4462d6dc44257aa6e4bee0 --- src/dump_systemstate/dump_systemstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dump_systemstate/dump_systemstate.c b/src/dump_systemstate/dump_systemstate.c index 8dbe9ce..9b50fa5 100644 --- a/src/dump_systemstate/dump_systemstate.c +++ b/src/dump_systemstate/dump_systemstate.c @@ -185,8 +185,8 @@ int main(int argc, char *argv[]) dpercent = get_disk_used_percent("/tmp"); if (80 < dpercent) { - fprintf_fd(out_fd, "\n==== tmp usage detail - %d%% (/bin/du -h /tmp)\n", dpercent); - char *du_args[] = {"/bin/du", "-h", "/tmp", NULL}; + fprintf_fd(out_fd, "\n==== tmp usage detail - %d%% (/bin/du -ah /tmp)\n", dpercent); + char *du_args[] = {"/bin/du", "-ah", "/tmp", NULL}; spawn_wait_checked(du_args, NULL); } -- 2.7.4 From 296b22a695bc3197a71d125abed926fe779ce4d8 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 2 Apr 2020 13:32:36 +0200 Subject: [PATCH 07/16] dump_systemstate: Use compile-time parameter check in get_disk_used_percent() Guard functions with assert as it's programming error to invoke it with null path. Change-Id: I3a312f90c0553c1dd9e9233551c0d42b89c260f7 --- src/dump_systemstate/dump_systemstate.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dump_systemstate/dump_systemstate.c b/src/dump_systemstate/dump_systemstate.c index 9b50fa5..149bfb0 100644 --- a/src/dump_systemstate/dump_systemstate.c +++ b/src/dump_systemstate/dump_systemstate.c @@ -21,6 +21,7 @@ * @brief dump system states. */ +#include #include #include #include @@ -73,15 +74,13 @@ static void usage() ); } -/* get disk used percentage */ static int get_disk_used_percent(const char *path) { + assert(path); + struct statfs lstatfs; int percent; - if (!path) - return -1; - if (statfs(path, &lstatfs) < 0) return -1; percent = (((lstatfs.f_blocks - lstatfs.f_bfree) * 1000) / (lstatfs.f_blocks)) + 9; -- 2.7.4 From d3a974dd6778c9c7a61c9be840524582c060cfdc Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 2 Apr 2020 13:37:03 +0200 Subject: [PATCH 08/16] dump_systemstate: Add /opt/usr disk usage section Change-Id: Ib52cba397f7272c14dcb7623efc85535d4d98d8e --- src/dump_systemstate/dump_systemstate.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/dump_systemstate/dump_systemstate.c b/src/dump_systemstate/dump_systemstate.c index 149bfb0..814acda 100644 --- a/src/dump_systemstate/dump_systemstate.c +++ b/src/dump_systemstate/dump_systemstate.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "dump_systemstate.h" @@ -88,6 +89,17 @@ static int get_disk_used_percent(const char *path) return percent; } +static dev_t get_disk_device(const char *path) +{ + assert(path); + + struct stat st; + if (stat(path, &st) < 0) + return -1; + + return st.st_dev; +} + int main(int argc, char *argv[]) { int c, ret, i, dpercent, exit_code = 0; @@ -182,6 +194,16 @@ int main(int argc, char *argv[]) spawn_wait_checked(du_args, NULL); } + if (get_disk_device("/opt") != get_disk_device("/opt/usr")) { + dpercent = get_disk_used_percent("/opt/usr"); + + if (90 < dpercent) { + fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt/usr)\n", dpercent); + char *du_args[] = {"/bin/du", "-ah", "/opt/usr", NULL}; + spawn_wait_checked(du_args, NULL); + } + } + dpercent = get_disk_used_percent("/tmp"); if (80 < dpercent) { fprintf_fd(out_fd, "\n==== tmp usage detail - %d%% (/bin/du -ah /tmp)\n", dpercent); -- 2.7.4 From ba0ee769a2a8eaf87bcaa343eea7b41dd0c0ce7c Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 26 Mar 2020 14:23:28 +0100 Subject: [PATCH 09/16] Fix cmp_backtraces test Change-Id: Ia628adfb80a4945d34e9847e864c903106dba3e6 --- tests/system/cmp_backtraces/cmp_backtraces.sh.template | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/system/cmp_backtraces/cmp_backtraces.sh.template b/tests/system/cmp_backtraces/cmp_backtraces.sh.template index 417cadd..5795397 100755 --- a/tests/system/cmp_backtraces/cmp_backtraces.sh.template +++ b/tests/system/cmp_backtraces/cmp_backtraces.sh.template @@ -44,8 +44,14 @@ wait_for_app minicoredumper untar_file ${BASE_DIR} ${CORE_MINI}.tar -gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_ORIG} -ex "thread apply all bt" -ex "q" 2> /dev/null | grep -e '^#' > ${BASE_DIR}/${THREADS_ORIG} -gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_MINI} -ex "thread apply all bt" -ex "q" 2> /dev/null | grep -e '^#' > ${BASE_DIR}/${THREADS_MINI} +# We want to compare if the call stack from the original dump is the same as +# the one from the minidump. GDB can also sometimes display the type of +# argument based on the data stored in the heap. Unfortunately, the minidump does +# not contain heap, and this causes differences in result. Therefore, the GDB +# result is filtered so that we can compare the two call stacks. + +gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_ORIG} -ex "thread apply all bt" -ex "q" 2> /dev/null | grep -e '^#' | sed 's/: [0-9]\+\(x[0-9]\+\( <[^>]\+>\)\?\)\?/: 0/g' > ${BASE_DIR}/${THREADS_ORIG} +gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_MINI} -ex "thread apply all bt" -ex "q" 2> /dev/null | grep -e '^#' | sed 's/: [0-9]\+\(x[0-9]\+\( <[^>]\+>\)\?\)\?/: 0/g' > ${BASE_DIR}/${THREADS_MINI} if ! diff ${BASE_DIR}/${THREADS_ORIG} ${BASE_DIR}/${THREADS_MINI} > /dev/null; then fail "backtraces are different" -- 2.7.4 From c24000a957f0256275bb9d8da8840d2ee953773e Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Thu, 2 Apr 2020 14:14:45 +0200 Subject: [PATCH 10/16] dump_systemstate: report ran command faithfully Change-Id: Id4b830804ae420b60a7250c220a56a5695f80cff Signed-off-by: Michal Bloch --- src/dump_systemstate/dump_systemstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dump_systemstate/dump_systemstate.c b/src/dump_systemstate/dump_systemstate.c index 814acda..dd183e6 100644 --- a/src/dump_systemstate/dump_systemstate.c +++ b/src/dump_systemstate/dump_systemstate.c @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) dpercent = get_disk_used_percent("/opt"); if (90 < dpercent) { - fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt)\n", dpercent); + fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt --exclude=/opt/usr)\n", dpercent); char *du_args[] = {"/bin/du", "-ah", "/opt", "--exclude=/opt/usr", NULL}; spawn_wait_checked(du_args, NULL); } -- 2.7.4 From cf5606eec31acfc055d6d1a4f963ca875dae326e Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 2 Apr 2020 13:40:03 +0200 Subject: [PATCH 11/16] Release 6.0.14 This release brings /opt/usr reporting to dump_systemstate utility. Change-Id: I1aada1d58681272703b7c64181d0c7aceccc3d84 --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 5717544..c405a49 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -13,7 +13,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 6.0.13 +Version: 6.0.14 Release: 1 Group: Framework/system License: Apache-2.0 and BSD-2-Clause and MIT -- 2.7.4 From 2ff06d121be26113a27b83874d1ffc3fc8caa141 Mon Sep 17 00:00:00 2001 From: Wiktor Gerstenstein Date: Wed, 19 Feb 2020 17:37:21 +0100 Subject: [PATCH 12/16] Add tizen-manifest.xml to crash-reports Change-Id: I6fc7f723ad33cd825e2c5f85b42c7b134a0f1f8b --- packaging/crash-worker.manifest | 1 + packaging/crash-worker.spec | 1 + src/crash-manager/crash-manager.c | 73 +++++++++++++++++++++- src/crash-manager/crash-manager.h | 1 + tests/system/CMakeLists.txt | 1 + .../copy_tizen_manifest.sh.template | 56 +++++++++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tests/system/copy_tizen_manifest/copy_tizen_manifest.sh.template diff --git a/packaging/crash-worker.manifest b/packaging/crash-worker.manifest index 1ed60c3..0b9ab26 100644 --- a/packaging/crash-worker.manifest +++ b/packaging/crash-worker.manifest @@ -21,6 +21,7 @@ + diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 5717544..58e9041 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -245,6 +245,7 @@ mkdir -p %{buildroot}%{crash_temp} %{_libdir}/crash-worker/system-tests/check_minicore_mem/cp.sh %{_libdir}/crash-worker/system-tests/cmp_backtraces/cmp_backtraces.sh %{_libdir}/crash-worker/system-tests/cmp_backtraces/cp.sh +%{_libdir}/crash-worker/system-tests/copy_tizen_manifest/copy_tizen_manifest.sh %{_libdir}/crash-worker/system-tests/crash_root_path/crash_root_path.sh %{_libdir}/crash-worker/system-tests/critical_process/critical_process.sh %{_libdir}/crash-worker/system-tests/dbus_notify/dbus_notify.sh diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 0f4cdae..682da09 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -59,6 +59,7 @@ #define CRASH_TEMP_SUBDIR "/temp/" #define CRASH_PATH_SUBDIR "/dump/" #define LIVE_PATH_SUBDIR "/livedump/" +#define APP_PATH_SUBDIR "/app/" #define WAIT_FOR_OPT_TIMEOUT_SEC 60 @@ -152,6 +153,30 @@ out_free: return have_pkgid && *pkgid != NULL; } +static char *get_app_root_path(const char *pkgid) +{ + char *root_path = NULL; + pkgmgrinfo_pkginfo_h handle; + int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + if (ret != PMINFO_R_OK) + return NULL; + + ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path); + if (ret != PMINFO_R_OK) { + _E("Unable to get app root path for %s", pkgid); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return NULL; + } + + char *path = root_path ? strdup(root_path) : NULL; + if (path == NULL && root_path != NULL) + _E("Failed to get app root path for %s. strdup() error: %m", pkgid); + + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + + return path; +} + static bool set_appinfo(char *exepath, char **appid, char **pkgid) { char *a = NULL, *p = NULL; @@ -381,6 +406,8 @@ bool set_crash_info(struct crash_info *cinfo) || -1 == asprintf(&cinfo->result_path, "%s/%s%s", crash_dump_path, cinfo->name, suffix)) goto out_oom; + if (is_app) + cinfo->app_root_path = get_app_root_path(cinfo->pkgid); if (mkdir(cinfo->pfx, 0775) < 0) { _E("Failed to mkdir %s: %m", cinfo->pfx); @@ -689,6 +716,47 @@ static bool process_continue(const pid_t pid) return kill_pid(pid, SIGCONT, false); } +static bool copy_application_data(struct crash_info *cinfo, const char *filename) +{ + bool is_ok = false; + char *src_filepath = NULL; + char *dst_filepath = NULL; + char *dst_dirpath = NULL; + + if (cinfo->app_root_path && + (asprintf(&src_filepath, "%s/%s", cinfo->app_root_path, filename) == -1 + || asprintf(&dst_filepath, "%s%s%s", cinfo->pfx, APP_PATH_SUBDIR, filename) == -1)) { + _E("Failed to asprintf for %s file in %s path", filename, + !src_filepath ? cinfo->app_root_path : cinfo->pfx); + goto out; + } + + if (!src_filepath || access(src_filepath, F_OK)) + goto out; + + dst_dirpath = strdup(dst_filepath); + if (dst_dirpath == NULL) { + _E("Failed to copy dst_filepath: %s", dst_filepath); + goto out; + } + dst_dirpath = dirname(dst_dirpath); + if (mkdir(dst_dirpath, 0775) < 0 && errno != EEXIST) { + _E("Failed to mkdir %s (%m)", dst_dirpath); + goto out; + } + + if (copy_file(dst_filepath, src_filepath)) + _E("Cannot copy %s file to: %s", src_filepath, dst_filepath); + else + is_ok = true; +out: + free(src_filepath); + free(dst_filepath); + free(dst_dirpath); + + return is_ok; +} + static bool execute_crash_modules(struct crash_info *cinfo) { int exit_code = 0; @@ -710,6 +778,7 @@ static bool execute_crash_modules(struct crash_info *cinfo) } execute_crash_stack(cinfo, NULL); + (void)copy_application_data(cinfo, "tizen-manifest.xml"); // manifest.xml is optional because not every application has that. if (cinfo->livedump) process_continue(cinfo->pid_info); @@ -1004,6 +1073,7 @@ static void free_crash_info(struct crash_info *cinfo) free(cinfo->cmd_path); free(cinfo->temp_dir); free(cinfo->result_path); + free(cinfo->app_root_path); free(cinfo->pfx); free(cinfo->info_path); free(cinfo->core_path); @@ -1027,7 +1097,8 @@ void crash_info_init(struct crash_info *cinfo) cinfo->cmd_line = NULL; cinfo->cmd_path = NULL; cinfo->temp_dir = NULL; - cinfo->pfx = NULL; + cinfo->app_root_path = NULL; + cinfo->pfx = NULL; cinfo->result_path = NULL; cinfo->info_path = NULL; cinfo->core_path = NULL; diff --git a/src/crash-manager/crash-manager.h b/src/crash-manager/crash-manager.h index 1e26941..6e66af1 100644 --- a/src/crash-manager/crash-manager.h +++ b/src/crash-manager/crash-manager.h @@ -38,6 +38,7 @@ struct crash_info { char *cmd_path; char *temp_dir; char *name; + char *app_root_path; char *result_path; char *pfx; char *info_path; diff --git a/tests/system/CMakeLists.txt b/tests/system/CMakeLists.txt index c17c517..37fe6ff 100644 --- a/tests/system/CMakeLists.txt +++ b/tests/system/CMakeLists.txt @@ -19,6 +19,7 @@ endmacro() configure_test("check_minicore_mem") configure_test("cmp_backtraces" "cp") +configure_test("copy_tizen_manifest") configure_test("crash_root_path") configure_test("critical_process") configure_test("dbus_notify") diff --git a/tests/system/copy_tizen_manifest/copy_tizen_manifest.sh.template b/tests/system/copy_tizen_manifest/copy_tizen_manifest.sh.template new file mode 100644 index 0000000..2e52e6e --- /dev/null +++ b/tests/system/copy_tizen_manifest/copy_tizen_manifest.sh.template @@ -0,0 +1,56 @@ +#!/bin/bash + +# Check the report for tizen-manifest.xml file + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +CRASH_MANAGER_CONF=/etc/crash-manager.conf + +clean_crash_dump +clean_temp + +pid=0 +psout=$(ps -ewo pid,cmd | awk -v OFS=$' ' '$cmd ~ "/apps/" || $cmd ~ "org."') +if [ $(wc -l <<< "$psout") -le 1 ]; then + skip "no run application found" +fi + +while IFS=$' ' read -r pidd cmd +do + cmd=${cmd%%[[:space:]]*} + for VARIABLE in 1 2 # path levels count to check + do + cmd=$(dirname $cmd) + if [ -f "$cmd/tizen-manifest.xml" ]; then + pid=$pidd + break 2 + fi + done +done <<< "$psout" + +test $pid -ne 0 || fail "no running application has a tizen-manifest file" + +kill -6 $pid + +sleep 2 + +wait_for_app crash-manager + +pushd ${CRASH_DUMP_PATH} +name=$(echo *_${pid}_*) +name=${name%.zip} + +test -f "${name}.zip" || fail "crash report not found" +unzip "${name}.zip" || fail "unable to extract archive" + +test -s "${name}/app/tizen-manifest.xml" || fail "tizen-manifest corrupt or not found" + +for i in ${CRASH_TEMP_PATH}/*; do + test -a "${i}" && fail "temp directory not cleaned up" +done + +exit_ok -- 2.7.4 From 4dbe9071ca99ae3c8f7b9b3cf2085b0648294e97 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 7 Apr 2020 13:27:12 +0200 Subject: [PATCH 13/16] Fix build id reading when the binary don't have it Change-Id: I82db306cad980104e096e8b738db24fc5e3547bb --- src/crash-manager/so-info.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/crash-manager/so-info.c b/src/crash-manager/so-info.c index 678638a..b3f76a9 100644 --- a/src/crash-manager/so-info.c +++ b/src/crash-manager/so-info.c @@ -85,13 +85,13 @@ static unsigned char *map_file(const char *filename, int64_t *size) static Elf##bits##_Off build_id_section_address##bits(const unsigned char *mapped_file, const int64_t size)\ {\ if (mapped_file <= 0)\ - return -1;\ + return 0;\ \ Elf##bits##_Ehdr *elheader = (Elf##bits##_Ehdr*)mapped_file;\ Elf##bits##_Shdr *sec = (Elf##bits##_Shdr*)(mapped_file + elheader->e_shoff);\ \ if (size < (intptr_t)sec + elheader->e_shstrndx*sizeof(Elf##bits##_Shdr) - (intptr_t)mapped_file)\ - return -2;\ + return 0;\ \ char *names = (char *)(mapped_file + sec[elheader->e_shstrndx].sh_offset);\ \ @@ -102,7 +102,7 @@ static Elf##bits##_Off build_id_section_address##bits(const unsigned char *mappe return sec[i].sh_offset;\ } \ \ - return -1;\ + return 0;\ } \ DECLARE_BUILD_ID_SECTION_ADDRESS(32) @@ -157,10 +157,12 @@ static int get_build_id(char *filename, char **build_id) if (mapped_file > 0) { Elf64_Off offset = build_id_section_address(mapped_file, size); - if (offset > 0) + if (offset > 0) { ret = get_build_id_from(mapped_file, offset, build_id); - else + } else { + _W("File %s doesn't contain build-id", filename); ret = -1; + } munmap(mapped_file, size); } else { -- 2.7.4 From 8b7e006c08c8e01d7440fee4ceae20e3dbfd3d94 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 8 Apr 2020 16:33:18 +0200 Subject: [PATCH 14/16] crash-manager: Fix free of invalid pointer returned by dirname() This fixes SVACE issue (overwriting dst_dirpath pointer by dirname(3) result, which should not be freed). Change-Id: Iad2ed92c6111f8133e3c6363876ff3fad80557f3 --- src/crash-manager/crash-manager.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 682da09..e7ff778 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -735,13 +735,14 @@ static bool copy_application_data(struct crash_info *cinfo, const char *filename goto out; dst_dirpath = strdup(dst_filepath); - if (dst_dirpath == NULL) { - _E("Failed to copy dst_filepath: %s", dst_filepath); + char *dst_dirname = dirname(dst_dirpath); + if (dst_dirpath == NULL || dst_dirname == NULL) { + _E("Out of memory"); goto out; } - dst_dirpath = dirname(dst_dirpath); - if (mkdir(dst_dirpath, 0775) < 0 && errno != EEXIST) { - _E("Failed to mkdir %s (%m)", dst_dirpath); + + if (mkdir(dst_dirname, 0775) < 0 && errno != EEXIST) { + _E("Failed to mkdir %s: %m", dst_dirname); goto out; } -- 2.7.4 From 2e5c4e13576fcda223207b2d654c6f0e10a4eed9 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 8 Apr 2020 16:33:50 +0200 Subject: [PATCH 15/16] crash-manager: Clarify when tizen-manifest.xml is copied Change-Id: Iba48fc54f9809c077b5ebc0fbe8463186abd767e --- src/crash-manager/crash-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index e7ff778..c889cdb 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -779,7 +779,7 @@ static bool execute_crash_modules(struct crash_info *cinfo) } execute_crash_stack(cinfo, NULL); - (void)copy_application_data(cinfo, "tizen-manifest.xml"); // manifest.xml is optional because not every application has that. + (void)copy_application_data(cinfo, "tizen-manifest.xml"); // manifest is optional because only tizen applications have it if (cinfo->livedump) process_continue(cinfo->pid_info); -- 2.7.4 From 9780ef741d88fa958ecaeb9abf08be3e8b346ae5 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 7 Apr 2020 10:06:06 +0200 Subject: [PATCH 16/16] Fix libcrash-service test Because of second trap, core_pattern didn't have the correct value restored Change-Id: I71c6f2c401c293769caa816fe2e767b30578d7b6 --- tests/system/libcrash-service/libcrash-service.sh.template | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/system/libcrash-service/libcrash-service.sh.template b/tests/system/libcrash-service/libcrash-service.sh.template index 611978a..97b81cf 100755 --- a/tests/system/libcrash-service/libcrash-service.sh.template +++ b/tests/system/libcrash-service/libcrash-service.sh.template @@ -29,8 +29,6 @@ wait_for_file ${LIVE_DUMP_PATH}/kenny*zip kill -9 ${KENNY_PID} -trap popd 0 - pushd ${LIVE_DUMP_PATH} unzip kenny*zip -- 2.7.4