diff options
author | Mateusz Moscicki <m.moscicki2@partner.samsung.com> | 2020-05-04 10:00:07 +0200 |
---|---|---|
committer | Mateusz Moscicki <m.moscicki2@partner.samsung.com> | 2020-05-04 10:01:58 +0200 |
commit | 15a18f4b35a569352b94a33ea3579562b404bd55 (patch) | |
tree | 3c39fb83110e7db4edf783512eef4f312fb19701 | |
parent | dcf6aad965ea4b24b649c93b6608a46070d52323 (diff) | |
parent | 3d7768f421d9ad89f63185f83fd607ac44571640 (diff) | |
download | crash-worker-15a18f4b35a569352b94a33ea3579562b404bd55.tar.gz crash-worker-15a18f4b35a569352b94a33ea3579562b404bd55.tar.bz2 crash-worker-15a18f4b35a569352b94a33ea3579562b404bd55.zip |
Merge branch 'tizen' into tizen_5.5submit/tizen_5.5/20200504.104440accepted/tizen/5.5/unified/20200505.133412
Change-Id: I593619b2394cc321a92cc76582ac433c86de85c5
-rw-r--r-- | packaging/crash-worker.spec | 2 | ||||
-rw-r--r-- | src/crash-manager/crash-manager.c | 52 | ||||
-rw-r--r-- | src/crash-manager/crash-popup-launch.c | 2 | ||||
-rw-r--r-- | src/crash-manager/so-info.c | 99 | ||||
-rw-r--r-- | src/crash-manager/so-info.h | 2 |
5 files changed, 148 insertions, 9 deletions
diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 590b396..2d8877b 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: 5.5.37 +Version: 5.5.38 Release: 1 Group: Framework/system License: Apache-2.0 and BSD-2-Clause and MIT diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index b64908c..27929af 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -833,6 +833,57 @@ out: return is_ok; } +static void copy_application_xmls(struct crash_info *cinfo) +{ + const char * const app_config_paths[] = { + tzplatform_getenv(TZ_SYS_RW_PACKAGES), + tzplatform_getenv(TZ_SYS_RO_PACKAGES) + }; + char *src_filepath = NULL; + char *dst_filepath = NULL; + char *dst_dirpath = NULL; + char maps_path[PATH_MAX] = {'\0'}; + + if (asprintf(&dst_dirpath, "%s%s", cinfo->pfx, APP_PATH_SUBDIR) == -1) { + _E("Failed to asprintf for dst dir: %s%s", cinfo->pfx, APP_PATH_SUBDIR); + return; + } + if (mkdir(dst_dirpath, 0775) < 0 && errno != EEXIST) { + _E("Failed to mkdir %s (%m)", dst_dirpath); + goto out; + } + if (snprintf(maps_path, sizeof(maps_path), "/proc/%d/maps", cinfo->pid_info) <= 0) { + _E("Failed to snprintf maps path: /proc/%d/maps", cinfo->pid_info); + goto out; + } + + GSList *app_list = get_app_name_from_map(maps_path); + for (GSList *iterator = app_list; iterator; iterator = iterator->next) { + char *app_name = (char *)iterator->data; + + if (asprintf(&dst_filepath, "%s%s.xml", dst_dirpath, app_name) == -1) { + _E("Failed to asprintf dst file path: %s%s%s.xml", cinfo->pfx, APP_PATH_SUBDIR, app_name); + } else { + for (size_t i = 0; i < ARRAY_SIZE(app_config_paths); ++i) { + if (asprintf(&src_filepath, "%s/%s%s", app_config_paths[i], app_name, ".xml") == -1) { + _E("Failed to asprintf source file path: %s", src_filepath); + continue; + } + if (file_exists(src_filepath)) { + if (copy_file(dst_filepath, src_filepath)) + _E("Cannot copy file from %s to: %s", src_filepath, dst_filepath); + } + free(src_filepath); + } + free(dst_filepath); + } + free(app_name); + } + g_slist_free(app_list); +out: + free(dst_dirpath); +} + static bool execute_crash_modules(struct crash_info *cinfo) { int exit_code = 0; @@ -855,6 +906,7 @@ static bool execute_crash_modules(struct crash_info *cinfo) execute_crash_stack(cinfo, NULL); (void)copy_application_data(cinfo, "tizen-manifest.xml"); // manifest is optional because only tizen applications have it + copy_application_xmls(cinfo); if (cinfo->livedump) process_continue(cinfo->pid_info); diff --git a/src/crash-manager/crash-popup-launch.c b/src/crash-manager/crash-popup-launch.c index 1f24915..4ec2663 100644 --- a/src/crash-manager/crash-popup-launch.c +++ b/src/crash-manager/crash-popup-launch.c @@ -77,8 +77,6 @@ bool launch_crash_popup(GDBusConnection *conn, const char *const cmdline, const out: if (reply) g_variant_unref(reply); - if (parameters) - g_variant_unref(parameters); return ret; } diff --git a/src/crash-manager/so-info.c b/src/crash-manager/so-info.c index b3f76a9..5dc26ff 100644 --- a/src/crash-manager/so-info.c +++ b/src/crash-manager/so-info.c @@ -16,8 +16,10 @@ * limitations under the License. */ +#include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <libgen.h> #include <limits.h> #include <string.h> #include <elf.h> @@ -34,6 +36,7 @@ #include <rpm/header.h> #include "shared/log.h" #include "shared/util.h" +#include <tzplatform_config.h> #define BID_SNAME ".note.gnu.build-id" @@ -365,8 +368,10 @@ void search_for_tpk(rpmts ts, GSList *pkgs) char *get_app_name_from_path(const char *file_path) { - static const char *prefix[] = {"/usr/apps/", - "/opt/usr/globalapps/"}; + const char * const prefix[] = { + tzplatform_mkpath(TZ_SYS_RO_APP, "/"), + tzplatform_mkpath(TZ_SYS_RW_APP, "/") + }; for (size_t i = 0; i < ARRAY_SIZE(prefix); i++) { if (strncmp(file_path, prefix[i], strlen(prefix[i])) != 0) @@ -381,6 +386,86 @@ char *get_app_name_from_path(const char *file_path) return NULL; } +GSList *get_app_name_from_map(char *map_path) +{ + GSList *app_name_list = NULL; + GSList *file_list = get_filepaths(map_path); + for (GSList *iterator = file_list; iterator; iterator = iterator->next) { + char *app_name = get_app_name_from_path((char *)iterator->data); + if (app_name) + app_name_list = g_slist_append(app_name_list, app_name); + free(iterator->data); + } + g_slist_free(file_list); + return app_name_list; +} + +bool replace_suffix(char *string, char *suffix, char *replace, char* buff, size_t len) +{ + assert(string); + assert(suffix); + assert(replace); + assert(buff); + + char *sub = strstr(string, suffix); + if (sub == NULL) + return false; + + size_t prefix_len = sub - string; + if (len < prefix_len) { + _I("Buffer too small"); + return false; + } + + strncpy(buff, string, prefix_len); + if (snprintf(&buff[prefix_len], len, "%s", replace) < 0) { + _E("Suffix replaceing error (%s %s -> %s): %m", string, suffix, replace); + return false; + } + + return true; +} + +bool correct_file_path(const char *file_path, char *buff, size_t len) +{ + assert(file_path); + assert(buff); + + bool result = false; + char file_path_copy[PATH_MAX]; + + strncpy(file_path_copy, file_path, sizeof(file_path_copy) - 1); + + char *file_name = basename(file_path_copy); + char dll_name[PATH_MAX]; + + if (!replace_suffix(file_name, ".ni.dll", ".dll", dll_name, sizeof(dll_name))) + return false; + + _D("Correcting the file: %s", file_path); + + strncpy(file_path_copy, file_path, sizeof(file_path_copy) - 1); + char *dir_name = dirname(file_path_copy); + + if (!file_exists_in_dir(dir_name, dll_name)) { + char tmp_dir_name[PATH_MAX]; + + strncpy(tmp_dir_name, dir_name, sizeof(tmp_dir_name) - 1); + dir_name = dirname(tmp_dir_name); + + if (!file_exists_in_dir(dir_name, dll_name)) { + _D("Cannot find the corresponding dll file for: %s", file_path); + return false; + } + } + + result = snprintf(buff, len, "%s/%s", dir_name, dll_name) > 0; + if (!result) + _E("Can not correct file path %s: %m", file_path); + + return result; +} + void get_and_save_so_info(char *map_path, char *out_path) { FILE *f = fopen(out_path, "w"); @@ -396,12 +481,16 @@ void get_and_save_so_info(char *map_path, char *out_path) for (GSList *iterator = file_list; iterator; iterator = iterator->next) { char *file_path = (char *)iterator->data; - + char modified_file_path[PATH_MAX]; char *build_id = NULL; - if (is_dotnet_file(file_path)) + + if (is_dotnet_file(file_path)) { build_id = strdup(""); - else if (get_build_id(file_path, &build_id) <= 0 || build_id == NULL) + if (correct_file_path(file_path, modified_file_path, sizeof(modified_file_path))) + file_path = modified_file_path; + } else if (get_build_id(file_path, &build_id) <= 0 || build_id == NULL) { continue; + } char *rpm_info = get_rpm_info(ts, file_path); if (rpm_info == NULL) { diff --git a/src/crash-manager/so-info.h b/src/crash-manager/so-info.h index 0b28770..0248855 100644 --- a/src/crash-manager/so-info.h +++ b/src/crash-manager/so-info.h @@ -20,5 +20,5 @@ #define __SO_INFO_H__ void get_and_save_so_info(char *map_filename, char *out_file); - +GSList *get_app_name_from_map(char *map_path); #endif |