summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWiktor Gerstenstein <w.gerstenste@partner.samsung.com>2020-02-19 17:37:21 +0100
committerWiktor Gerstenstein <w.gerstenste@partner.samsung.com>2020-04-04 00:47:50 +0200
commit2ff06d121be26113a27b83874d1ffc3fc8caa141 (patch)
tree8b1a050dbd87db072c51ad7d62e019a68e76e33e
parentec59290483ecf6a69480944fe0acacf2fb153655 (diff)
downloadcrash-worker-2ff06d121be26113a27b83874d1ffc3fc8caa141.tar.gz
crash-worker-2ff06d121be26113a27b83874d1ffc3fc8caa141.tar.bz2
crash-worker-2ff06d121be26113a27b83874d1ffc3fc8caa141.zip
Add tizen-manifest.xml to crash-reports
Change-Id: I6fc7f723ad33cd825e2c5f85b42c7b134a0f1f8b
-rw-r--r--packaging/crash-worker.manifest1
-rw-r--r--packaging/crash-worker.spec1
-rw-r--r--src/crash-manager/crash-manager.c73
-rw-r--r--src/crash-manager/crash-manager.h1
-rw-r--r--tests/system/CMakeLists.txt1
-rw-r--r--tests/system/copy_tizen_manifest/copy_tizen_manifest.sh.template56
6 files changed, 132 insertions, 1 deletions
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 @@
<filesystem path="/usr/lib/crash-worker/system-tests/report_type_info/report_type_info.sh" label="User::Shell" exec_label="User::Shell"/>
<filesystem path="/usr/lib/crash-worker/system-tests/without_core/without_core.sh" label="User::Shell" exec_label="User::Shell"/>
<filesystem path="/usr/lib/crash-worker/system-tests/crash_root_path/crash_root_path.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/copy_tizen_manifest/copy_tizen_manifest.sh" label="User::Shell" exec_label="User::Shell"/>
<filesystem path="/usr/lib/crash-worker/system-tests/utils/btee" label="User::Shell" exec_label="User::Shell"/>
<filesystem path="/usr/lib/crash-worker/system-tests/utils/kenny" label="User::Shell" exec_label="User::Shell"/>
<filesystem path="/usr/lib/crash-worker/system-tests/utils/minicore-utils.sh" label="User::Shell" exec_label="User::Shell"/>
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