From 236600bdad00d1f53b4221e0cac4a47bc64d1645 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 3 Oct 2018 13:59:18 +0200 Subject: [PATCH 01/16] Define _GNU_SOURCE once for whole codebase There is no need to repeat this in every file. Change-Id: Ia788840d819b8d72122296a5e5d64aa2a7c3cb40 --- CMakeLists.txt | 2 +- src/crash-manager/crash-manager.c | 2 -- src/crash-manager/dbus_notify.c | 1 - src/crash-stack/CMakeLists.txt | 2 +- src/crash-stack/crash-stack.c | 1 - src/shared/util.c | 3 --- src/sys-assert/arm/backtrace.c | 2 +- src/sys-assert/arm_64/backtrace.c | 2 +- src/sys-assert/sys-assert.c | 1 - src/sys-assert/x86/backtrace.c | 2 +- src/sys-assert/x86/context.c | 2 +- 11 files changed, 6 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9834ed5..9f3222d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(crash-worker C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) +ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE=1) # Sub modules ADD_SUBDIRECTORY(src/crash-manager) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 95cbf8b..c48e29a 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -16,8 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE - #include #include #include diff --git a/src/crash-manager/dbus_notify.c b/src/crash-manager/dbus_notify.c index 6a8c5d8..cf78f6a 100644 --- a/src/crash-manager/dbus_notify.c +++ b/src/crash-manager/dbus_notify.c @@ -16,7 +16,6 @@ * Author: Mateusz Moscicki */ -#define _GNU_SOURCE #include #include #include diff --git a/src/crash-stack/CMakeLists.txt b/src/crash-stack/CMakeLists.txt index fd26fac..f996da9 100644 --- a/src/crash-stack/CMakeLists.txt +++ b/src/crash-stack/CMakeLists.txt @@ -21,7 +21,7 @@ else() set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-stub.c) endif() -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIE -D_GNU_SOURCE=1") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIE") set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") # Binary diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index a348067..00e2f3f 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -17,7 +17,6 @@ * Łukasz Stelmach * Rafał Pietruch */ -#define _GNU_SOURCE 1 /** * @file crash-stack.c diff --git a/src/shared/util.c b/src/shared/util.c index 2367524..775d6be 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -14,9 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include #include #include diff --git a/src/sys-assert/arm/backtrace.c b/src/sys-assert/arm/backtrace.c index 7520bba..2d1241a 100644 --- a/src/sys-assert/arm/backtrace.c +++ b/src/sys-assert/arm/backtrace.c @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define _GNU_SOURCE + #include #include #include diff --git a/src/sys-assert/arm_64/backtrace.c b/src/sys-assert/arm_64/backtrace.c index 3c8f560..21a10d4 100644 --- a/src/sys-assert/arm_64/backtrace.c +++ b/src/sys-assert/arm_64/backtrace.c @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define _GNU_SOURCE + #include #include #include diff --git a/src/sys-assert/sys-assert.c b/src/sys-assert/sys-assert.c index 75c7c3b..5af44ff 100644 --- a/src/sys-assert/sys-assert.c +++ b/src/sys-assert/sys-assert.c @@ -15,7 +15,6 @@ * limitations under the License. */ -#define _GNU_SOURCE #include #include #include diff --git a/src/sys-assert/x86/backtrace.c b/src/sys-assert/x86/backtrace.c index 0453bbb..4c07d86 100644 --- a/src/sys-assert/x86/backtrace.c +++ b/src/sys-assert/x86/backtrace.c @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define _GNU_SOURCE + #include #include #include diff --git a/src/sys-assert/x86/context.c b/src/sys-assert/x86/context.c index 5644d15..313ad86 100644 --- a/src/sys-assert/x86/context.c +++ b/src/sys-assert/x86/context.c @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define _GNU_SOURCE + #include #include #include -- 2.7.4 From 8f8c0ba615a88de9c78d6b24f3ce0470c7015cbd Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 7 Nov 2018 00:21:26 +0100 Subject: [PATCH 02/16] util: Fix and replace nullvec2str utility function with concatenate() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Multiple issues were found and fixed in previously-unused nullvec2str function, including major problem with possible stack corruption via long parameters. This commit completely rewrites the function to dynamically resize the buffer while appending new parameters to avoid previous problems. Additionally, name is changed to somewhat more developer friendly name. Influenced-by: Mateusz Mościcki and Michał Bloch Change-Id: Ia97e3851bb4b5779a14704098752e3644c487f0b --- src/shared/util.c | 31 ++++++++++++++++++++++++------- src/shared/util.h | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index 775d6be..bdb8259 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -828,17 +828,34 @@ char* get_exe_path(pid_t pid) return result; } -char *nullvec2str(char *const vec[]) +/* This function is supposed to accept same data as passed to execve + * (argv and envp), which can be arrays of strings as well as NULL + * pointer. + */ +char* concatenate(char *const vec[]) { - char command[PATH_MAX] = {0, }; + size_t length = 0; + for (char *const *p = vec; p && *p; p++) + length += strlen(*p) + 1; + + if (length == 0) + return strdup(""); + + char *str = (char *)malloc(length); + if (!str) + return NULL; - for (char *const *p = vec; *p; ++p) { - strncat(command, *p, sizeof(command)-1); - strncat(command, " ", sizeof(command)-1); + char *destp = str; + char *const *vecp = vec; + while (*vecp) { + destp = stpcpy(destp, *(vecp++)); + if (*vecp) + destp = stpcpy(destp, " "); } - command[sizeof(command)-1] = 0; - return strdup(command); + + return str; } + /** * @} */ diff --git a/src/shared/util.h b/src/shared/util.h index dfe40bf..53e0c7d 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -67,7 +67,7 @@ char* get_exe_path(pid_t pid); char* get_cmd_line(pid_t pid); -char *nullvec2str(char *const vec[]); +char* concatenate(char *const vec[]); #ifdef __cplusplus } -- 2.7.4 From 6accf65c59124e5a70e6034922ad14f8853fc511 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 7 Nov 2018 12:58:19 +0100 Subject: [PATCH 03/16] util: Add fsync_path to selectively flush file buffer to disk Change-Id: I3cd9169dafff33cdfbaf1c21955c37d38a524fae --- src/shared/util.c | 16 ++++++++++++++++ src/shared/util.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index bdb8259..85879d6 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -502,6 +502,22 @@ int run_command_timeout(char *path, char *args[], char *env[], int timeout) return res; } +int fsync_path(char *const path) +{ + int fd, ret; + + ret = fd = open(path, O_RDONLY); + if (fd >= 0) { + ret = fsync(fd); + close(fd); + } + + if (ret < 0) + _E("Unable to fsync %s: %m", path); + + return ret; +} + static int remove_dir_internal(int fd) { DIR *dir; diff --git a/src/shared/util.h b/src/shared/util.h index 53e0c7d..819a19c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -51,6 +51,8 @@ int run_command_write_fd_timeout(char *path, char *args[], char *env[], int dfd, int run_command_timeout(char *path, char *args[], char *env[], int timeout); +int fsync_path(char *const path); + int remove_dir(const char *path, int del_dir); int get_exec_pid(const char *execpath); -- 2.7.4 From 5991e4bda77ecc5b0f219370b2ba7fb5eb6f749d Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 20 Sep 2018 21:32:11 +0200 Subject: [PATCH 04/16] dump_systemstate: Replace extremely inefficient vconftool with buxton2ctl vconftool and buxton2ctl access the same data. vconftool is shell script which under the hood uses buxton2ctl. However, it does so in very inefficient manner - to get the keys it calls buxton2ctl once, but to get key values it calls buxton2ctl for each key. This causes it to fork On TM1 target with 548 keys in "db/" this means 548 fork & buxton2ctl execs. buxton2ctl gets the data from server via socket connection, meaning that it needs to connect & write request and wait for response. All of this together sums up to absurd - `buxton2ctl dump system` takes ~50ms, while `vconftool get db/ -r` takes more than 12seconds - which is roughly 250 times slower! sh-3.2# time buxton2ctl dump system >/dev/null real 0m0.050s user 0m0.040s sys 0m0.000s sh-3.2# time vconftool get db/ -r >/dev/null real 0m12.344s user 0m0.560s sys 0m1.190s With this change applied, dump_systemstate invocation time drops from 13seconds to 1.5-2sec (without logs), and from 13 seconds to 3-4secs (with logs, ie. -k -d -j options). Change-Id: I0cb042d18e5322d8246bf03ee142117217c83b4c --- packaging/crash-worker.spec | 1 + src/dump_systemstate/dump_systemstate.c | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 024821a..1bdc552 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -41,6 +41,7 @@ Requires: zip Requires: libelf Requires: libdw Requires: %{_sbindir}/minicoredumper +Requires: %{_bindir}/buxton2ctl %description crash-manager diff --git a/src/dump_systemstate/dump_systemstate.c b/src/dump_systemstate/dump_systemstate.c index d4c0e40..f7f254d 100644 --- a/src/dump_systemstate/dump_systemstate.c +++ b/src/dump_systemstate/dump_systemstate.c @@ -188,18 +188,14 @@ int main(int argc, char *argv[]) INFORM_IF_ERROR(ret) if (is_root) { - fprintf_fd(out_fd, "\n==== System configuration (/usr/bin/vconftool get memory, db, file)\n"); - char *get_mem_args[] = {"/bin/vconftool", "get", "memory/", "-r", NULL}; + fprintf_fd(out_fd, "\n==== System configuration (/usr/bin/buxton2ctl dump memory, system)\n"); + char *get_mem_args[] = {"/usr/bin/buxton2ctl", "dump", "memory", NULL}; ret = run_command_write_fd_timeout(get_mem_args[0], get_mem_args, NULL, out_fd, NULL, 0, TIMEOUT_DEFAULT); INFORM_IF_ERROR(ret) - char *get_db_args[] = {"/bin/vconftool", "get", "db/", "-r", NULL}; + char *get_db_args[] = {"/usr/bin/buxton2ctl", "dump", "system", NULL}; ret = run_command_write_fd_timeout(get_db_args[0], get_db_args, NULL, out_fd, NULL, 0, TIMEOUT_DEFAULT); INFORM_IF_ERROR(ret) - - char *get_file_args[] = {"/bin/vconftool", "get", "file/", "-r", NULL}; - ret = run_command_write_fd_timeout(get_file_args[0], get_file_args, NULL, out_fd, NULL, 0, TIMEOUT_DEFAULT); - INFORM_IF_ERROR(ret) } if (arg_dmesg && is_root) { -- 2.7.4 From 865653d839a318ab3834dd91f36938e8d6ef1d65 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 16 Nov 2018 16:34:31 +0100 Subject: [PATCH 05/16] Release 5.5.2 This version brings one major change - from now on buxton2ctl is used instead of vconftool to dump the internal database (buxton is the backend used by vconf anyway). The reason for this change is inefficency of vconftool utility, for details see commit 5991e4b ("dump_systemstate: Replace extremely inefficient vconftool with buxton2ctl"). Minor improvements include: - util: Add fsync_path to selectively flush file buffer to disk - util: Fix and replace nullvec2str utility function with concatenate() - Define _GNU_SOURCE once for whole codebase - packaging: Drop unused variables from cmake invocation - util: Unify function calling convention to specify destination first - util: copy_bytes: Multiple changes Change-Id: I260c34576783ee0dfa79c9b704939b943dfa0515 --- 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 1bdc552..97ebb24 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -10,7 +10,7 @@ Name: crash-worker Summary: Crash-manager -Version: 5.5.1 +Version: 5.5.2 Release: 1 Group: Framework/system License: Apache-2.0 and BSD -- 2.7.4 From d62aaac0df6f30adb5b8e18d6b1646db819d552a Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Mon, 5 Nov 2018 13:46:03 +0100 Subject: [PATCH 06/16] Add system tests Change-Id: I9db485028d328bcc43e3bc4626c24a7f1a844f53 --- packaging/crash-worker_system-tests.manifest | 25 +++++ packaging/crash-worker_system-tests.spec | 74 +++++++++++++++ tests/system/CMakeLists.txt | 33 +++++++ .../check_minicore_mem.sh.template | 38 ++++++++ tests/system/check_minicore_mem/cp.sh | 19 ++++ .../cmp_backtraces/cmp_backtraces.sh.template | 54 +++++++++++ tests/system/cmp_backtraces/cp.sh.template | 18 ++++ .../crash_root_path/crash_root_path.sh.template | 53 +++++++++++ .../critical_process/critical_process.sh.template | 83 +++++++++++++++++ tests/system/info_file/info_file.sh.template | 70 ++++++++++++++ tests/system/log_file/log_file.sh.template | 73 +++++++++++++++ .../report_type_info/report_type_info.sh.template | 35 +++++++ tests/system/run.sh.template | 37 ++++++++ tests/system/so_info_file/so_info_file.sh.template | 46 ++++++++++ tests/system/time_test/cp.sh | 19 ++++ tests/system/time_test/time_test.sh.template | 50 ++++++++++ tests/system/utils/CMakeLists.txt | 14 +++ tests/system/utils/btee.c | 102 +++++++++++++++++++++ tests/system/utils/kenny.cpp | 78 ++++++++++++++++ tests/system/utils/minicore-utils.sh | 96 +++++++++++++++++++ .../wait_for_opt_usr/wait_for_opt_usr.sh.template | 49 ++++++++++ tests/system/without_core/without_core.sh.template | 42 +++++++++ 22 files changed, 1108 insertions(+) create mode 100644 packaging/crash-worker_system-tests.manifest create mode 100644 packaging/crash-worker_system-tests.spec create mode 100644 tests/system/CMakeLists.txt create mode 100755 tests/system/check_minicore_mem/check_minicore_mem.sh.template create mode 100755 tests/system/check_minicore_mem/cp.sh create mode 100755 tests/system/cmp_backtraces/cmp_backtraces.sh.template create mode 100755 tests/system/cmp_backtraces/cp.sh.template create mode 100644 tests/system/crash_root_path/crash_root_path.sh.template create mode 100755 tests/system/critical_process/critical_process.sh.template create mode 100644 tests/system/info_file/info_file.sh.template create mode 100644 tests/system/log_file/log_file.sh.template create mode 100644 tests/system/report_type_info/report_type_info.sh.template create mode 100644 tests/system/run.sh.template create mode 100644 tests/system/so_info_file/so_info_file.sh.template create mode 100755 tests/system/time_test/cp.sh create mode 100755 tests/system/time_test/time_test.sh.template create mode 100644 tests/system/utils/CMakeLists.txt create mode 100644 tests/system/utils/btee.c create mode 100644 tests/system/utils/kenny.cpp create mode 100644 tests/system/utils/minicore-utils.sh create mode 100755 tests/system/wait_for_opt_usr/wait_for_opt_usr.sh.template create mode 100644 tests/system/without_core/without_core.sh.template diff --git a/packaging/crash-worker_system-tests.manifest b/packaging/crash-worker_system-tests.manifest new file mode 100644 index 0000000..15573a3 --- /dev/null +++ b/packaging/crash-worker_system-tests.manifest @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/crash-worker_system-tests.spec b/packaging/crash-worker_system-tests.spec new file mode 100644 index 0000000..f891d6c --- /dev/null +++ b/packaging/crash-worker_system-tests.spec @@ -0,0 +1,74 @@ +%global __debug_package 1 +# because of this is debug package, there are source files (kenny.cpp and +# btee.c) that will be copied to the destination directory, but we don't want +# them in the rpm package so this flag is to avoid RPM build error: +%define _unpackaged_files_terminate_build 0 + +Name: crash-worker_system-tests +Summary: Package with binaries and scripts for crash-worker system tests +Version: 5.5.2 +Release: 1 +Group: Framework/system +License: Apache-2.0 and BSD +Source0: %{name}-%{version}.tar.gz +Source1001: crash-worker_system-tests.manifest +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(rpm) +BuildRequires: cmake + +Requires: diff +Requires: gdb +Requires: coreutils +Requires: tlm + +Requires: crash-worker +Requires: %{_sbindir}/minicoredumper + +%description +This package contains installable tests in Bash. + +%prep +%setup -q + + +%build +cp %{SOURCE1001} . + +export CFLAGS+=" -Werror" + +cd tests/system +%cmake . -DCRASH_SYSTEM_TESTS_PATH=%{_libdir}/crash-worker_system-tests + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +cd tests/system +%make_install + +%files -f debugfiles.list +%manifest %{name}.manifest +%defattr(0750,system_fw,system_fw) +%{_libdir}/crash-worker_system-tests/check_minicore_mem/check_minicore_mem.sh +%{_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/critical_process/critical_process.sh +%{_libdir}/crash-worker_system-tests/time_test/time_test.sh +%{_libdir}/crash-worker_system-tests/time_test/cp.sh +%{_libdir}/crash-worker_system-tests/wait_for_opt_usr/wait_for_opt_usr.sh +%{_libdir}/crash-worker_system-tests/info_file/info_file.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_type_info/report_type_info.sh +%{_libdir}/crash-worker_system-tests/without_core/without_core.sh +%{_libdir}/crash-worker_system-tests/crash_root_path/crash_root_path.sh +%{_libdir}/crash-worker_system-tests/utils/btee +%{_libdir}/crash-worker_system-tests/utils/kenny +%{_libdir}/crash-worker_system-tests/utils/minicore-utils.sh +%{_libdir}/crash-worker_system-tests/run.sh +%defattr(-,root,root) + +# %post +# /usr/bin/chsmack -a "_" -e "SSSystem::Privileged" -r %{_libdir}/crash-worker_system-tests/ + diff --git a/tests/system/CMakeLists.txt b/tests/system/CMakeLists.txt new file mode 100644 index 0000000..384a729 --- /dev/null +++ b/tests/system/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 2.6) + +ADD_SUBDIRECTORY(utils) + +macro(CONFIGURE_TEST test_name) + set(file_name ${test_name}) + set(extra_args ${ARGN}) + + list(LENGTH extra_args extra_args_count) + if (${extra_args_count} GREATER 0) + list(GET extra_args 0 optional_arg) + set(file_name ${optional_arg}) + endif() + + configure_file("${test_name}/${file_name}.sh.template" "${test_name}/${file_name}.sh" @ONLY) + INSTALL(DIRECTORY ${test_name}/ DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/${test_name} FILES_MATCHING PATTERN "*sh") +endmacro() + +configure_test("check_minicore_mem") +configure_test("time_test") +configure_test("cmp_backtraces") +configure_test("cmp_backtraces" "cp") +configure_test("critical_process") +configure_test("wait_for_opt_usr") +configure_test("info_file") +configure_test("log_file") +configure_test("so_info_file") +configure_test("report_type_info") +configure_test("without_core") +configure_test("crash_root_path") + +configure_file("run.sh.template" "run.sh" @ONLY) +INSTALL(FILES run.sh DESTINATION ${CRASH_SYSTEM_TESTS_PATH}) diff --git a/tests/system/check_minicore_mem/check_minicore_mem.sh.template b/tests/system/check_minicore_mem/check_minicore_mem.sh.template new file mode 100755 index 0000000..627088a --- /dev/null +++ b/tests/system/check_minicore_mem/check_minicore_mem.sh.template @@ -0,0 +1,38 @@ +#!/bin/sh + +# Minimal coredump MUST consume less than 100MB, assuming it is created from +# process with maximum number of 8 threads. + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +CORE_MINI='coredump.mini' +BASE_DIR='/tmp' +MEM_LIMIT='102400' + +save_core_pattern + +echo "|${CRASH_WORKER_SYSTEM_TESTS}/check_minicore_mem/cp.sh %p %u %g %s %t %h %e ${BASE_DIR} ${CORE_MINI} ${MEM_LIMIT}" > /proc/sys/kernel/core_pattern +rm -f ${BASE_DIR}/${CORE_MINI} + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +restore_core_pattern + +wait_for_file ${BASE_DIR}/${CORE_MINI} + +RESULT=`gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_MINI} --batch -ex "thread apply all bt"` + +check "MAGICNAME.*id=.*kenny.cpp:31" +check "run.*id=.*kenny.cpp:56" + +exit_with_code "SUCCESS" 0 diff --git a/tests/system/check_minicore_mem/cp.sh b/tests/system/check_minicore_mem/cp.sh new file mode 100755 index 0000000..d34d150 --- /dev/null +++ b/tests/system/check_minicore_mem/cp.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +PID=${1} # %p +USER=${2} # %u +GID=${3} # %g +SIG=${4} # %s +TIME=${5} # %t +HOST=${6} # %h +EXE=${7} # %e +BASE_DIR=${8} # base_dir +MINICORE_FILE=${9} # mini +MEM_LIMIT=${10} + +ulimit -v ${MEM_LIMIT} +ulimit -m ${MEM_LIMIT} + +/sbin/minicoredumper ${PID} ${USER} ${GID} ${SIG} ${TIME} ${HOST} ${EXE} /etc/minicoredumper/minicoredumper.cfg.json -d ${BASE_DIR} -o ${MINICORE_FILE} + + diff --git a/tests/system/cmp_backtraces/cmp_backtraces.sh.template b/tests/system/cmp_backtraces/cmp_backtraces.sh.template new file mode 100755 index 0000000..11142e9 --- /dev/null +++ b/tests/system/cmp_backtraces/cmp_backtraces.sh.template @@ -0,0 +1,54 @@ +#!/bin/sh + +# Functionality to create minimal coredump MUST be provided. It MUST have +# following properties: +# +# it MUST be standards-compliant core file, +# it MUST be readable by unmodified GDB, +# it MUST have all necessary information required to resolve call stacks +# ("backtrace") from all threads. + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +CORE_ORIG="coredump.orig" +CORE_MINI="coredump.mini" +THREADS_ORIG="threads.orig" +THREADS_MINI="threads.mini" +BASE_DIR="/tmp" + +save_core_pattern + +echo "|${CRASH_WORKER_SYSTEM_TESTS}/cmp_backtraces/cp.sh %p %u %g %s %t %h %e ${BASE_DIR} ${CORE_ORIG} ${CORE_MINI}" > /proc/sys/kernel/core_pattern + +rm -f ${BASE_DIR}/${CORE_MINI} +rm -f ${BASE_DIR}/${CORE_ORIG} +rm -f ${BASE_DIR}/${THREADS_MINI} +rm -f ${BASE_DIR}/${THREADS_ORIG} + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny 10 & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +restore_core_pattern + +wait_for_file ${BASE_DIR}/${CORE_ORIG} +wait_for_file ${BASE_DIR}/${CORE_MINI} +wait_for_app minicoredumper + +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} + +if ! diff ${BASE_DIR}/${THREADS_ORIG} ${BASE_DIR}/${THREADS_MINI} > /dev/null; then + exit_with_code "FAIL: backtraces are different" 1 +fi + +exit_with_code "SUCCESS" 0 + diff --git a/tests/system/cmp_backtraces/cp.sh.template b/tests/system/cmp_backtraces/cp.sh.template new file mode 100755 index 0000000..65f03eb --- /dev/null +++ b/tests/system/cmp_backtraces/cp.sh.template @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +PID=${1} # %p +USER=${2} # %u +GID=${3} # %g +SIG=${4} # %s +TIME=${5} # %t +HOST=${6} # %h +EXE=${7} # %e +BASE_DIR=${8} # base_dir +ORIG=${9} # orig +MINICORE_FILE=${10} # mini + +${CRASH_WORKER_SYSTEM_TESTS}/utils/btee ${BASE_DIR}/${ORIG} | /sbin/minicoredumper ${PID} ${USER} ${GID} ${SIG} ${TIME} ${HOST} ${EXE} /etc/minicoredumper/minicoredumper.cfg.json -d ${BASE_DIR} -o ${MINICORE_FILE} diff --git a/tests/system/crash_root_path/crash_root_path.sh.template b/tests/system/crash_root_path/crash_root_path.sh.template new file mode 100644 index 0000000..95c818e --- /dev/null +++ b/tests/system/crash_root_path/crash_root_path.sh.template @@ -0,0 +1,53 @@ +#!/bin/sh + +# 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 + +CRASH_MANAGER_CONF=/etc/crash-manager.conf +NEW_PATH=/tmp/crash_path_test/ +if [ ! -d ${NEW_PATH} ]; then + mkdir ${NEW_PATH} +else + rm -rf ${NEW_PATH}/* +fi + +function check_file_exists { + if [ ! -f ${NEW_PATH}/dump/kenny*/kenny*.${1} ]; then + exit_with_code "FAIL: no ${1} file in report" 1 + fi +} + +mount -o rw,remount / +backup_file ${CRASH_MANAGER_CONF} +cat ${CRASH_MANAGER_CONF}.backup | sed "s|#[ ]\+CrashRootPath=.*|CrashRootPath=${NEW_PATH}|" > ${CRASH_MANAGER_CONF} + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +restore_file ${CRASH_MANAGER_CONF} + +wait_for_app crash-manager + +pushd ${NEW_PATH}/dump +if ! unzip kenny*zip > /dev/null; then + popd + exit_with_code "FAIL: report not found in ${NEW_PATH}/dump" 1 +fi +popd + +check_file_exists coredump +check_file_exists info +check_file_exists so_info +check_file_exists log + +exit_with_code "SUCCESS" 0 diff --git a/tests/system/critical_process/critical_process.sh.template b/tests/system/critical_process/critical_process.sh.template new file mode 100755 index 0000000..4c8ce35 --- /dev/null +++ b/tests/system/critical_process/critical_process.sh.template @@ -0,0 +1,83 @@ +#!/bin/bash + +# Crash worker SHOULD create minimal coredump when a "critical +# process" in user-session is crashed before the user-session is +# destroyed (or user-session timeouts). +# +# "critical process" in user-session is defined as a process which, +# when failed, causes user-session to terminate. + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +clean_crash_root + +SUICIDE_SERVICE_PATH='/usr/lib/systemd/user/suicide.service' +SES_ID=`su - owner -c "loginctl list-sessions | head -n2 | tail -n1 | tr -s ' ' | cut -d' ' -f2"` + +function clean_after_test { + su - owner -c 'systemctl --user stop suicide.service' + rm ${SUICIDE_SERVICE_PATH} + su - owner -c 'systemctl --user daemon-reload' +} + +mount -o rw,remount / +cat << EOF > ${SUICIDE_SERVICE_PATH} +[Unit] +Description=Test service + +[Service] +Type=oneshot +ExecStart=/bin/sleep 1 +RemainAfterExit=true +ExecStop=/bin/sh -c 'kill -6 \$\$\$\$' + +[Install] +RequiredBy=basic.target +Before=basic.target +EOF + +chsmack -a "_" ${SUICIDE_SERVICE_PATH} + +su - owner -c 'systemctl --user daemon-reload' +su - owner -c 'systemctl --user start suicide.service' + +USER_TEST1=`gum-utils -c --username=test1 2> /dev/null` +if [ -z ${USER_TEST1} ]; then + gum-utils -a --username test1 --usertype normal --usecret tizen 1> /dev/null 2>&1 +fi + +save_core_pattern +echo "|/usr/bin/crash-manager %p %u %g %s %t %i" > /proc/sys/kernel/core_pattern + +tlm-client -s --username test1 --password tizen --seat seat0 1> /dev/null 2>&1 +sleep 4 + +restore_core_pattern + +TIMEOUT=240 +while true; do + if [[ `ls ${CRASH_ROOT_PATH}` =~ sh.*.zip ]]; then + tlm-client -s --username owner --password tizen --seat seat0 1> /dev/null 2>&1 + sleep 4 + gum-utils -d --username test1 1> /dev/null 2>&1 + clean_after_test + exit_with_code "SUCCESS" 0 + fi + + if endoftime; then + break + else + sleep 1 + fi +done + +tlm-client -s --username owner --password tizen --seat seat0 1> /dev/null 2>&1 +sleep 4 +gum-utils -d --username test1 1> /dev/null 2>&1 + +clean_after_test +exit_with_code "FAIL" 1 diff --git a/tests/system/info_file/info_file.sh.template b/tests/system/info_file/info_file.sh.template new file mode 100644 index 0000000..2e5e227 --- /dev/null +++ b/tests/system/info_file/info_file.sh.template @@ -0,0 +1,70 @@ +#!/bin/sh + +# Check correction of the *.info 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 + +clean_crash_root + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +wait_for_app crash-manager + +REPORT_ZIP=$(ls ${CRASH_ROOT_PATH}) +REPORT_DIR=$(basename ${REPORT_ZIP} .zip) + +if [ ! -f ${CRASH_ROOT_PATH}/${REPORT_ZIP} ]; then + exit_with_code "FAIL: no report in ${CRASH_ROOT_PATH}" 1 +fi + +pushd ${CRASH_ROOT_PATH} +if ! unzip ${REPORT_ZIP} > /dev/nulll; then + popd + exit_with_code "FAIL: report ${REPORT_ZIP} does not exist" +fi +popd + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.info) + +check "Executable File Path: ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny" + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.info | sed -n '/Register Information/,/Memory information/p') + +check "[a-z0-9]+[ \t]+= 0x[a-f0-9]+" + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.info | sed -n '/Memory information/,/Threads Information/p') + +check "MemTotal:" +check "VmExe:" +check "VmSwap:" + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.info | sed -n '/Maps Information/,/End of Maps Information/p') + +check "${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny" +check '[heap]' +check '/usr/lib/libm-.*.so' +check '/usr/lib/libc-.*.so' +check '/usr/lib/libgcc_s.so' +check '/usr/lib/libstdc++.*so' +check '/usr/lib/libpthread-.*.so' +check '/usr/lib/ld-.*.so' +check '[stack]' + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.info | sed -n '/Callstack Information/,/End of Call Stack/p') + +check ': .*nanosleep' +check ': .*sleep.*' +check ': .*start.*kenny' +check ': main.*kenny' + +exit_with_code "SUCCESS" 0 diff --git a/tests/system/log_file/log_file.sh.template b/tests/system/log_file/log_file.sh.template new file mode 100644 index 0000000..26b852f --- /dev/null +++ b/tests/system/log_file/log_file.sh.template @@ -0,0 +1,73 @@ +#!/bin/sh + +# Check correction of the *.log file + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +function check_section_not_empty { + COUNT=${2} + RES=$(echo "${RESULT}" | grep -A ${COUNT} "^${1}" | grep -ve "^==== " | wc -l) + if [ ${RES} -eq ${COUNT} ]; then + return 0 + fi + exit_with_code "FAIL: section ${1} does not contain enough data" 1 +} + +function check_section { + check "${1}" + check_section_not_empty "${1}" ${2} +} + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +clean_crash_root + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +wait_for_app crash-manager + +REPORT_ZIP=$(ls ${CRASH_ROOT_PATH}) +REPORT_DIR=$(basename ${REPORT_ZIP} .zip) + +if [ ! -f ${CRASH_ROOT_PATH}/${REPORT_ZIP} ]; then + exit_with_code "FAIL: no report in ${CRASH_ROOT_PATH}" 1 +fi + +pushd ${CRASH_ROOT_PATH} +if ! unzip ${REPORT_ZIP} > /dev/nulll; then + popd + exit_with_code "FAIL: report ${REPORT_ZIP} does not exist" +fi +popd + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.log) + +check_section "==== Binary version" 7 +check_section "==== Tizen version" 4 +check_section "==== Kernel version" 2 +check_section "==== Boot arguments" 2 +check_section "==== CPU . system architecture" 7 +check_section "==== System uptime" 2 +check_section "==== System statistics" 5 +check_section "==== System memory usage" 7 +check_section "==== Device major numbers" 2 +check_section "==== System disk I/O" 2 +check_section "==== System disk space usage" 4 +check_section "==== System timezone" 2 +check_section "==== System summary" 5 +check_section "==== Current processes" 10 +check_section "==== System memory statistics" 10 +check_section "==== System configuration" 10 +check_section "==== Kernel messages" 10 +check_section "==== Log messages" 10 +check_section "==== Journal messages" 10 + +exit_with_code "SUCCESS" 0 diff --git a/tests/system/report_type_info/report_type_info.sh.template b/tests/system/report_type_info/report_type_info.sh.template new file mode 100644 index 0000000..b49ac80 --- /dev/null +++ b/tests/system/report_type_info/report_type_info.sh.template @@ -0,0 +1,35 @@ +#!/bin/sh + +# Check the report type change in the config 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_root + +mount -o rw,remount / +backup_file ${CRASH_MANAGER_CONF} +cat ${CRASH_MANAGER_CONF}.backup | sed "s/#[ ]\+ReportType=.*/ReportType=INFO/" > ${CRASH_MANAGER_CONF} + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +restore_file ${CRASH_MANAGER_CONF} + +wait_for_app crash-manager + +if ! compgen -G ${CRASH_ROOT_PATH}/kenny*info > /dev/null; then + exit_with_code "FAIL: info file not found" 1 +fi + +exit_with_code "SUCCESS" 0 diff --git a/tests/system/run.sh.template b/tests/system/run.sh.template new file mode 100644 index 0000000..b8bd498 --- /dev/null +++ b/tests/system/run.sh.template @@ -0,0 +1,37 @@ +#!/bin/sh + +TESTS=("check_minicore_mem" "cmp_backtraces" "info_file" "log_file" + "report_type_info" "critical_process" "time_test" "wait_for_opt_usr" + "so_info_file" "without_core" "crash_root_path") + +if [ -z "${CRASH_SYSTEM_TESTS_PATH}" ]; then + CRASH_SYSTEM_TESTS_PATH="@CRASH_SYSTEM_TESTS_PATH@" +fi + +LOG_FILE=/tmp/crash-worker_system-tests.log + +function run_test { + RED="\033[0;31m" + GREEN="\033[0;32m" + NORMAL="\033[0m" + + echo -ne "${TEST}:\t" + echo "===================================" >> ${LOG_FILE} + echo "Test ${TEST}:" >> ${LOG_FILE} + echo "===================================" >> ${LOG_FILE} + ${CRASH_SYSTEM_TESTS_PATH}/${TEST}/${TEST}.sh 1>> ${LOG_FILE} 2>&1 + if [ "$?" -eq "0" ]; then + echo -e "${GREEN}SUCCESS${NORMAL}" + echo "SUCCESS" >> ${LOG_FILE} + else + echo -e "${RED}FAIL${NORMAL}" + echo "FAIL" >> ${LOG_FILE} + fi +} + +if [ -f ${LOG_FILE} ]; then + rm ${LOG_FILE} +fi +for TEST in ${TESTS[@]}; do + run_test ${TEST} +done diff --git a/tests/system/so_info_file/so_info_file.sh.template b/tests/system/so_info_file/so_info_file.sh.template new file mode 100644 index 0000000..1838a9b --- /dev/null +++ b/tests/system/so_info_file/so_info_file.sh.template @@ -0,0 +1,46 @@ +#!/bin/sh + +# Check correction of the *.so_info 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 + +clean_crash_root + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +wait_for_app crash-manager + +REPORT_ZIP=$(ls ${CRASH_ROOT_PATH}) +REPORT_DIR=$(basename ${REPORT_ZIP} .zip) + +if [ ! -f ${CRASH_ROOT_PATH}/${REPORT_ZIP} ]; then + exit_with_code "FAIL: no report in ${CRASH_ROOT_PATH}" 1 +fi + +pushd ${CRASH_ROOT_PATH} +if ! unzip ${REPORT_ZIP} > /dev/nulll; then + exit_with_code "FAIL: report ${REPORT_ZIP} does not exist" +fi +popd + +RESULT=$(cat ${CRASH_ROOT_PATH}/${REPORT_DIR}/${REPORT_DIR}.so_info) + +check "utils/kenny [a-z0-9]+ crash-worker_system-tests;[^;]+;[^;]+;[a-z0-9]+" +check "/usr/lib/libm[^ ]+ [a-z0-9]+ glibc;[^;]+;[^;]+;[a-z0-9]+" +check "/usr/lib/libc[^ ]+ [a-z0-9]+ glibc;[^;]+;[^;]+;[a-z0-9]+" +check "/usr/lib/libgcc_s[^ ]+ [a-z0-9]+ libgcc;[^;]+;[^;]+;[a-z0-9]+" +check "/usr/lib/libstdc[^ ]+ [a-z0-9]+ libstd[^;]+;[^;]+;[^;]+;[a-z0-9]+" +check "/usr/lib/libpthread[^ ]+ [a-z0-9]+ glibc;[^;]+;[^;]+;[a-z0-9]+" +check "/usr/lib/ld[^ ]+ [a-z0-9]+ glibc;[^;]+;[^;]+;[a-z0-9]+" + +exit_with_code "SUCCESS" 0 diff --git a/tests/system/time_test/cp.sh b/tests/system/time_test/cp.sh new file mode 100755 index 0000000..c8699e8 --- /dev/null +++ b/tests/system/time_test/cp.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +PID=${1} # %p +USER=${2} # %u +GID=${3} # %g +SIG=${4} # %s +TIME=${5} # %t +HOST=${6} # %h +EXE=${7} # %e +BASE_DIR=${8} # base_dir +ORIG=${9} # orig +MINICORE_FILE=${10} # mini +MINICORE_TIME=${11} # minicore_time + +START=$(date +%s) +/sbin/minicoredumper ${PID} ${USER} ${GID} ${SIG} ${TIME} ${HOST} ${EXE} /etc/minicoredumper/minicoredumper.cfg.json -d ${BASE_DIR} -o ${MINICORE_FILE} +STOP=$(date +%s) + +echo $((${STOP} - ${START})) > ${BASE_DIR}/${MINICORE_TIME} diff --git a/tests/system/time_test/time_test.sh.template b/tests/system/time_test/time_test.sh.template new file mode 100755 index 0000000..8a78090 --- /dev/null +++ b/tests/system/time_test/time_test.sh.template @@ -0,0 +1,50 @@ +#!/bin/sh + +# Minimal coredump SHOULD complete within 5 seconds. +# +# Real time MUST be measured from invocation of minicoredumper binary to it +# closing its standard input file descriptor. Measurement MUST be performed on +# idle system. + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +CORE_ORIG='core.orig' +CORE_MINI='core.mini' +THREADS_ORIG='threads.orig' +THREADS_MINI='threads.mini' +TEMP_DIR='/tmp' +MINICORE_TIME_FILE='mc_time' +TIME_LIMIT=5 + +save_core_pattern + +echo "|${CRASH_WORKER_SYSTEM_TESTS}/time_test/cp.sh %p %u %g %s %t %h %e ${TEMP_DIR} ${CORE_ORIG} ${CORE_MINI} ${MINICORE_TIME_FILE}" > /proc/sys/kernel/core_pattern + +rm -f ${TEMP_DIR}/${CORE_MINI} +rm -f ${TEMP_DIR}/${CORE_ORIG} +rm -f ${TEMP_DIR}/${CORE_ORIG} +rm -f ${TEMP_DIR}/${MINICORE_TIME_FILE} + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny 100 & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +restore_core_pattern + +wait_for_file ${TEMP_DIR}/${MINICORE_TIME_FILE} + +MINICORE_TIME=$(< ${TEMP_DIR}/${MINICORE_TIME_FILE}) + +if [ ${MINICORE_TIME} -le ${TIME_LIMIT} ]; then + exit_with_code "SUCCESS" 0 +else + exit_with_code "FAIL: dumping time: ${MINICORE_TIME} but limit was: ${TIME_LIMIT}" 1 +fi diff --git a/tests/system/utils/CMakeLists.txt b/tests/system/utils/CMakeLists.txt new file mode 100644 index 0000000..a486aab --- /dev/null +++ b/tests/system/utils/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required (VERSION 2.6) +project(system_tests) + +add_executable(btee btee.c) + +add_executable(kenny kenny.cpp) +find_package(Threads) +target_link_libraries(kenny ${CMAKE_THREAD_LIBS_INIT}) +set_target_properties(kenny PROPERTIES COMPILE_FLAGS "-std=c++11 -ggdb -O0") + +install(TARGETS kenny DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/utils) +install(TARGETS btee DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/utils) +install(FILES minicore-utils.sh DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/utils) + diff --git a/tests/system/utils/btee.c b/tests/system/utils/btee.c new file mode 100644 index 0000000..2f596fa --- /dev/null +++ b/tests/system/utils/btee.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Mateusz Moscicki + */ +#include +#include +#include +#include +#include +#include + +#define TMP_DIR "/tmp/" +#define DEFAULT_FILE_NAME "core_" + +enum copy_errors { + COPY_OK, + COPY_WRITE_FAIL, + COPY_READ_FAIL +}; + +static int copy_data(int dest, int src) +{ + char buff[1024]; + int readed; + while ((readed = read(src, buff, sizeof(buff))) > 0) { + int written = 0; + while ((written = write(dest, buff, readed)) < readed) { + if (written < 0) + return COPY_WRITE_FAIL; + readed -= written; + } + } + + return readed >= 0 ? COPY_OK : COPY_READ_FAIL; +} + +int main(int argc, char *argv[]) +{ +#define EXIT_FAIL(fmt, ...) { \ + dprintf(STDERR_FILENO, fmt, ##__VA_ARGS__); \ + ret = EXIT_FAILURE; \ + goto exit; \ + } + + int ret = EXIT_SUCCESS; + char *file_name; + + if (argc >= 2) + file_name = strdup(argv[1]); + else + file_name = tempnam(TMP_DIR, DEFAULT_FILE_NAME); + + if (file_name == NULL) + EXIT_FAIL("error: %m\n") + + int fd = open(file_name, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + if (fd == -1) + EXIT_FAIL("open file %s error: %m\n", file_name) + + int copy_res = copy_data(fd, STDIN_FILENO); + close(fd); + + switch (copy_res) { + case COPY_WRITE_FAIL: + EXIT_FAIL("write to FD error: %m\n") + case COPY_READ_FAIL: + EXIT_FAIL("read from STDIN error: %m\n") + } + + fd = open(file_name, O_RDONLY); + if (fd == -1) + EXIT_FAIL("open file %s error: %m\n", file_name) + + copy_res = copy_data(STDOUT_FILENO, fd); + close(fd); + + switch (copy_res) { + case COPY_WRITE_FAIL: + EXIT_FAIL("write to STDOUT error: %m\n") + case COPY_READ_FAIL: + EXIT_FAIL("read from FD error: %m\n") + } + +exit: + free(file_name); + return ret; +#undef EXIT_FAIL +} + diff --git a/tests/system/utils/kenny.cpp b/tests/system/utils/kenny.cpp new file mode 100644 index 0000000..98ec8cb --- /dev/null +++ b/tests/system/utils/kenny.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Mateusz Moscicki + */ +#include +#include +#include +#include + +static constexpr size_t T_NUM = 8; +static constexpr size_t DEFAULT_COUNT = 1; +static constexpr size_t MB = 1024*1024; + +// This function is used to check the correctness of gdb +// callstack, so id param may be useful in this case +static void MAGICNAME(int id) { + while (true) + sleep(1); +} + +static bool alloc_chunk(size_t nr) { + try { + // For tests purposes we have to alloc some memory for nothing + char *buff = new char[MB]; + std::memset(buff, nr % 256, MB); + } catch (std::bad_alloc& er) { + std::cout << "Memory allocation for " << nr << " chunk failed: " << er.what() << std::endl; + return false; + } + + return true; +} + +static bool alloc_memory(size_t megabytes) { + for (size_t i = 0; i < megabytes; i++) { + if (!alloc_chunk(i)) + return false; + } + return true; +} + +static void run(int id) { + MAGICNAME(id); +} + +int main(int argc, char *argv[]) { + std::thread threads[T_NUM]; + + for (size_t i = 0; i < T_NUM; i++) { + threads[i] = std::thread(run, i); + std::this_thread::sleep_for(std::chrono::microseconds(10)); + } + + size_t count = DEFAULT_COUNT; + + if (argc > 1) + count = std::stoul(argv[1]); + + if (!alloc_memory(count)) + return EXIT_FAILURE; + + run(-1); + + return EXIT_SUCCESS; +} diff --git a/tests/system/utils/minicore-utils.sh b/tests/system/utils/minicore-utils.sh new file mode 100644 index 0000000..75f2bfc --- /dev/null +++ b/tests/system/utils/minicore-utils.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +__CORE_PATTERN="" + +function save_core_pattern { + __CORE_PATTERN=$(< /proc/sys/kernel/core_pattern) +} + +function exit_with_code { + echo ${1} + exit ${2} +} + +function restore_core_pattern { + echo ${__CORE_PATTERN} > /proc/sys/kernel/core_pattern +} + +function endoftime { + TIMEOUT=$((TIMEOUT-1)) + if [ $((TIMEOUT)) == 0 ]; then + return 0 + fi + return 1 +} + +function check { + if [[ ${RESULT} =~ ${1} ]]; then + return 0 + fi + exit_with_code "FAIL: not found ${1} in ${RESULT}" 1 +} + +function tzplatform_var { + VAL=`tzplatform-get ${1}` + if [ $? == 0 ]; then + echo $VAL | cut -d'=' -f2 + return 0 + fi + return 1 +} + +function clean_crash_root { + export CRASH_ROOT_PATH=`tzplatform_var TZ_SYS_CRASH` + + killall crash-manager + killall minicoredumper + + sleep 1 + + if [ -z ${CRASH_ROOT_PATH} ]; then + exit_with_code "Couldn't get TZ_SYS_CRASH or TZ_SYS_CRASH is empty" 1 + fi + + if [ ! -d ${CRASH_ROOT_PATH} ]; then + exit_with_code "${CRASH_ROOT_PATH} does not exist" 1 + fi + + rm -rf ${CRASH_ROOT_PATH}/* +} + +function wait_for_file { + TIMEOUT=240 + while [ ! -f ${1} ]; + do + if endoftime; then + exit_with_code "FAIL: ${1} does not exist" 1 + else + sleep 1 + fi + done + return 0 +} + +function wait_for_app { + TIMEOUT=240 + while true; + do + if ! pidof ${1} 1> /dev/null 2>&1; then + break; + fi + if endoftime; then + exit_with_code "FAIL: ${1} is still running" 1 + else + sleep 1 + fi + done + return 0 +} + +function backup_file { + cp ${1} ${1}.backup +} + +function restore_file { + mv ${1}.backup ${1} +} diff --git a/tests/system/wait_for_opt_usr/wait_for_opt_usr.sh.template b/tests/system/wait_for_opt_usr/wait_for_opt_usr.sh.template new file mode 100755 index 0000000..fb35e84 --- /dev/null +++ b/tests/system/wait_for_opt_usr/wait_for_opt_usr.sh.template @@ -0,0 +1,49 @@ +#!/bin/sh + +# Crash worker SHOULD create minimal coredump when process crashed before +# /opt/usr (user partition) is mounted. Crash worker MAY create it in temporary +# location or wait for /opt/usr partition to be mounted. + +if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then + CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@" +fi + +. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh + +OPT_MOUNTPOINT='/opt' +MTAB=`cat /etc/mtab | grep " ${OPT_MOUNTPOINT}"` + +clean_crash_root + +if ! umount -l ${OPT_MOUNTPOINT}; then + exit_with_code "umount ${OPT_MOUNTPOINT} error" 1 +fi + +save_core_pattern + +echo "|/usr/bin/crash-manager %p %u %g %s %t %i" > /proc/sys/kernel/core_pattern + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny 10 & + sleep 1 + killall -6 kenny +} 1> /dev/null 2>&1 + +sleep 20 + +restore_core_pattern + +echo "${MTAB}" | while read OPT_LINE; do + OPT_DEV=`echo ${OPT_LINE} | cut -d' ' -f1` + OPT_FS=`echo ${OPT_LINE} | cut -d' ' -f3` + OPT_OPTS=`echo ${OPT_LINE} | cut -d' ' -f4` + OPT_CUR_MOUNTPOINT=`echo ${OPT_LINE} | cut -d' ' -f2` + + if ! mount -t ${OPT_FS} -o ${OPT_OPTS} ${OPT_DEV} ${OPT_CUR_MOUNTPOINT}; then + exit_with_code "ERROR: mount -t ${OPT_FS} -o ${OPT_OPTS} ${OPT_DEV} ${OPT_CUR_MOUNTPOINT}" 1 + fi +done + +wait_for_app crash-manager + +wait_for_file ${CRASH_ROOT_PATH}'/kenny*zip' diff --git a/tests/system/without_core/without_core.sh.template b/tests/system/without_core/without_core.sh.template new file mode 100644 index 0000000..18f92a9 --- /dev/null +++ b/tests/system/without_core/without_core.sh.template @@ -0,0 +1,42 @@ +#!/bin/sh + +# Test of generating a report without coredump 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_root + +mount -o rw,remount / +backup_file ${CRASH_MANAGER_CONF} +cat ${CRASH_MANAGER_CONF}.backup | sed "s/#[ ]\+DumpCore=1/DumpCore=0/" > ${CRASH_MANAGER_CONF} + +{ + ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny & + sleep 1 + kill -6 $! +} 1> /dev/null 2>&1 + +sleep 2 + +restore_file ${CRASH_MANAGER_CONF} + +wait_for_app crash-manager + +pushd ${CRASH_ROOT_PATH} +if ! unzip kenny*zip > /dev/null; then + popd + exit_with_code "FAIL: report does not exist" 1 +fi +popd + +if ls ${CRASH_ROOT_PATH}/kenny*/kenny*.coredump > /dev/null; then + exit_with_code "FAIL: coredump file exists" 1 +fi + +exit_with_code "SUCCESS" 0 -- 2.7.4 From 8b0d119c51d648589b7988ab59f9a242707e87e1 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 22 Nov 2018 18:44:03 +0100 Subject: [PATCH 07/16] sysctl: Set fs.suid_dumpable=2 for release builds This commit enables dumping all processes - including those considered by kernel as "suid". Process is considered "suid" not only when it does (among other) setuid/setgid but also when Capabilities are defined in systemd unit. With suid_dumpable=0 crash of such "suid" processes would not trigger execution of crash-worker by the kernel. Please see suid_dumpable description in proc(5) for full explanation what kernel considers "suid". Change-Id: I067355ba651507b35ef7c8d23245443184b670cf --- src/crash-manager/99-crash-manager.conf.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/crash-manager/99-crash-manager.conf.in b/src/crash-manager/99-crash-manager.conf.in index 5961717..e1900b9 100644 --- a/src/crash-manager/99-crash-manager.conf.in +++ b/src/crash-manager/99-crash-manager.conf.in @@ -1,3 +1,5 @@ # Tizen crash-manager kernel.core_pattern=|/usr/bin/crash-manager %p %u %g %s %t %i kernel.core_pipe_limit=10 +# All processes should be dumped +fs.suid_dumpable=2 -- 2.7.4 From 6b43b25a56e14807360b3596715d20ce4e842e4d Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 22 Nov 2018 18:49:36 +0100 Subject: [PATCH 08/16] Drop unused service files This commit removes unused service files originally disabled in commit 9ef91ff21 ("Fix bugs [..] - Do not install unused services: tizen-debug-on/off"). Change-Id: Icb41586586106a427524f1c8eddfdedc23d53f93 --- CMakeLists.txt | 1 - data/CMakeLists.txt | 10 ---------- data/tizen-debug-off.service.in | 15 --------------- data/tizen-debug-on.service.in | 15 --------------- src/crash-manager/99-crash-manager-debug.conf.in | 4 ---- src/crash-manager/CMakeLists.txt | 8 +------- 6 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 data/CMakeLists.txt delete mode 100644 data/tizen-debug-off.service.in delete mode 100644 data/tizen-debug-on.service.in delete mode 100644 src/crash-manager/99-crash-manager-debug.conf.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f3222d..0a14531 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,5 @@ ADD_SUBDIRECTORY(src/crash-stack) ADD_SUBDIRECTORY(src/dump_systemstate) ADD_SUBDIRECTORY(src/log_dump) -#ADD_SUBDIRECTORY(data) ADD_SUBDIRECTORY(tests) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt deleted file mode 100644 index 681894d..0000000 --- a/data/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -CONFIGURE_FILE(tizen-debug-on.service.in tizen-debug-on.service @ONLY) -CONFIGURE_FILE(tizen-debug-off.service.in tizen-debug-off.service @ONLY) - -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen-debug-on.service DESTINATION /usr/lib/systemd/system - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen-debug-off.service DESTINATION /usr/lib/systemd/system - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/data/tizen-debug-off.service.in b/data/tizen-debug-off.service.in deleted file mode 100644 index c589bbb..0000000 --- a/data/tizen-debug-off.service.in +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=tizen debug off -DefaultDependencies=no -After=opt.mount tizen-debug-on.service -Before=sysinit.target - -[Service] -SmackProcessLabel=System -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/rm -f @DEBUGMODE_PATH@ -ExecStart=/sbin/sysctl -p /usr/lib/sysctl.d/99-crash-manager.conf - -[Install] -WantedBy=sysinit.target diff --git a/data/tizen-debug-on.service.in b/data/tizen-debug-on.service.in deleted file mode 100644 index e72ca2a..0000000 --- a/data/tizen-debug-on.service.in +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=tizen debug on -DefaultDependencies=no -After=opt.mount -Before=sysinit.target - -[Service] -SmackProcessLabel=System -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/touch -f @DEBUGMODE_PATH@ -ExecStart=/sbin/sysctl -p /usr/lib/sysctl.d/99-crash-manager.conf - -[Install] -WantedBy=sysinit.target diff --git a/src/crash-manager/99-crash-manager-debug.conf.in b/src/crash-manager/99-crash-manager-debug.conf.in deleted file mode 100644 index 3fa5692..0000000 --- a/src/crash-manager/99-crash-manager-debug.conf.in +++ /dev/null @@ -1,4 +0,0 @@ -# Tizen crash-manager -kernel.core_pattern=|/usr/bin/crash-manager %p %u %g %s %t %i -kernel.core_pipe_limit=10 -fs.suid_dumpable=1 diff --git a/src/crash-manager/CMakeLists.txt b/src/crash-manager/CMakeLists.txt index ee04dd0..5c36d30 100644 --- a/src/crash-manager/CMakeLists.txt +++ b/src/crash-manager/CMakeLists.txt @@ -34,13 +34,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) CONFIGURE_FILE(500.${PROJECT_NAME}-upgrade.sh.in 500.${PROJECT_NAME}-upgrade.sh @ONLY) - -IF(USE_COREDUMP_CONF) - CONFIGURE_FILE(99-${PROJECT_NAME}-debug.conf.in 99-${PROJECT_NAME}.conf @ONLY) -ELSE() - CONFIGURE_FILE(99-${PROJECT_NAME}.conf.in 99-${PROJECT_NAME}.conf @ONLY) -ENDIF(USE_COREDUMP_CONF) - +CONFIGURE_FILE(99-${PROJECT_NAME}.conf.in 99-${PROJECT_NAME}.conf @ONLY) INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/crash-manager.conf DESTINATION /etc -- 2.7.4 From 93bfd1fea3fe36feead530837c1e305ce0af505b Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 23 Nov 2018 17:04:11 +0100 Subject: [PATCH 09/16] Release 5.5.3 This release brings full suite of system tests, verified on TM1, Odroid, 32-bit emulator. Addtionaly, this commit sets fs.suid_dumpable=2 sysctl to ensure all processes are subject to core dumping. Change-Id: I0d7142a42ef580ce1cb11c9d246c267438fb299c --- packaging/crash-worker.spec | 2 +- packaging/crash-worker_system-tests.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 97ebb24..3a221ce 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -10,7 +10,7 @@ Name: crash-worker Summary: Crash-manager -Version: 5.5.2 +Version: 5.5.3 Release: 1 Group: Framework/system License: Apache-2.0 and BSD diff --git a/packaging/crash-worker_system-tests.spec b/packaging/crash-worker_system-tests.spec index f891d6c..68f521e 100644 --- a/packaging/crash-worker_system-tests.spec +++ b/packaging/crash-worker_system-tests.spec @@ -6,7 +6,7 @@ Name: crash-worker_system-tests Summary: Package with binaries and scripts for crash-worker system tests -Version: 5.5.2 +Version: 5.5.3 Release: 1 Group: Framework/system License: Apache-2.0 and BSD -- 2.7.4 From 90533436899d8fb09cd880facb1fe6c61cba50bb Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 22 Nov 2018 20:34:17 +0100 Subject: [PATCH 10/16] crash-manager: Do not force system to wait for crash-popup to complete Calling crash-popup is synchronous, meaning that call has to complete for crash-manager to complete, releasing core pipe descriptor - which allows another crash to be handled. This commit releases the core pipe descriptor allowing another crash to be handled before popup is shown. Change-Id: Iea08efc6318960ee43bb5494eaff42636529ec17 --- src/crash-manager/crash-manager.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index c48e29a..7768284 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -1286,9 +1286,6 @@ int main(int argc, char *argv[]) } move_dump_data(cinfo.info_path, &cinfo); } - /* launch crash-popup only if the .debugmode file is exist*/ - if (debug_mode) - launch_crash_popup(&cinfo); struct NotifyParams notify_params = { .prstatus_fd = cinfo.prstatus_fd, @@ -1303,6 +1300,23 @@ int main(int argc, char *argv[]) send_notify(¬ify_params); + /* Release the core pipe as passed by kernel, allowing another + * coredump to be handled. + * + * Due to usage of core_pipe_limit there is limited number of + * crash-manager processes that kernel is going to invoke + * concurrently. As the next and last step is a _synchronous_ + * call to crash-popup we close the descriptor here. + * + * Note: for VIP processes this will likely cause the system + * to reboot without showing popup. + */ + close(STDIN_FILENO); + + /* launch crash-popup only if the .debugmode file exists */ + if (debug_mode) + launch_crash_popup(&cinfo); + exit: close(cinfo.prstatus_fd); free(crash_temp_path); -- 2.7.4 From 61b7db69a6bee619857a8339fa9c9d4a28b67b9f Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 7 Dec 2018 11:02:06 +0100 Subject: [PATCH 11/16] Make disk-usage functions use off_t The off_t is the same type that stat(2) uses and it's widest type that can actually hold information real disk usage. Change-Id: Id4b5d1160bdecafb065cf6792274c255619817fc --- src/crash-manager/crash-manager.c | 8 ++++---- src/shared/util.c | 4 ++-- src/shared/util.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 7768284..215904b 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -94,7 +94,7 @@ enum { struct file_info { bool isdir; - int size; + size_t size; time_t mtime; char *path; }; @@ -906,7 +906,7 @@ static int mtime_cmp(const void *_a, const void *_b) return 0; } -static int scan_dump(struct file_info **dump_list, size_t *usage) +static int scan_dump(struct file_info **dump_list, off_t *usage) { struct file_info *temp_list; struct dirent **scan_list = NULL; @@ -1026,7 +1026,7 @@ static void clean_dump(void) { struct file_info *dump_list = NULL; int i, scan_num, dump_num, remove_flag; - size_t usage = 0; + off_t usage = 0; time_t cur_time; scan_num = scan_dump(&dump_list, &usage); @@ -1065,7 +1065,7 @@ static void clean_dump(void) dump_list[i].path); break; case USAGE_EXCEED: - _I("Reached the maximum disk usage %d/%d kb, so remove (%s)", + _I("Reached the maximum disk usage %lld/%d kb, so remove (%s)", usage / 1024, system_max_use, dump_list[i].path); break; diff --git a/src/shared/util.c b/src/shared/util.c index 85879d6..564d276 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -651,12 +651,12 @@ int get_file_count(char *path) return count; } -int get_directory_usage(char *path) +off_t get_directory_usage(char *path) { DIR *dir; struct dirent *de; struct stat st; - size_t usage = 0; + off_t usage = 0; int fd = -1; fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME); diff --git a/src/shared/util.h b/src/shared/util.h index 819a19c..c45bf3c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -59,7 +59,7 @@ int get_exec_pid(const char *execpath); int get_file_count(char *path); -int get_directory_usage(char *path); +off_t get_directory_usage(char *path); int log_kmsg(char *fmt, ...); -- 2.7.4 From 770ef44c466bf977da8d63ac4b5153f926bdf7a8 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 7 Dec 2018 11:02:24 +0100 Subject: [PATCH 12/16] crash-stack: Fix format specifier Change-Id: Ifdc4a229275b866f5718f0779b1a9cba01d7b1ea --- src/crash-stack/proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crash-stack/proc.c b/src/crash-stack/proc.c index fd346c6..da21663 100644 --- a/src/crash-stack/proc.c +++ b/src/crash-stack/proc.c @@ -472,8 +472,8 @@ static int copy_memory_proc_mem(int pid, struct mem_data_chunk **frames, ssize_t rd = pread(fd, to, count, from); if (rd == -1) { - _E("pread() at %s:0x%lx (#%d) failed: %m [%d]", - fname, from, i, errno); + _E("pread() at %s:0x%llx (#%d) failed: %m [%d]", + fname, from, i, errno); goto proc_mem_end; } -- 2.7.4 From ac711afc73c2b8db9b6f2a673da9bbee9869d882 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 14 Dec 2018 16:08:46 +0100 Subject: [PATCH 13/16] Release 5.5.4 This release brings following fixes: - fix DLog format specifier (needed if DLog start enforcing valid printf-formats) - fix: Make disk-usage functions use off_t - relability fix: crash-manager: Do not force system to wait for crash-popup to complete Change-Id: I733f09298c34c1c7824f57dfa156f23cf9196947 --- packaging/crash-worker.spec | 2 +- packaging/crash-worker_system-tests.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 3a221ce..587c925 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -10,7 +10,7 @@ Name: crash-worker Summary: Crash-manager -Version: 5.5.3 +Version: 5.5.4 Release: 1 Group: Framework/system License: Apache-2.0 and BSD diff --git a/packaging/crash-worker_system-tests.spec b/packaging/crash-worker_system-tests.spec index 68f521e..6e814f0 100644 --- a/packaging/crash-worker_system-tests.spec +++ b/packaging/crash-worker_system-tests.spec @@ -6,7 +6,7 @@ Name: crash-worker_system-tests Summary: Package with binaries and scripts for crash-worker system tests -Version: 5.5.3 +Version: 5.5.4 Release: 1 Group: Framework/system License: Apache-2.0 and BSD -- 2.7.4 From 2f379db2c637bda9c84b8606fdc9bbb2b721e5f8 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 18 Dec 2018 12:15:40 +0100 Subject: [PATCH 14/16] Fix DLog format specifier for 64-bit architecures Change-Id: I3f29eb0dc3e5081843f0c982dab92cd45aad1364 --- src/crash-manager/crash-manager.c | 5 +++-- src/crash-stack/proc.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 215904b..1cba5ee 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -976,7 +977,7 @@ static int scan_dump(struct file_info **dump_list, off_t *usage) *usage = 0; for (i = 0; i < dump_num; i++) { - _D("[%d] path: %s(%s), size: %d kb, mtime: %s", + _D("[%d] path: %s(%s), size: %zu kb, mtime: %s", i, temp_list[i].path, temp_list[i].isdir ? "DIR" : "FILE", @@ -1065,7 +1066,7 @@ static void clean_dump(void) dump_list[i].path); break; case USAGE_EXCEED: - _I("Reached the maximum disk usage %lld/%d kb, so remove (%s)", + _I("Reached the maximum disk usage %" PRId64 "/%d kb, so remove (%s)", usage / 1024, system_max_use, dump_list[i].path); break; diff --git a/src/crash-stack/proc.c b/src/crash-stack/proc.c index da21663..46f40e1 100644 --- a/src/crash-stack/proc.c +++ b/src/crash-stack/proc.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -472,7 +473,7 @@ static int copy_memory_proc_mem(int pid, struct mem_data_chunk **frames, ssize_t rd = pread(fd, to, count, from); if (rd == -1) { - _E("pread() at %s:0x%llx (#%d) failed: %m [%d]", + _E("pread() at %s:0x%" PRIx64 " (#%d) failed: %m [%d]", fname, from, i, errno); goto proc_mem_end; } -- 2.7.4 From d233538e2b50d3fe644a64096945ea35fe65495d Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 18 Dec 2018 12:25:56 +0100 Subject: [PATCH 15/16] Release 5.5.5 This release brings one change - DLog format specifier fixes for 64-bit architecures. Change-Id: I443faa5a06afb9c272c953360e0f85cbf913f7db --- packaging/crash-worker.spec | 2 +- packaging/crash-worker_system-tests.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 587c925..287cfbd 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -10,7 +10,7 @@ Name: crash-worker Summary: Crash-manager -Version: 5.5.4 +Version: 5.5.5 Release: 1 Group: Framework/system License: Apache-2.0 and BSD diff --git a/packaging/crash-worker_system-tests.spec b/packaging/crash-worker_system-tests.spec index 6e814f0..c57473b 100644 --- a/packaging/crash-worker_system-tests.spec +++ b/packaging/crash-worker_system-tests.spec @@ -6,7 +6,7 @@ Name: crash-worker_system-tests Summary: Package with binaries and scripts for crash-worker system tests -Version: 5.5.4 +Version: 5.5.5 Release: 1 Group: Framework/system License: Apache-2.0 and BSD -- 2.7.4 From 11f80fbdbf633b1f396e87d87c08de757fdb1bd4 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 17 Jan 2019 12:38:48 +0100 Subject: [PATCH 16/16] svace: fix closing potentially negative fd This commit fixes following issue reported by svace: "Variable 'cinfo.prstatus_fd', which may receive negative value at crash-manager.c:588 by calling function 'set_crash_info' at crash-manager.c:1267, is used at crash-manager.c:1332 by calling function 'close'." Change-Id: Ie625bc8ac5eb16a84bb7b139b569c6189e1a5e25 --- src/crash-manager/crash-manager.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 1cba5ee..e2c6a0f 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -1202,7 +1202,7 @@ static void free_crash_info(struct crash_info *cinfo) int main(int argc, char *argv[]) { - struct crash_info cinfo = {0}; + struct crash_info cinfo = {.prstatus_fd = -1}; /* Execute dump_systemstate in parallel */ static int dump_state_pid; @@ -1319,7 +1319,8 @@ int main(int argc, char *argv[]) launch_crash_popup(&cinfo); exit: - close(cinfo.prstatus_fd); + if (cinfo.prstatus_fd >= 0) + close(cinfo.prstatus_fd); free(crash_temp_path); free(crash_root_path); free(crash_crash_path); -- 2.7.4