log_dump: Honour CrashRootPath from config 43/203443/6
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 17 Apr 2019 14:06:55 +0000 (16:06 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 18 Apr 2019 10:24:34 +0000 (12:24 +0200)
Change-Id: I738e241a1fbb12447f32fcc7f963a8185eec0f12

packaging/crash-worker_system-tests.spec
src/log_dump/CMakeLists.txt
src/log_dump/log_dump.c
tests/system/CMakeLists.txt
tests/system/log_dump_crash_root_path/log_dump_crash_root_path.sh.template [new file with mode: 0644]

index 0d73a63..4cdcf12 100644 (file)
@@ -62,6 +62,7 @@ cd tests/system
 %{_libdir}/crash-worker_system-tests/info_file/info_file.sh
 %{_libdir}/crash-worker_system-tests/log_dump_normal/log_dump_normal.sh
 %{_libdir}/crash-worker_system-tests/log_dump_short/log_dump_short.sh
+%{_libdir}/crash-worker_system-tests/log_dump_crash_root_path/log_dump_crash_root_path.sh
 %{_libdir}/crash-worker_system-tests/log_file/log_file.sh
 %{_libdir}/crash-worker_system-tests/so_info_file/so_info_file.sh
 %{_libdir}/crash-worker_system-tests/report_basic/report_basic.sh
index c3b6843..a7446a2 100644 (file)
@@ -7,6 +7,7 @@ SET(LOG_DUMP_SRCS
        dbus-handler.c
        ${CMAKE_SOURCE_DIR}/src/shared/util.c
        ${CMAKE_SOURCE_DIR}/src/shared/spawn.c
+       ${CMAKE_SOURCE_DIR}/src/shared/config.c
    )
 
 INCLUDE(FindPkgConfig)
@@ -14,6 +15,7 @@ pkg_check_modules(log_dump_pkgs REQUIRED
        dlog
        capi-system-info
        libtzplatform-config
+       iniparser
        gio-2.0
        )
 
index 03d1b0f..868e163 100644 (file)
 #include <system_info.h>
 #include <tzplatform_config.h>
 
-#include "log_dump.h"
+#include "defs.h"
 #include "dbus-handler.h"
+#include "log_dump.h"
+#include "shared/config.h"
 #include "shared/spawn.h"
 #include "shared/util.h"
 
@@ -46,6 +48,8 @@ static const struct option opts[] = {
        { 0, 0, 0, 0 }
 };
 
+/* crash worker configuration - for admin-selectable CrashRootPath */
+config_t config;
 /* tzplaform vars */
 char *dir_scripts;
 /* dynamic vars */
@@ -80,7 +84,7 @@ static bool init_temp_dir(char *const temp_root, char **temp_dir)
 
 static char *crash_root_get(void)
 {
-       return strdup(tzplatform_getenv(TZ_SYS_CRASH_ROOT));
+       return config.crash_root_path;
 }
 
 static bool init_vars(const char *crash_root)
@@ -279,6 +283,9 @@ int main(int argc, char *argv[])
        int c, ret;
        int option;
 
+       if (!config_init(&config, CRASH_MANAGER_CONFIG_PATH))
+               return false;
+
        /* need to do this first, because even usage() uses the vars */
        if (!init_vars(crash_root_get())) {
                printf("Unable to initialize - please check program logs");
@@ -300,5 +307,7 @@ int main(int argc, char *argv[])
        else
                ret = log_dump(option);
 
+       config_free(&config);
+
        return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }
index fbe4129..0767dc1 100644 (file)
@@ -34,6 +34,7 @@ configure_test("without_core")
 configure_test("crash_root_path")
 configure_test("log_dump_short")
 configure_test("log_dump_normal")
+configure_test("log_dump_crash_root_path")
 
 get_property(TESTS_LIST GLOBAL PROPERTY TMP_TESTS_LIST)
 
diff --git a/tests/system/log_dump_crash_root_path/log_dump_crash_root_path.sh.template b/tests/system/log_dump_crash_root_path/log_dump_crash_root_path.sh.template
new file mode 100644 (file)
index 0000000..40a0fa3
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# Custom report path test
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+    CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+tmpdir=$(mktemp -d /tmp/logdump-crash-root-path-test.XXXXXX)
+
+CRASH_MANAGER_CONF=/etc/crash-manager.conf
+mount -o rw,remount /
+backup_file ${CRASH_MANAGER_CONF}
+sed -ie 's,^CrashRootPath=.*,,g' ${CRASH_MANAGER_CONF}
+echo "CrashRootPath=$tmpdir" >> ${CRASH_MANAGER_CONF}
+
+log_dump --short
+logfile="${tmpdir}"/debug/* # there shall be only one file
+
+check_file_exists "$logfile"
+
+num=`unzip -qql "$logfile" | wc -l`
+if [ $num -ne 2 ]; then
+        exit_with_code "FAIL: 'log_dump --short' report contains $num files - 2 expected" 1
+fi
+
+restore_file ${CRASH_MANAGER_CONF}
+
+exit_with_code "SUCCESS" 0