From 1cecf42939be3bab650d8b99202036d61c1679cc Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 25 Jul 2019 08:50:37 +0200 Subject: [PATCH] Add --output option This option allows to specify the custom output directory for reports Change-Id: I7a49d958f268f73f346b7f5b692cf3ce56808f37 --- packaging/crash-worker_system-tests.spec | 1 + src/crash-manager/crash-manager.c | 19 ++++++++++++- tests/system/CMakeLists.txt | 1 + tests/system/output_param/output_param.sh.template | 31 ++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 tests/system/output_param/output_param.sh.template diff --git a/packaging/crash-worker_system-tests.spec b/packaging/crash-worker_system-tests.spec index cc33e03..3fea883 100644 --- a/packaging/crash-worker_system-tests.spec +++ b/packaging/crash-worker_system-tests.spec @@ -78,6 +78,7 @@ cd tests/system %{_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_core/without_core.sh +%{_libdir}/crash-worker_system-tests/output_param/output_param.sh %if %{with livedumper} %{_libdir}/crash-worker_system-tests/livedumper/livedumper.sh %endif diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 5f70610..7d30c92 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -105,6 +105,7 @@ struct crash_info { char *log_path; char appid[APPID_MAX]; char pkgid[PKGNAME_MAX]; + char *output_path; bool livedump; bool kill; bool print_result_path; @@ -205,6 +206,15 @@ static int prepare_paths(struct crash_info* cinfo) int tmp_len; const char *crash_subdir = cinfo->livedump ? LIVE_PATH_SUBDIR : CRASH_PATH_SUBDIR; + if (cinfo->output_path) { + free(config.crash_root_path); + config.crash_root_path = strdup(cinfo->output_path); + if (!config.crash_root_path) { + _E("strdup() error: %m"); + return 0; + } + } + tmp_len = strlen(config.crash_root_path) + strlen(crash_subdir); crash_dump_path = (char*)malloc(tmp_len + 1); if (crash_dump_path == NULL) { @@ -342,6 +352,7 @@ static void print_help(const char *name) " -l --live get coredump of running process\n" " -k --kill-after-dump kill after dump (only with --live option)\n" " -r --print print report path to stdout\n" + " -o --output output directory\n" " -h --help this message\n" "\n" "for --live option only --pid is required\n" @@ -377,10 +388,11 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[]) {"live", no_argument, NULL, 'l'}, {"kill-after-dump", no_argument, NULL, 'k'}, {"print", no_argument, NULL, 'r'}, + {"output", required_argument, NULL, 'o'}, {"help", no_argument, NULL, 'h'}, }; - while ((opt = getopt_long(argc, argv, "p:u:g:i:s:t:hlkr", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "p:u:g:i:s:t:hlkro:", long_options, NULL)) != -1) { switch (opt) { case 'p': GET_NUMBER(pid) @@ -413,6 +425,10 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[]) case 'r': cinfo->print_result_path = true; break; + case 'o': + cinfo->output_path = optarg; + _D("output path: %s\n", optarg); + break; case 'h': default: print_help(argv[0]); @@ -1236,6 +1252,7 @@ static void crash_info_init(struct crash_info *cinfo) cinfo->print_result_path = false; cinfo->tid_info = -1; cinfo->time_info = 0; + cinfo->output_path = NULL; } static bool run(struct crash_info *cinfo) diff --git a/tests/system/CMakeLists.txt b/tests/system/CMakeLists.txt index 7db25e2..309e572 100644 --- a/tests/system/CMakeLists.txt +++ b/tests/system/CMakeLists.txt @@ -39,6 +39,7 @@ configure_test("dump_systemstate_extras") configure_test("livedumper") configure_test("extra_script") configure_test("dbus_notify") +configure_test("output_param") get_property(TESTS_LIST GLOBAL PROPERTY TMP_TESTS_LIST) diff --git a/tests/system/output_param/output_param.sh.template b/tests/system/output_param/output_param.sh.template new file mode 100755 index 0000000..7379009 --- /dev/null +++ b/tests/system/output_param/output_param.sh.template @@ -0,0 +1,31 @@ +#!/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 + +OUTPUT=/tmp/output_dir/ +mkdir -p ${OUTPUT} + +save_core_pattern +trap restore_core_pattern 0 + +echo "|/usr/bin/crash-manager -p %p -u %u -g %g -s %s -t %t --output ${OUTPUT}" > /proc/sys/kernel/core_pattern + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny 10 & + sleep 1 + killall -6 kenny +} 1> /dev/null 2>&1 + +sleep 2 + +wait_for_file ${OUTPUT}/dump/*zip +rm -rf ${OUTPUT} + +exit_ok + -- 2.7.4