summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt7
-rw-r--r--[-rwxr-xr-x]LICENSE0
-rw-r--r--LICENSE.MIT9
-rw-r--r--[-rwxr-xr-x]NOTICE0
-rw-r--r--TODO1
-rw-r--r--include/defs.h.in5
-rw-r--r--packaging/crash-worker.manifest21
-rw-r--r--packaging/crash-worker.spec185
-rw-r--r--packaging/crash-worker_system-tests.manifest25
-rw-r--r--packaging/crash-worker_system-tests.spec91
-rw-r--r--src/crash-manager/70-crash-manager.conf.in2
-rw-r--r--src/crash-manager/CMakeLists.txt7
-rw-r--r--src/crash-manager/crash-manager.c754
-rw-r--r--src/crash-manager/crash-manager.conf38
-rw-r--r--src/crash-manager/crash-manager.conf.d.example3
-rw-r--r--src/crash-manager/crash-manager.h28
-rw-r--r--src/crash-manager/crash-popup-launch.c2
-rw-r--r--src/crash-manager/dbus_notify.c23
-rw-r--r--src/crash-manager/main.c148
-rw-r--r--src/crash-manager/so-info.c177
-rw-r--r--src/crash-manager/so-info.h2
-rw-r--r--src/crash-service/crash-service.c9
-rw-r--r--src/crash-service/crash-service.conf15
-rw-r--r--src/crash-service/crash-service.service.m45
-rw-r--r--src/crash-stack/crash-stack.c4
-rw-r--r--src/crash-stack/dwarf.h652
-rw-r--r--src/crash-stack/proc.c5
-rw-r--r--src/crash-stack/unwind.c79
-rw-r--r--[-rwxr-xr-x]src/dump_systemstate/CMakeLists.txt13
-rw-r--r--src/dump_systemstate/dump_systemstate.c123
-rw-r--r--src/dump_systemstate/extras.c124
-rw-r--r--src/dump_systemstate/extras.h8
-rw-r--r--src/dump_systemstate/files/crash-worker-files.conf9
-rw-r--r--src/dump_systemstate/files/files.conf.example (renamed from src/dump_systemstate/files.conf.example)3
-rw-r--r--src/dump_systemstate/programs/crash-worker-programs.conf73
-rw-r--r--src/dump_systemstate/programs/programs.conf.example (renamed from src/dump_systemstate/programs.conf.example)2
-rw-r--r--src/livedumper/CMakeLists.txt2
-rw-r--r--src/livedumper/core.hpp17
-rw-r--r--src/shared/config.c263
-rw-r--r--src/shared/config.h21
-rw-r--r--src/shared/elf_helpers.h209
-rw-r--r--src/shared/log.h16
-rw-r--r--src/shared/util.c76
-rw-r--r--src/shared/util.h7
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/system/CMakeLists.txt33
-rw-r--r--tests/system/clean_temp/clean_temp.sh.template33
-rwxr-xr-xtests/system/cmp_backtraces/cmp_backtraces.sh.template10
-rw-r--r--tests/system/copy_tizen_manifest/copy_tizen_manifest.sh.template56
-rw-r--r--tests/system/crash_root_path/crash_root_path.sh.template17
-rw-r--r--tests/system/dbus_notify_legacy/dbus_notify_legacy.sh.template80
-rw-r--r--tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template26
-rw-r--r--tests/system/exclude_paths/exclude_paths.sh.template46
-rwxr-xr-xtests/system/full_core/full_core.sh.template50
-rwxr-xr-xtests/system/libcrash-service/libcrash-service.sh.template2
-rw-r--r--tests/system/log_file/log_file.sh.template3
-rw-r--r--tests/system/report_basic/report_basic.sh.template2
-rw-r--r--tests/system/so_info_file/so_info_file.sh.template2
-rw-r--r--tests/system/temp_lock/temp_lock.sh.template37
-rw-r--r--tests/system/utils/CMakeLists.txt3
-rw-r--r--tests/system/utils/minicore-utils.sh13
-rw-r--r--tests/system/without_so_info_file/without_so_info_file.sh.template40
62 files changed, 2975 insertions, 743 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 630e1aa..e7579d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,14 +7,9 @@ ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE=1)
# Sub modules
ADD_SUBDIRECTORY(include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/crash-service)
ADD_SUBDIRECTORY(src/crash-manager)
-
-IF("${SYS_ASSERT}" STREQUAL "ON")
- ADD_SUBDIRECTORY(src/sys-assert)
-ENDIF("${SYS_ASSERT}" STREQUAL "ON")
-
ADD_SUBDIRECTORY(src/crash-stack)
ADD_SUBDIRECTORY(src/dump_systemstate)
diff --git a/LICENSE b/LICENSE
index 8aa906c..8aa906c 100755..100644
--- a/LICENSE
+++ b/LICENSE
diff --git a/LICENSE.MIT b/LICENSE.MIT
new file mode 100644
index 0000000..5b16ef4
--- /dev/null
+++ b/LICENSE.MIT
@@ -0,0 +1,9 @@
+The MIT License
+
+Copyright (c) 2019 Samsung Electronics
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/NOTICE b/NOTICE
index 579ba56..579ba56 100755..100644
--- a/NOTICE
+++ b/NOTICE
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..7c41e96
--- /dev/null
+++ b/TODO
@@ -0,0 +1 @@
+* In the future "/usr/bin/pkgcmd --global" as crash_worker user will stop working, so it needs to be changed to get installed applications for the global user and for the actual user.
diff --git a/include/defs.h.in b/include/defs.h.in
index 3ac9871..906b649 100644
--- a/include/defs.h.in
+++ b/include/defs.h.in
@@ -2,11 +2,13 @@
#define __DEFS_H__
#define KERNEL_DEFINED_TASK_COMM_LEN 16 // from include/linux/sched.h
+#define DEFAULT_UMASK 0077
+#define DEFAULT_REPORT_PERM 0644
+#define DEFAULT_CRASH_DIR_PERM 0775
#define CRASH_PATH "@CRASH_PATH@"
#define CRASH_ROOT_PATH "@CRASH_ROOT_PATH@"
#define CRASH_TEMP "@CRASH_TEMP@"
-#define SYS_ASSERT "@SYS_ASSERT@"
#define CRASH_STACK_BIN_PATH "@CRASH_STACK_BIN_PATH@"
#define CRASH_POPUP_BIN_PATH "@CRASH_POPUP_BIN_PATH@"
#define CRASH_NOTIFY_BIN_PATH "@CRASH_NOTIFY_BIN_PATH@"
@@ -17,5 +19,6 @@
#define MINICOREDUMPER_CONFIG_PATH "@MINICOREDUMPER_CONFIG_PATH@"
#define DEBUGMODE_PATH "@DEBUGMODE_PATH@"
#define LIVEDUMPER_BIN_PATH "@LIVEDUMPER_BIN_PATH@"
+#define DLOG_LOG_LEVEL @DLOG_LOG_LEVEL@
#endif /* __DEFS_H__ */
diff --git a/packaging/crash-worker.manifest b/packaging/crash-worker.manifest
index 25bee3e..0b9ab26 100644
--- a/packaging/crash-worker.manifest
+++ b/packaging/crash-worker.manifest
@@ -5,5 +5,26 @@
<assign>
<filesystem path="/usr/bin/dump_systemstate" label="System" exec_label="System"/>
<filesystem path="/usr/bin/crash-manager" label="System" exec_label="System"/>
+
+ <filesystem path="/usr/lib/crash-worker/system-tests/full_core/full_core.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/check_minicore_mem/check_minicore_mem.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/check_minicore_mem/cp.sh" label="User::Shell" exec_label="System"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/cmp_backtraces/cmp_backtraces.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/cmp_backtraces/cp.sh" label="User::Shell" exec_label="System"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/critical_process/critical_process.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/time_test/time_test.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/time_test/cp.sh" label="User::Shell" exec_label="System"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/wait_for_opt_usr/wait_for_opt_usr.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/info_file/info_file.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/log_file/log_file.sh" label="User::Shell" exec_label="User::Shell"/>
+ <filesystem path="/usr/lib/crash-worker/system-tests/so_info_file/so_info_file.sh" label="User::Shell" exec_label="User::Shell"/>
+ <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"/>
+ <filesystem path="/usr/bin/crash-worker-system-tests-run.sh" label="User::Shell" exec_label="User::Shell"/>
</assign>
</manifest>
diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec
index 41fe249..fc3af9e 100644
--- a/packaging/crash-worker.spec
+++ b/packaging/crash-worker.spec
@@ -11,14 +11,14 @@
# NOTE: To disable coredump set DumpCore=0 in configuration file
-Name: crash-worker
-Summary: Crash-manager
-Version: 5.5.26
-Release: 1
-Group: Framework/system
-License: Apache-2.0 and BSD
-Source0: %{name}-%{version}.tar.gz
-Source1001: crash-worker.manifest
+Name: crash-worker
+Summary: Coredump handler and report generator for Tizen
+Version: 5.5.46
+Release: 1
+Group: Framework/system
+License: Apache-2.0 and BSD-2-Clause and MIT
+Source0: %{name}-%{version}.tar.gz
+Source1001: crash-worker.manifest
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(iniparser)
@@ -27,11 +27,10 @@ BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(rpm)
BuildRequires: cmake
BuildRequires: pkgconfig(pkgmgr-info)
-
BuildRequires: pkgconfig(libunwind-generic)
BuildRequires: libelf-devel libelf
-BuildRequires: libebl-devel libebl
BuildRequires: libdw-devel libdw
+BuildRequires: libcap-devel
%if %{with doc}
BuildRequires: doxygen
@@ -44,48 +43,57 @@ BuildRequires: boost-devel
Requires(post): coreutils
Requires(post): tar
Requires(post): gzip
-Requires: zip
-Requires: libelf
-Requires: libdw
-Requires: minicoredumper >= 2.1.0
-Requires: %{_bindir}/buxton2ctl
+Requires: zip
+Requires: libelf
+Requires: libdw
+Requires: minicoredumper >= 2.1.0
+Requires: %{_bindir}/buxton2ctl
%if %{with crashservice}
-Requires: %{name}-livedumper = %{version}-%{release}
+Requires: %{name}-livedumper = %{version}-%{release}
%endif
-
%description
-crash-manager
-%package devel
-Requires: crash-worker
-Summary: Crash-manager development package
-%description devel
-This package provides library and header files.
+%package -n libcrash-service
+Summary: libcrash-service provides API to communicate with crash-service
+%description -n libcrash-service
-%if %{with doc}
-%package doc
-Summary: Documentation package for crash-worker
-Group: Framework/System
+%package devel
+Requires: libcrash-service
+Summary: Crash-manager headers and library for linking
+%description devel
-%description doc
-This package provides development documentation for crash-worker.
+%if %{with doc}
+%package doc
+Summary: Documentation package for crash-worker
+Group: Framework/System
+%description doc
%endif
%if %{with tests}
-%package tests
-Summary: Package with binaries and data for crash-worker tests
-
-%description tests
-This package contains installable tests in Bash.
+%package tests
+Summary: Package with binaries and data for crash-worker tests
+%description tests
%endif
%if %{with livedumper}
-%package livedumper
-Summary: Livedumper allows to dump core of live process
-
-%description livedumper
+%package livedumper
+Summary: Livedumper allows to dump core of live process
+%description livedumper
%endif
+%package system-tests
+Summary: System tests for crash-worker components
+Requires: diff
+Requires: gdb
+Requires: coreutils
+Requires: tlm
+Requires: /bin/bash
+Requires: /usr/bin/unzip
+Requires: /usr/bin/mcookie
+Requires: %{_sbindir}/minicoredumper
+Requires: %{name}-system-tests-debuginfo = %{version}-%{release}
+%description system-tests
+
%prep
%setup -q
@@ -134,14 +142,17 @@ export CFLAGS+=" -Werror"
-DCRASH_STACK_BIN_PATH=%{_libexecdir}/crash-stack \
-DCRASH_POPUP_BIN_PATH=%{_libexecdir}/crash-popup-launch \
-DCRASH_NOTIFY_BIN_PATH=%{_libexecdir}/crash-notify-send \
- -DCRASH_TESTS_PATH=%{_libdir}/crash-worker-tests \
+ -DCRASH_TESTS_PATH=%{_libdir}/crash-worker/tests \
+ -DCRASH_SYSTEM_TESTS_PATH=%{_libdir}/crash-worker/system-tests \
-DLIVEDUMPER=%{on_off livedumper} \
-DCRASH_SERVICE=%{on_off crashservice} \
-DUPGRADE_SCRIPT_PATH=%{upgrade_script_path} \
-DLOGGER=dlog \
+ -DDLOG_LOG_LEVEL=DLOG_INFO \
-DVERSION=%{version}
make %{?jobs:-j%jobs}
+
%if %{with doc}
make doc
%endif
@@ -151,41 +162,53 @@ rm -rf %{buildroot}
%make_install
mkdir -p %{buildroot}%{crash_root_path}
mkdir -p %{buildroot}%{crash_path}
-mkdir -p %{buildroot}%{crash_temp}
%post
-/usr/bin/chsmack -a "System" -t %{crash_path}
-/usr/bin/chsmack -a "System" -t %{crash_temp}
+chsmack -a "System" -t %{crash_root_path}
+chsmack -a "System" -t %{crash_path}
+
+if [ $1 -eq 2 ] ; then
+ # All directories are created with appropriate permissions by
+ # crash-manager/service (0775) and with correct label (System)
+ # due to smack execute being set to System on /usr/bin/crash-manager
+ # binary.
+ #
+ # Following is only for package-based upgrade in Tizen 6.5
+ # Drop this in Tizen 7.0
+ chsmack -a "System" -t %{crash_temp}
+fi
%files
-%license LICENSE LICENSE.BSD
+%license LICENSE LICENSE.BSD LICENSE.MIT
%manifest crash-worker.manifest
-%defattr(-,system_fw,system_fw,-)
+%defattr(-,crash_worker,crash_worker,-)
%dir %{crash_root_path}
-%dir %{crash_path}
-%dir %{crash_temp}
+%attr(0775,crash_worker,crash_worker) %{crash_path}
%{_sysconfdir}/crash-manager.conf
+%{_sysconfdir}/crash-manager.conf.d/crash-manager.conf.example
%attr(-,root,root) %{_prefix}/lib/sysctl.d/70-crash-manager.conf
-%attr(0750,system_fw,system_fw) %{_bindir}/crash-manager
-%attr(0750,system_fw,system_fw) %{_bindir}/dump_systemstate
-%{_sysconfdir}/dump_systemstate.conf.d/files/files.conf.example
-%{_sysconfdir}/dump_systemstate.conf.d/programs/programs.conf.example
+%attr(0750,crash_worker,crash_worker) %{_bindir}/crash-manager
+%attr(0750,crash_worker,crash_worker) %{_bindir}/dump_systemstate
+%{_sysconfdir}/dump_systemstate.conf.d/files/*.conf*
+%{_sysconfdir}/dump_systemstate.conf.d/programs/*.conf*
%{_libexecdir}/crash-stack
%{_libexecdir}/crash-popup-launch
%{_libexecdir}/crash-notify-send
%{_libdir}/libcrash-manager.so.*
%if %{with crashservice}
-%attr(0750,system_fw,system_fw) %{_bindir}/crash-service
+%attr(0750,crash_worker,crash_worker) %{_bindir}/crash-service
%attr(-,root,root) %{_unitdir}/crash-service.service
%attr(-,root,root) %{_sysconfdir}/dbus-1/system.d/crash-service.conf
%attr(-,root,root) %{_datadir}/dbus-1/system-services/org.tizen.system.crash.livedump.service
-%{_libdir}/libcrash-service.so.*
%endif
#upgrade script
%attr(-,root,root) %{upgrade_script_path}/500.crash-manager-upgrade.sh
+%files -n libcrash-service
+%{_libdir}/libcrash-service.so.*
+
%files devel
%{_includedir}/crash-manager.h
%{_libdir}/libcrash-manager.so
@@ -205,15 +228,15 @@ mkdir -p %{buildroot}%{crash_temp}
%files tests
%manifest %{name}.manifest
%defattr(-,root,root)
-%{_libdir}/crash-worker-tests/test1-default-crash
-%{_libdir}/crash-worker-tests/test1-default-sleep
-%{_libdir}/crash-worker-tests/test1-default-ill
-%{_libdir}/crash-worker-tests/test1-custom-crash
-%{_libdir}/crash-worker-tests/test1-custom-sleep
-%{_libdir}/crash-worker-tests/test1-custom-ill
-%{_libdir}/crash-worker-tests/run_tests.sh
-%{_libdir}/crash-worker-tests/tests_common.sh
-%{_libdir}/crash-worker-tests/crash_common.sh
+%{_libdir}/crash-worker/tests/test1-default-crash
+%{_libdir}/crash-worker/tests/test1-default-sleep
+%{_libdir}/crash-worker/tests/test1-default-ill
+%{_libdir}/crash-worker/tests/test1-custom-crash
+%{_libdir}/crash-worker/tests/test1-custom-sleep
+%{_libdir}/crash-worker/tests/test1-custom-ill
+%{_libdir}/crash-worker/tests/run_tests.sh
+%{_libdir}/crash-worker/tests/tests_common.sh
+%{_libdir}/crash-worker/tests/crash_common.sh
%endif
@@ -222,3 +245,43 @@ mkdir -p %{buildroot}%{crash_temp}
%manifest %{name}.manifest
%{_bindir}/livedumper
%endif
+
+%files system-tests
+%manifest %{name}.manifest
+%{_bindir}/crash-worker-system-tests-run
+
+%{_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/clean_temp/clean_temp.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
+%{_libdir}/crash-worker/system-tests/dbus_notify_legacy/dbus_notify_legacy.sh
+%{_libdir}/crash-worker/system-tests/dump_systemstate_extras/dump_systemstate_extras.sh
+%{_libdir}/crash-worker/system-tests/exclude_paths/exclude_paths.sh
+%{_libdir}/crash-worker/system-tests/extra_script/extra_script.sh
+%{_libdir}/crash-worker/system-tests/full_core/full_core.sh
+%{_libdir}/crash-worker/system-tests/info_file/info_file.sh
+%{_libdir}/crash-worker/system-tests/libcrash-service/libcrash-service.sh
+%{_libdir}/crash-worker/system-tests/log_file/log_file.sh
+%{_libdir}/crash-worker/system-tests/output_param/output_param.sh
+%{_libdir}/crash-worker/system-tests/report_basic/report_basic.sh
+%{_libdir}/crash-worker/system-tests/report_type_info/report_type_info.sh
+%{_libdir}/crash-worker/system-tests/so_info_file/so_info_file.sh
+%{_libdir}/crash-worker/system-tests/temp_lock/temp_lock.sh
+%{_libdir}/crash-worker/system-tests/time_test/cp.sh
+%{_libdir}/crash-worker/system-tests/time_test/time_test.sh
+%{_libdir}/crash-worker/system-tests/utils/btee
+%{_libdir}/crash-worker/system-tests/utils/kenny
+%{_libdir}/crash-worker/system-tests/utils/libcrash-servicetest
+%{_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_so_info_file/without_so_info_file.sh
+%{_libdir}/crash-worker/system-tests/without_core/without_core.sh
+
+%if %{with livedumper}
+%{_libdir}/crash-worker/system-tests/livedumper/livedumper.sh
+%endif
diff --git a/packaging/crash-worker_system-tests.manifest b/packaging/crash-worker_system-tests.manifest
deleted file mode 100644
index 15573a3..0000000
--- a/packaging/crash-worker_system-tests.manifest
+++ /dev/null
@@ -1,25 +0,0 @@
-<manifest>
- <request>
- <domain name="_"/>
- </request>
- <assign>
- <filesystem path="/usr/lib/crash-worker_system-tests/check_minicore_mem/check_minicore_mem.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/check_minicore_mem/cp.sh" label="User::Shell" exec_label="System"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/cmp_backtraces/cmp_backtraces.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/cmp_backtraces/cp.sh" label="User::Shell" exec_label="System"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/critical_process/critical_process.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/time_test/time_test.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/time_test/cp.sh" label="User::Shell" exec_label="System"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/wait_for_opt_usr/wait_for_opt_usr.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/info_file/info_file.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/log_file/log_file.sh" label="User::Shell" exec_label="User::Shell"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/so_info_file/so_info_file.sh" label="User::Shell" exec_label="User::Shell"/>
- <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/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"/>
- <filesystem path="/usr/lib/crash-worker_system-tests/run.sh" label="User::Shell" exec_label="User::Shell"/>
- </assign>
-</manifest>
diff --git a/packaging/crash-worker_system-tests.spec b/packaging/crash-worker_system-tests.spec
deleted file mode 100644
index f289f5e..0000000
--- a/packaging/crash-worker_system-tests.spec
+++ /dev/null
@@ -1,91 +0,0 @@
-%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
-%define _with_livedumper on
-%bcond_with livedumper
-
-Name: crash-worker_system-tests
-Summary: Package with binaries and scripts for crash-worker system tests
-Version: 5.5.26
-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: pkgconfig(dlog)
-BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(crash-service)
-BuildRequires: cmake
-
-Requires: diff
-Requires: gdb
-Requires: coreutils
-Requires: tlm
-Requires: /bin/bash
-Requires: /usr/bin/unzip
-Requires: /usr/bin/mcookie
-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/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
-%{_libdir}/crash-worker_system-tests/dump_systemstate_extras/dump_systemstate_extras.sh
-%{_libdir}/crash-worker_system-tests/extra_script/extra_script.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/report_basic/report_basic.sh
-%{_libdir}/crash-worker_system-tests/report_type_info/report_type_info.sh
-%{_libdir}/crash-worker_system-tests/run.sh
-%{_libdir}/crash-worker_system-tests/so_info_file/so_info_file.sh
-%{_libdir}/crash-worker_system-tests/time_test/cp.sh
-%{_libdir}/crash-worker_system-tests/time_test/time_test.sh
-%{_libdir}/crash-worker_system-tests/utils/btee
-%{_libdir}/crash-worker_system-tests/utils/kenny
-%{_libdir}/crash-worker_system-tests/utils/libcrash-servicetest
-%{_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
-%{_libdir}/crash-worker_system-tests/libcrash-service/libcrash-service.sh
-%if %{with livedumper}
-%{_libdir}/crash-worker_system-tests/livedumper/livedumper.sh
-%endif
-%defattr(-,root,root)
-
-# %post
-# /usr/bin/chsmack -a "_" -e "SSSystem::Privileged" -r %{_libdir}/crash-worker_system-tests/
-
diff --git a/src/crash-manager/70-crash-manager.conf.in b/src/crash-manager/70-crash-manager.conf.in
index b7dfe62..f788a2e 100644
--- a/src/crash-manager/70-crash-manager.conf.in
+++ b/src/crash-manager/70-crash-manager.conf.in
@@ -1,5 +1,5 @@
# Tizen crash-manager
-kernel.core_pattern=|/usr/bin/crash-manager -p %p -u %u -g %g -s %s -t %t
+kernel.core_pattern=|/usr/bin/crash-manager -E %E -p %p -u %u -g %g -s %s -t %t
kernel.core_pipe_limit=10
# All processes should be dumped
fs.suid_dumpable=2
diff --git a/src/crash-manager/CMakeLists.txt b/src/crash-manager/CMakeLists.txt
index b38a084..2fdf2a2 100644
--- a/src/crash-manager/CMakeLists.txt
+++ b/src/crash-manager/CMakeLists.txt
@@ -43,7 +43,7 @@ SET_TARGET_PROPERTIES(libcrash-manager PROPERTIES OUTPUT_NAME crash-manager)
TARGET_LINK_LIBRARIES(libcrash-manager ${crash-manager_pkgs_LDFLAGS})
ADD_EXECUTABLE(${PROJECT_NAME} ${CRASH_MANAGER_SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${crash-manager_pkgs_LDFLAGS} -pie -lrt libcrash-manager)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${crash-manager_pkgs_LDFLAGS} -pie -lcap -lrt libcrash-manager)
set(CRASH_POPUP crash-popup-launch)
ADD_EXECUTABLE(${CRASH_POPUP} ${CRASH_POPUP}.c)
@@ -69,6 +69,11 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/crash-manager.conf
DESTINATION /etc
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/crash-manager.conf.d.example
+ DESTINATION /etc/crash-manager.conf.d/
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+ RENAME crash-manager.conf.example)
+
INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/crash-manager.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c
index 86396db..d3f4e98 100644
--- a/src/crash-manager/crash-manager.c
+++ b/src/crash-manager/crash-manager.c
@@ -59,8 +59,10 @@
#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
+#define SPACE_REQUIRED_KB 1024
#define MINICOREDUMPER_TIMEOUT_MS DEFAULT_COMMAND_TIMEOUT_MS
#define LIVEDUMPER_TIMEOUT_MS DEFAULT_COMMAND_TIMEOUT_MS
@@ -85,6 +87,11 @@ config_t config;
static char* crash_dump_path;
static char* crash_temp_path;
+bool have_livecoredumper(void)
+{
+ return access(LIVEDUMPER_BIN_PATH, X_OK) == 0;
+}
+
/* pkgmgrinfo filter list function for getting application ID */
static int appinfo_get_appid_func(pkgmgrinfo_appinfo_h handle,
void *user_data)
@@ -98,76 +105,114 @@ static int appinfo_get_appid_func(pkgmgrinfo_appinfo_h handle,
return ret;
}
-/* get application ID by pkgmgrinfo filter */
-static int get_appid(char *exepath, char *appid, int len)
+static bool get_appid(char *exepath, char **appid)
{
pkgmgrinfo_appinfo_filter_h handle = NULL;
- int count, ret;
- char *aid = NULL;
+ bool have_appid = false;
- ret = pkgmgrinfo_appinfo_filter_create(&handle);
- if (ret != PMINFO_R_OK) {
- ret = -1;
- goto out;
- }
+ if (pkgmgrinfo_appinfo_filter_create(&handle) != PMINFO_R_OK)
+ return false;
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_EXEC, exepath);
- if (ret != PMINFO_R_OK) {
- ret = -1;
+ if (pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_EXEC, exepath) != PMINFO_R_OK)
goto out_free;
- }
- ret = pkgmgrinfo_appinfo_filter_count(handle, &count);
- if (ret != PMINFO_R_OK) {
- ret = -1;
+ int count = 0;
+ if (pkgmgrinfo_appinfo_filter_count(handle, &count) || count < 1)
goto out_free;
- }
- if (count < 1) {
- ret = -1;
+ char *aid = NULL;
+ if (pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, appinfo_get_appid_func, &aid) != PMINFO_R_OK)
goto out_free;
- }
- ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, appinfo_get_appid_func, &aid);
- if (ret != PMINFO_R_OK) {
- ret = -1;
- goto out_free;
- }
- if (aid) {
- snprintf(appid, len, "%s", aid);
- ret = 0;
- free(aid);
- }
+ have_appid = aid != NULL;
+ if (have_appid)
+ *appid = strdup(aid);
out_free:
pkgmgrinfo_appinfo_filter_destroy(handle);
-out:
- return ret;
+ return have_appid && *appid != NULL;
}
-/* get package ID by appid */
-static int get_pkgid(char *appid, char *pkgid, int len)
+static bool get_pkgid(char *appid, char **pkgid)
{
pkgmgrinfo_appinfo_h handle = NULL;
- int ret;
- char *pkid = NULL;
- ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
- if (ret != PMINFO_R_OK) {
- ret = -1;
- goto out;
- }
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkid);
- if (ret != PMINFO_R_OK) {
- ret = -1;
+ if (pkgmgrinfo_appinfo_get_appinfo(appid, &handle) != PMINFO_R_OK)
+ return false;
+
+ bool have_pkgid = false;
+ char *p = NULL;
+ if (pkgmgrinfo_appinfo_get_pkgid(handle, &p) != PMINFO_R_OK)
goto out_free;
- }
- snprintf(pkgid, len, "%s", pkid);
+
+ have_pkgid = p != NULL;
+ if (have_pkgid)
+ *pkgid = strdup(p);
out_free:
pkgmgrinfo_appinfo_destroy_appinfo(handle);
-out:
- return ret;
+ 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;
+
+ if (get_appid(exepath, &a)) {
+ *appid = a;
+ *pkgid = get_pkgid(a, &p) ? p : strdup(a);
+ return true;
+ }
+
+ char *bn = basename(exepath);
+ *appid = strdup(bn);
+ *pkgid = strdup(bn);
+ return false;
+}
+
+static int check_disk_available(const char *path, int check_size)
+{
+ struct statfs lstatfs;
+
+ if (!path)
+ return false;
+
+ if (statfs(path, &lstatfs) < 0) {
+ _E("Error when checking free space (%d): %m", errno);
+ return false;
+ }
+ int avail_size = (int)(lstatfs.f_bavail * (lstatfs.f_bsize / 1024));
+
+ if (check_size > avail_size) {
+ _E("Available disk space (%d) is less than (%d)", avail_size, check_size);
+ return false;
+ }
+
+ return true;
}
static int prepare_paths(struct crash_info* cinfo)
@@ -202,6 +247,13 @@ static int prepare_paths(struct crash_info* cinfo)
return 1;
}
+static void unlock_dir(int fd)
+{
+ if (flock(fd, LOCK_UN) < 0)
+ _E("Failed to unlock file descriptor: %m");
+ close(fd);
+}
+
static bool make_dump_dir(void)
{
const char *dirs[] = {crash_dump_path, crash_temp_path};
@@ -210,14 +262,17 @@ static bool make_dump_dir(void)
const char *dirname = dirs[i];
int r = mkdir(dirname, 0775);
- if (r >= 0)
- continue;
- if (errno != EEXIST) {
+ if (r < 0 && errno != EEXIST) {
_E("Unable to create directory %s: %m", dirname);
return false;
}
+ chmod(dirname, DEFAULT_CRASH_DIR_PERM); // Fixup permissions for directories created with bad umask
+
+ if (r >= 0)
+ continue;
+
struct stat st = {0};
r = stat(dirname, &st);
bool isdir = !!(st.st_mode & S_IFDIR);
@@ -238,24 +293,36 @@ static bool get_cmd_info(struct crash_info *cinfo)
{
assert(cinfo);
- cinfo->cmd_line = malloc(PATH_MAX);
+ char buf[PATH_MAX];
+
+ if (!read_proc_file(cinfo->pid_info, "cmdline", buf, sizeof(buf), NULL))
+ goto err;
+
+ cinfo->cmd_line = strdup(buf);
if (!cinfo->cmd_line)
return false;
- if (!read_proc_file(cinfo->pid_info, "cmdline", cinfo->cmd_line, PATH_MAX, NULL))
+ if (!read_proc_file(cinfo->tid_info, "comm", buf, sizeof(buf), filter_drop_trailing_whitespace))
+ goto err;
+
+ cinfo->comm = strdup(buf);
+ if (!cinfo->comm)
goto err;
- char buf[PATH_MAX];
if (!get_exe_path(cinfo->pid_info, buf, sizeof(buf)))
goto err;
cinfo->cmd_path = strdup(buf);
+ if (!cinfo->cmd_path)
+ goto err;
- return !!cinfo->cmd_path;
+ return true;
err:
free(cinfo->cmd_line);
cinfo->cmd_line = NULL;
+ free(cinfo->comm);
+ cinfo->comm = NULL;
return false;
}
@@ -308,124 +375,165 @@ close_fd:
return -1;
}
-bool set_crash_info(struct crash_info *cinfo)
+void get_proc_name(const char *cmd_line, char *buff, size_t buff_len)
{
- int ret;
- char *temp_dir_ret = NULL;
- char date[80];
- struct tm loc_tm;
+ assert(buff != NULL);
+ char *space = strchr(cmd_line, ' ');
+ size_t name_len;
+
+ if (space == NULL)
+ name_len = strlen(cmd_line);
+ else
+ name_len = space - cmd_line;
+
+ if (name_len > buff_len - 1)
+ name_len = buff_len - 1;
+
+ strncpy(buff, cmd_line, name_len);
+
+ buff[name_len] = '\0';
+}
+static void set_crash_info_defaults(struct crash_info *cinfo)
+{
if (cinfo->livedump) {
- if (cinfo->kill)
- cinfo->sig_info = 9;
- else
- cinfo->sig_info = 0;
- }
+ cinfo->sig_info = cinfo->kill ? SIGKILL : 0;
+ } else if (cinfo->tid_info == -1)
+ cinfo->tid_info = find_crash_tid(cinfo->pid_info);
- if (cinfo->livedump && !file_exists(LIVEDUMPER_BIN_PATH)) {
- fprintf(stderr, "Error: %s doesn't exist - can not perform livedump. Terminating.\n", LIVEDUMPER_BIN_PATH);
- _E("Error: %s doesn't exist - can not perform livedump. Terminating.\n", LIVEDUMPER_BIN_PATH);
- return false;
+ if (cinfo->tid_info == -1) {
+ _W("TID not known. Assuming TID = PID (%d).", cinfo->pid_info);
+ cinfo->tid_info = cinfo->pid_info;
}
+}
- if (cinfo->tid_info == -1) {
- if (cinfo->livedump) {
- cinfo->tid_info = cinfo->pid_info;
- } else {
- cinfo->tid_info = find_crash_tid(cinfo->pid_info);
- if (cinfo->tid_info < 0) {
- _I("TID not found");
- cinfo->tid_info = cinfo->pid_info;
- }
- }
+static int dump_filter(const struct dirent *de)
+{
+ assert(de);
+
+ if (de->d_name[0] == '.')
+ return 0;
+ return 1;
+}
+
+/* We treat all errors as if the file was locked. This function is used to check
+ * if we can remove the temporary directory. We don't want to remove that
+ * directory if an error has occurred, because the deletion will probably also
+ * fail */
+static bool is_locked(const char *dir_name)
+{
+ assert(dir_name);
+
+ char lock_file[PATH_MAX];
+ if (snprintf(lock_file, sizeof(lock_file), "%s", dir_name) == -1) {
+ _E("Unable to check locking status for %s: %m", dir_name);
+ return true;
}
- if (!get_cmd_info(cinfo)) {
- _E("Failed to get command info");
- return false;
+ int fd = open(lock_file, O_RDONLY | O_DIRECTORY);
+ if (fd == -1) {
+ _E("Unable to open file %s to check if it's blocked: %m", lock_file);
+ return true;
}
- if (cinfo->time_info == 0)
- cinfo->time_info = time(NULL);
+ bool result = flock(fd, LOCK_EX | LOCK_NB) == -1;
- localtime_r(&cinfo->time_info, &loc_tm);
- strftime(date, sizeof(date), "%Y%m%d%H%M%S", &loc_tm);
+ close(fd);
+ return result;
+}
- if (asprintf(&cinfo->temp_dir, "%s/crash.XXXXXX", crash_temp_path) == -1) {
- _E("Failed to asprintf for temp_dir");
- cinfo->temp_dir = NULL;
- return false;
- }
+static bool clean_temp(const char *temp_dir)
+{
+ bool result = true;
+ assert(temp_dir);
+
+ struct dirent **scan_list = NULL;
+ int scan_num;
- temp_dir_ret = mkdtemp(cinfo->temp_dir);
- if (!temp_dir_ret || access(temp_dir_ret, F_OK)) {
- _E("Failed to mkdtemp for temp_dir");
+ if ((scan_num = scandir(temp_dir, &scan_list, &dump_filter, NULL)) < 0)
return false;
- }
- if (asprintf(&cinfo->name, "%s_%d_%s", basename(cinfo->cmd_line),
- cinfo->pid_info, date) == -1) {
- _E("Failed to snprintf for name");
- cinfo->name = NULL;
- goto rm_temp;
- }
+ for (int i = 0; i < scan_num; i++) {
+ char dir_name[PATH_MAX];
- if (config.allow_zip)
- ret = asprintf(&cinfo->result_path,
- "%s/%s.zip", crash_dump_path, cinfo->name);
- else
- ret = asprintf(&cinfo->result_path,
- "%s/%s", crash_dump_path, cinfo->name);
- if (ret == -1) {
- _E("Failed to asprintf for result path");
- cinfo->result_path = NULL;
- goto rm_temp;
- }
+ if (snprintf(dir_name, sizeof(dir_name), "%s/%s", temp_dir, scan_list[i]->d_name) == -1) {
+ _E("Unable to clean temp for %s: %m", dir_name);
+ result = false;
+ continue;
+ }
- if (asprintf(&cinfo->pfx, "%s/%s", cinfo->temp_dir, cinfo->name) == -1) {
- _E("Failed to asprintf for pfx");
- cinfo->pfx = NULL;
- goto rm_temp;
- }
- ret = mkdir(cinfo->pfx, 0775);
- if (ret < 0) {
- _E("Failed to mkdir for %s", cinfo->pfx);
- goto rm_temp;
+ if (is_locked(dir_name))
+ _D("Temporary directory %s is locked", dir_name);
+ else if (!remove_dir(dir_name, true))
+ _W("Can not remove temporary directory: %s", dir_name);
+ else
+ _D("Temporary directory %s removed", dir_name);
}
- if (asprintf(&cinfo->info_path, "%s/%s.info", cinfo->pfx, cinfo->name) == -1) {
- _E("Failed to asprintf for info path");
- cinfo->info_path = NULL;
- goto rm_temp;
+ return result;
+}
+
+/* Note: caller of this function is responsible for cleaning up the cinfo on failure */
+bool set_crash_info(struct crash_info *cinfo)
+{
+ set_crash_info_defaults(cinfo);
+
+ if (!get_cmd_info(cinfo)) {
+ _E("Failed to get command info");
+ return false;
}
- if (asprintf(&cinfo->core_path, "%s/%s.coredump", cinfo->pfx, cinfo->name) == -1) {
- _E("Failed to asprintf for core path");
- cinfo->core_path = NULL;
- goto rm_temp;
+ char date[16];
+ struct tm loc_tm;
+ cinfo->time_info = time(NULL);
+ localtime_r(&cinfo->time_info, &loc_tm);
+ strftime(date, sizeof(date), "%Y%m%d%H%M%S", &loc_tm);
+
+ if (asprintf(&cinfo->temp_dir, "%s/crash.XXXXXX", crash_temp_path) == -1)
+ goto out_oom;
+
+ if (mkdtemp(cinfo->temp_dir) == NULL || access(cinfo->temp_dir, F_OK)) {
+ _E("Failed to create temporary directory %s: %m", cinfo->temp_dir);
+ return false;
}
- if (asprintf(&cinfo->log_path, "%s/%s.log", cinfo->pfx, cinfo->name) == -1) {
- _E("Failed to asprintf for log path");
- cinfo->log_path = NULL;
- goto rm_temp;
+ char proc_name[PATH_MAX];
+ get_proc_name(cinfo->cmd_line, proc_name, sizeof(proc_name));
+ const char *suffix = config.report_type >= REP_TYPE_FULL ? (config.allow_zip ? ".zip" : "") : ".info";
+ bool is_app = set_appinfo(cinfo->cmd_line, &cinfo->appid, &cinfo->pkgid);
+ if (!cinfo->appid || !cinfo->pkgid)
+ goto out_oom;
+
+ if (-1 == asprintf(&cinfo->name, "%s_%d_%s", is_app ? cinfo->pkgid : basename(proc_name), cinfo->pid_info, date)
+ || -1 == asprintf(&cinfo->pfx, "%s/%s", cinfo->temp_dir, cinfo->name)
+ || -1 == asprintf(&cinfo->info_path, "%s/%s.info", cinfo->pfx, cinfo->name)
+ || -1 == asprintf(&cinfo->core_path, "%s/%s.coredump", cinfo->pfx, cinfo->name)
+ || -1 == asprintf(&cinfo->log_path, "%s/%s.log", cinfo->pfx, cinfo->name)
+ || -1 == asprintf(&cinfo->zip_path, "%s/report.zip", cinfo->temp_dir)
+ || -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);
+ goto out_rm_temp;
}
if (set_prstatus(cinfo) < 0)
- goto rm_temp;
-
- if (get_appid(cinfo->cmd_line, cinfo->appid, sizeof(cinfo->appid)) < 0) {
- snprintf(cinfo->appid, sizeof(cinfo->appid), "%s", basename(cinfo->cmd_line));
- snprintf(cinfo->pkgid, sizeof(cinfo->pkgid), "%s", basename(cinfo->cmd_line));
- } else {
- if (get_pkgid(cinfo->appid, cinfo->pkgid, sizeof(cinfo->pkgid)) < 0)
- snprintf(cinfo->pkgid, sizeof(cinfo->pkgid), "%s", cinfo->appid);
- }
+ goto out_rm_temp;
return true;
-rm_temp:
- remove_dir(cinfo->temp_dir, 1);
+out_rm_temp:
+ unlock_dir(cinfo->lock_fd);
+ remove_dir(cinfo->temp_dir, true);
+ clean_temp(crash_temp_path);
+ return false;
+
+out_oom:
+ _E("Out of memory");
return false;
}
@@ -444,7 +552,7 @@ static void launch_crash_popup(struct crash_info *cinfo)
static bool dump_system_state(const struct crash_info *cinfo, pid_t *pid)
{
- char *av[] = {DUMP_SYSTEMSTATE_BIN_PATH, "-d", "-k", "-j", "-p", "-e", "-f", cinfo->log_path, NULL};
+ char *av[] = {DUMP_SYSTEMSTATE_BIN_PATH, "-d", "-k", "-j", "-p", "-e", "-f", cinfo->log_path, "-b", NULL};
spawn_param_s param = { .fn = spawn_setstdout, .u.int_val = STDERR_FILENO };
return spawn(av, NULL, &param, pid, NULL);
}
@@ -465,9 +573,9 @@ static void save_so_info(const struct crash_info *cinfo)
/* remove a file whose name begins with 'beggining_of_name'. This is needed
* when we don't want to include coredump in report, but we only know the
* beginning of the coredump file name. */
-static int remove_file_in_dir(const char *directory, const char *beginning_of_name)
+static bool remove_file_in_dir(const char *directory, const char *beginning_of_name)
{
- int ret = -1;
+ bool ret = false;
int errno_unlink = 0;
DIR *dir = opendir(directory);
@@ -483,7 +591,7 @@ static int remove_file_in_dir(const char *directory, const char *beginning_of_na
struct dirent* file_info;
while ((file_info = readdir(dir)) != NULL) {
if (strstr(file_info->d_name, beginning_of_name) == file_info->d_name) {
- ret = unlinkat(dir_fd, file_info->d_name, 0);
+ ret = unlinkat(dir_fd, file_info->d_name, 0) != -1;
errno_unlink = errno;
break;
}
@@ -520,9 +628,6 @@ static void launch_dbus_notify(struct crash_info *cinfo)
char pid_str[11], tid_str[11], sig_str[11];
char *prstatus_fd_str = NULL;
- char tid_comm_str[KERNEL_DEFINED_TASK_COMM_LEN + 1] = { 0, };
-
- (void)read_proc_file(cinfo->tid_info, "comm", tid_comm_str, sizeof(tid_comm_str), filter_drop_trailing_whitespace);
if (asprintf(&prstatus_fd_str, "%d", cinfo->prstatus_fd) == -1) {
_E("Unable to allocate memory: %m");
@@ -533,6 +638,8 @@ static void launch_dbus_notify(struct crash_info *cinfo)
SNPRINTF_OR_EXIT(tid, "%d");
SNPRINTF_OR_EXIT(sig, "%d");
+ char *legacy_notification_str = config.legacy_notification ? "--legacy-sig" : "";
+
char *av[] = { CRASH_NOTIFY_BIN_PATH,
"--cmdline", cinfo->cmd_line,
"--cmdpath", cinfo->cmd_path,
@@ -543,7 +650,8 @@ static void launch_dbus_notify(struct crash_info *cinfo)
"--reportpath", cinfo->result_path,
"--prstatus_fd", prstatus_fd_str,
"--signal", sig_str,
- "--tid-comm", tid_comm_str,
+ "--tid-comm", cinfo->comm,
+ legacy_notification_str,
NULL };
spawn(av, NULL, NULL, NULL, NULL);
@@ -573,6 +681,9 @@ static bool execute_minicoredump(struct crash_info *cinfo, int *exit_code)
const char *without_core_str = config.dump_core ? NULL : "-s";
+ char proc_name[PATH_MAX];
+ get_proc_name(cinfo->cmd_line, proc_name, sizeof(proc_name));
+
/* Execute minicoredumper */
char *args[] = {
MINICOREDUMPER_BIN_PATH, // minicoredumper filename path
@@ -582,7 +693,7 @@ static bool execute_minicoredump(struct crash_info *cinfo, int *exit_code)
sig_str, // %s - number of signal
time_str, // %t - time of dump
"localhost", // %h - hostname
- basename(cinfo->cmd_line), // %e - exe name (need for result filename)
+ basename(proc_name), // %e - exe name (need for result filename)
MINICOREDUMPER_CONFIG_PATH, // config file
"-d",
cinfo->pfx, // temp dir
@@ -600,12 +711,9 @@ static bool execute_minicoredump(struct crash_info *cinfo, int *exit_code)
/* Minicoredumper must be executed to dump at least PRSTATUS for
other tools, coredump, however, might have been disabled. */
if (!config.dump_core && file_exists_in_dir(cinfo->pfx, coredump_name)) {
- if (remove_file_in_dir(cinfo->pfx, coredump_name) != 0)
- _E("Saving core disabled - removing coredump %s/%s failed: %m",
- cinfo->pfx, coredump_name);
- else
- _D("Saving core disabled - removed coredump %s/%s",
- cinfo->pfx, coredump_name);
+ _E("Saving core disabled but coredump found (minicoredumper bug?). Removing coredump %s/%s", cinfo->pfx, coredump_name);
+ if (!remove_file_in_dir(cinfo->pfx, coredump_name))
+ _E("Removing coredump %s/%s failed: %m", cinfo->pfx, coredump_name);
}
out:
@@ -711,6 +819,113 @@ 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);
+ char *dst_dirname = dirname(dst_dirpath);
+ if (dst_dirpath == NULL || dst_dirname == NULL) {
+ _E("Out of memory");
+ goto out;
+ }
+
+ if (mkdir(dst_dirname, 0775) < 0 && errno != EEXIST) {
+ _E("Failed to mkdir %s: %m", dst_dirname);
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
+ goto out;
+ }
+
+ if (copy_file(dst_filepath, src_filepath)) {
+ _E("Cannot copy %s file to: %s", src_filepath, dst_filepath);
+ (void)check_disk_available(cinfo->app_root_path, SPACE_REQUIRED_KB);
+ }
+ else
+ is_ok = true;
+out:
+ free(src_filepath);
+ free(dst_filepath);
+ free(dst_dirpath);
+
+ 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);
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
+ 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;
+ }
+
+ GHashTable *app_names = get_app_name_from_map(maps_path);
+ GHashTableIter iter;
+ gpointer key;
+ g_hash_table_iter_init(&iter, app_names);
+ while (g_hash_table_iter_next(&iter, &key, NULL)) {
+ char *app_name = (char *)key;
+
+ 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 (file_exists(dst_filepath)) {
+ _W("File %s.xml already exists in report.", app_name);
+ } else {
+ if (copy_file(dst_filepath, src_filepath)) {
+ _E("Cannot copy file from %s to: %s", src_filepath, dst_filepath);
+ (void)check_disk_available(dst_dirpath, SPACE_REQUIRED_KB);
+ }
+ }
+ }
+ free(src_filepath);
+ }
+ free(dst_filepath);
+ }
+ free(app_name);
+ }
+ g_hash_table_unref(app_names);
+out:
+ free(dst_dirpath);
+}
+
static bool execute_crash_modules(struct crash_info *cinfo)
{
int exit_code = 0;
@@ -720,6 +935,7 @@ static bool execute_crash_modules(struct crash_info *cinfo)
return false;
if (!execute_livedumper(cinfo, &exit_code) || exit_code != 0) {
_E("Failed to run livedumper - can not continue");
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
process_continue(cinfo->pid_info);
return false;
}
@@ -727,28 +943,38 @@ static bool execute_crash_modules(struct crash_info *cinfo)
_I("Starting the minicoredumper");
if (!execute_minicoredump(cinfo, &exit_code) || exit_code != 0) {
_E("Failed to run minicoredumper - can not continue");
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
return false;
}
}
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);
return true;
}
-static int lock_dumpdir(void)
+static int lock_dir(const char *path, bool block)
{
+ assert(path);
+
int fd;
- if ((fd = open(crash_dump_path, O_RDONLY | O_DIRECTORY)) < 0) {
- _E("Failed to open %s: %m", crash_dump_path);
+ if ((fd = open(path, O_RDONLY | O_DIRECTORY)) == -1) {
+ _E("Failed to open %s: %m", path);
return -1;
}
- if (flock(fd, LOCK_EX) < 0) {
- _E("Failed to lock %s for exclusive access: %m", crash_dump_path);
+ int flock_flags = LOCK_EX;
+
+ if (!block)
+ flock_flags |= LOCK_NB;
+
+ if (flock(fd, flock_flags) == -1) {
+ _E("Failed to lock %s for exclusive access: %m", path);
close(fd);
return -1;
}
@@ -756,20 +982,6 @@ static int lock_dumpdir(void)
return fd;
}
-static void unlock_dumpdir(int fd)
-{
- if (flock(fd, LOCK_UN) < 0)
- _E("Failed to unlock file descriptor: %m");
- close(fd);
-}
-
-static int dump_filter(const struct dirent *de)
-{
- if (de->d_name[0] == '.')
- return 0;
- return 1;
-}
-
static int mtime_cmp(const void *_a, const void *_b)
{
const struct file_info *a = _a;
@@ -870,32 +1082,12 @@ exit:
return dump_num;
}
-static int check_disk_available(const char *path, int check_size)
-{
- struct statfs lstatfs;
- int avail_size = 0;
-
- if (!path)
- return -1;
-
- if (statfs(path, &lstatfs) < 0)
- return -1;
- avail_size = (int)(lstatfs.f_bavail * (lstatfs.f_bsize / 1024));
-
- if (check_size > avail_size) {
- _I("avail_size is (%d)", avail_size);
- return -1;
- }
-
- return 0;
-}
-
-static int remove_file_info(struct file_info file)
+static bool remove_file_info(struct file_info file)
{
if (file.isdir)
- return remove_dir(file.path, 1);
+ return remove_dir(file.path, true);
else
- return unlink(file.path);
+ return unlink(file.path) != -1;
}
static void clean_dump(void)
@@ -952,7 +1144,7 @@ static void clean_dump(void)
if (!remove_flag)
continue;
- if (remove_file_info(dump_list[i]) < 0) {
+ if (!remove_file_info(dump_list[i])) {
_E("Failed to remove %s", dump_list[i].path);
continue;
}
@@ -962,8 +1154,8 @@ static void clean_dump(void)
/* Check disk free space to keep */
if (config.system_keep_free &&
- check_disk_available(config.crash_root_path,
- config.system_keep_free) < 0) {
+ !check_disk_available(config.crash_root_path,
+ config.system_keep_free)) {
_I("Disk is not available! so set the maximum number of dump to 1");
config.max_crash_dump = 1;
}
@@ -975,55 +1167,37 @@ static void clean_dump(void)
static void compress(struct crash_info *cinfo)
{
- int ret, lock_fd;
- char zip_path[PATH_MAX];
-
- ret = snprintf(zip_path, sizeof(zip_path), "%s/report.zip",
- cinfo->temp_dir);
- if (ret < 0) {
- _E("Failed to snprintf for zip path");
- return;
- }
-
- char *args[] = {"/bin/zip", "-qyr", zip_path, cinfo->name, NULL};
+ char *args[] = {"/bin/zip", "-qyr", cinfo->zip_path, cinfo->name, NULL};
spawn_param_s param1 = { .fn = spawn_nullstdfds };
spawn_param_s param0 = { .fn = spawn_chdir, .u.char_ptr = cinfo->temp_dir, .next = &param1 };
(void)spawn_wait(args, NULL, &param0, ZIP_TIMEOUT_MS, NULL);
-
- if ((lock_fd = lock_dumpdir()) < 0)
- return;
- if (!rename(zip_path, cinfo->result_path))
- clean_dump();
- else
- _E("Failed to move %s to %s", zip_path, cinfo->result_path);
- unlock_dumpdir(lock_fd);
-
- if (remove_dir(cinfo->temp_dir, 1) < 0)
- _E("Failed to delete temp directory");
}
-static void move_dump_data(const char *from_path, const struct crash_info *cinfo)
+static bool move_dump_data(const char *from_path, const struct crash_info *cinfo)
{
int lock_fd;
+ bool is_ok = true;
- if ((lock_fd = lock_dumpdir()) < 0)
- return;
- if (!rename(from_path, cinfo->result_path))
+ if ((lock_fd = lock_dir(crash_dump_path, false)) < 0)
+ return false;
+ if (!rename(from_path, cinfo->result_path)) {
+ chmod(cinfo->result_path, DEFAULT_REPORT_PERM);
clean_dump();
- else
- _E("Failed to move %s to %s",
- from_path, cinfo->result_path);
- unlock_dumpdir(lock_fd);
+ } else {
+ _E("Failed to move %s to %s", from_path, cinfo->result_path);
+ (void)check_disk_available(crash_dump_path, SPACE_REQUIRED_KB);
+ is_ok = false;
+ }
+ unlock_dir(lock_fd);
- if (remove_dir(cinfo->temp_dir, 1) < 0)
- _E("Failed to delete temp directory");
+ return is_ok;
}
static int wait_for_opt(unsigned int timeout)
{
unsigned int count = 0;
- while (check_disk_available(config.crash_root_path, 0) < 0 && count < timeout) {
+ while (!check_disk_available(config.crash_root_path, 0) && count < timeout) {
log_kmsg("crash-manager: path %s is not available\n", config.crash_root_path);
sleep(1);
count++;
@@ -1041,12 +1215,18 @@ static void free_crash_info(struct crash_info *cinfo)
{
free(cinfo->cmd_line);
free(cinfo->cmd_path);
+ free(cinfo->comm);
free(cinfo->temp_dir);
free(cinfo->result_path);
+ free(cinfo->app_root_path);
free(cinfo->pfx);
free(cinfo->info_path);
free(cinfo->core_path);
free(cinfo->log_path);
+ free(cinfo->zip_path);
+ free(cinfo->appid);
+ free(cinfo->pkgid);
+ free(cinfo->executable_path);
}
void crash_info_init(struct crash_info *cinfo)
@@ -1058,14 +1238,38 @@ void crash_info_init(struct crash_info *cinfo)
cinfo->tid_info = -1;
cinfo->time_info = 0;
cinfo->output_path = NULL;
+ cinfo->executable_path = NULL;
cinfo->cmd_line = NULL;
cinfo->cmd_path = NULL;
+ cinfo->comm = 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;
cinfo->log_path = NULL;
+ cinfo->zip_path = NULL;
+ cinfo->appid = NULL;
+ cinfo->pkgid = NULL;
+ cinfo->lock_fd = -1;
+}
+
+static void release_crashed_process()
+{
+ /* 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);
+ _I("Released crashed process lock");
}
static bool run(struct crash_info *cinfo)
@@ -1085,53 +1289,47 @@ static bool run(struct crash_info *cinfo)
_W("Failed to call extra script from config");
}
+ _I("Creating report for pid %d, tid %d, cmdline %s, pkgid %s",
+ cinfo->pid_info, cinfo->tid_info, cinfo->cmd_line, cinfo->pkgid);
+
/* Exec crash modules */
if (!execute_crash_modules(cinfo)) {
_E("Failed to get basic crash information");
return false;
}
+ if (!cinfo->livedump && config.release_early)
+ release_crashed_process();
+
+ char *temp_report;
if (config.report_type >= REP_TYPE_FULL) {
/* Save shared objects info (file names, bulid IDs, rpm package names) */
- save_so_info(cinfo);
+ if (config.dump_so_info)
+ save_so_info(cinfo);
+ else
+ _I("Not saving .so_info (disabled in configuration)");
/* Wait misc. pids */
wait_for_pid(dump_state_pid, NULL);
if (extra_script_pid > 0)
wait_for_pid(extra_script_pid, NULL);
- /* Tar compression */
if (config.allow_zip)
compress(cinfo);
- else
- move_dump_data(cinfo->pfx, cinfo);
- } else {
- free(cinfo->result_path);
- if (asprintf(&cinfo->result_path, "%s/%s.info",
- crash_dump_path, cinfo->name) == -1) {
- cinfo->result_path = NULL;
- _E("asprintf() error: %m");
- return false;
- }
- move_dump_data(cinfo->info_path, cinfo);
- }
+
+ temp_report = config.allow_zip ? cinfo->zip_path : cinfo->pfx;
+ } else
+ temp_report = cinfo->info_path;
+
+ if (move_dump_data(temp_report, cinfo))
+ _I("Report for pid %d created at %s", cinfo->pid_info, cinfo->result_path);
if (cinfo->print_result_path)
printf("REPORT_PATH=%s\n", cinfo->result_path);
if (!cinfo->livedump) {
- /* 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);
+ if (!config.release_early)
+ release_crashed_process();
launch_dbus_notify(cinfo);
@@ -1150,6 +1348,9 @@ static bool crash_manager_prepare(struct crash_info *cinfo)
if (!config_init(&config, CRASH_MANAGER_CONFIG_PATH))
return false;
+ if (cinfo->executable_path && config_is_path_excluded(&config, cinfo->executable_path))
+ return false;
+
if (!prepare_paths(cinfo))
return false;
@@ -1163,6 +1364,10 @@ static bool crash_manager_prepare(struct crash_info *cinfo)
if (!set_crash_info(cinfo))
return false;
+ cinfo->lock_fd = lock_dir(cinfo->temp_dir, true);
+ if (cinfo->lock_fd == -1)
+ return false;
+
return true;
}
@@ -1178,6 +1383,17 @@ static void write_dump_reason(const char *reason, const char *base_dir, const ch
}
}
+static void crash_manager_cleanup(struct crash_info *cinfo)
+{
+ assert(cinfo);
+ unlock_dir(cinfo->lock_fd);
+
+ if (!remove_dir(cinfo->temp_dir, true))
+ _E("Failed to delete temp directory: %s", cinfo->temp_dir);
+
+ clean_temp(crash_temp_path);
+}
+
void crash_manager_free(struct crash_info *cinfo)
{
if (cinfo->prstatus_fd >= 0)
@@ -1194,7 +1410,10 @@ bool crash_manager_direct(struct crash_info *cinfo)
if (!crash_manager_prepare(cinfo))
return false;
- return run(cinfo);
+ bool result = run(cinfo);
+ crash_manager_cleanup(cinfo);
+
+ return result;
}
bool crash_manager_livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len)
@@ -1211,7 +1430,10 @@ bool crash_manager_livedump_pid(pid_t pid, const char *dump_reason, char *report
write_dump_reason(dump_reason, cinfo.pfx, cinfo.name);
- if (!run(&cinfo))
+ result = run(&cinfo);
+ crash_manager_cleanup(&cinfo);
+
+ if (!result)
goto exit;
strncpy(report_path, cinfo.result_path, report_path_len);
diff --git a/src/crash-manager/crash-manager.conf b/src/crash-manager/crash-manager.conf
index c485527..d1f58af 100644
--- a/src/crash-manager/crash-manager.conf
+++ b/src/crash-manager/crash-manager.conf
@@ -5,6 +5,14 @@ MaxRetentionSec=0
MaxCrashDump=0
AllowZip=yes
+# Release process before report completion (default - no)
+# This option determines whether the crashing process should be released
+# immediately after reading the necessary data from /proc/<PID>/ to allow the
+# process to be cleaned up. This is important for VIP processes because if they
+# are cleaned up too early, the device will be rebooted before the full report
+# is written.
+# ReleaseProcessLockEarly=no
+
# Crash report path must exist for the reports to be created
# CrashRootPath=/usr/opt/share/crash/
@@ -15,7 +23,37 @@ AllowZip=yes
# This option applies to ReportType=FULL only!
# DumpCore=1
+# DumpSharedObjectInfo - 1 to enable (default), 0 to disable
+# This option controls creation of .so_info file
+#
+# Note! When set to 0 report will not include information about packages that were
+# mapped into process memory. This information is normally needed to re-create
+# sysroot for the use with debugger.
+#
+# DumpSharedObjectInfo=1
+
+# Use Legacy ProcessCrashed DBus signal
+# When '0' (default), crash worker emits new-style signal with extensive data:
+# 1. cmd name,
+# 2. cmd path,
+# 3. appid,
+# 4. pkgid,
+# 5. report path,
+# 6. pid,
+# 7. tid,
+# 8. array of str->variant with additional data
+# When '1' (legacy), signal signature is limited to fields 1-4 (cmd name, path, app/pkgid).
+# The purpose of this is option is to support software still depending on legacy style.
+# UseLegacyNotification=0
+
# Extra script to run whose output will be attached to generated report
# Script will be called with two arguments, in pseudo-code:
# sh -c "$ExtraScript /path/to/report/temp/directory PID"
# ExtraScript=/path/to/script
+
+[ExcludePaths]
+# List of executables that should be excluded from crash dump
+# One line per entry, full path to *executable* needed, ie.
+# - specify /usr/bin/sleep NOT /bin/sleep,
+# - specify /usr/bin/bash, NOT /bin/sh
+# NameNotImportant=/usr/bin/daemon-with-sensitive-information
diff --git a/src/crash-manager/crash-manager.conf.d.example b/src/crash-manager/crash-manager.conf.d.example
new file mode 100644
index 0000000..b50dbff
--- /dev/null
+++ b/src/crash-manager/crash-manager.conf.d.example
@@ -0,0 +1,3 @@
+# Rename this file to end with .conf for it to be read by crash-manager
+[CrashManager]
+DumpCore=0
diff --git a/src/crash-manager/crash-manager.h b/src/crash-manager/crash-manager.h
index 7c102bc..bd4f85b 100644
--- a/src/crash-manager/crash-manager.h
+++ b/src/crash-manager/crash-manager.h
@@ -23,41 +23,41 @@
#include <unistd.h>
#include <stdbool.h>
-#define APPID_MAX 128
-#define PKGNAME_MAX 128
-
/* Paths and variables */
struct crash_info {
+ bool livedump;
+ bool kill;
+ bool print_result_path;
pid_t pid_info;
pid_t tid_info;
int uid_info;
int gid_info;
int sig_info;
+ int prstatus_fd;
char *cmd_line;
char *cmd_path;
- time_t time_info;
+ char *comm;
char *temp_dir;
char *name;
+ char *app_root_path;
char *result_path;
char *pfx;
char *info_path;
char *core_path;
char *log_path;
- char appid[APPID_MAX];
- char pkgid[PKGNAME_MAX];
+ char *zip_path;
char *output_path;
- bool livedump;
- bool kill;
- bool print_result_path;
-#ifdef SYS_ASSERT
- char *sysassert_cs_path;
- bool have_sysassert_report;
-#endif
- int prstatus_fd;
+ char *executable_path;
+ char *appid;
+ char *pkgid;
+ time_t time_info;
+ int lock_fd;
};
bool crash_manager_direct(struct crash_info *cinfo);
bool crash_manager_livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len);
void crash_info_init(struct crash_info *cinfo);
void crash_manager_free(struct crash_info *cinfo);
+
+bool have_livecoredumper(void);
#endif
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/dbus_notify.c b/src/crash-manager/dbus_notify.c
index 0254092..ca010e5 100644
--- a/src/crash-manager/dbus_notify.c
+++ b/src/crash-manager/dbus_notify.c
@@ -51,6 +51,7 @@ struct RegInfo {
};
struct NotifyParams {
+ bool legacy_notification;
int prstatus_fd;
pid_t pid;
pid_t tid;
@@ -148,10 +149,16 @@ strdup_error:
goto out;
}
-static GVariant* build_message_data(const struct NotifyParams *notify_params)
+static GVariant *build_legacy_message_data(const struct NotifyParams *notify_params)
{
- if (notify_params == NULL)
- return NULL;
+ assert(notify_params);
+
+ return g_variant_new("(ssss)", notify_params->cmd_name, notify_params->cmd_path, notify_params->appid, notify_params->pkgid);
+}
+
+static GVariant *build_message_data(const struct NotifyParams *notify_params)
+{
+ assert(notify_params);
GVariantBuilder md_builder;
g_variant_builder_init(&md_builder, G_VARIANT_TYPE("(sssssiia{sv})"));
@@ -209,7 +216,9 @@ static bool send_notify(GDBusConnection *conn, const struct NotifyParams *notify
int result = false;
GError *error = NULL;
- GVariant *data = build_message_data(notify_params);
+ GVariant *data = notify_params->legacy_notification
+ ? build_legacy_message_data(notify_params)
+ : build_message_data(notify_params);
if (data == NULL) {
_E("Error while preparing parameters");
goto out;
@@ -256,6 +265,7 @@ static bool parse_cmdline(int ac, char *av[], struct NotifyParams *params)
FLAG_PRSTATUS_FD,
FLAG_SIGNAL,
FLAG_TID_COMM,
+ FLAG_LEGACY_NOTIFICATION,
};
static const struct option options[] = {
{ .name = "cmdline", .has_arg = required_argument, .flag = NULL, .val = FLAG_CMDLINE },
@@ -268,6 +278,7 @@ static bool parse_cmdline(int ac, char *av[], struct NotifyParams *params)
{ .name = "prstatus_fd", .has_arg = required_argument, .flag = NULL, .val = FLAG_PRSTATUS_FD },
{ .name = "signal", .has_arg = required_argument, .flag = NULL, .val = FLAG_SIGNAL },
{ .name = "tid-comm", .has_arg = required_argument, .flag = NULL, .val = FLAG_TID_COMM },
+ { .name = "legacy-sig", .has_arg = no_argument, .flag = NULL, .val = FLAG_LEGACY_NOTIFICATION },
{ NULL },
};
@@ -295,6 +306,8 @@ static bool parse_cmdline(int ac, char *av[], struct NotifyParams *params)
params->signal = atoi(optarg);
else if (FLAG_TID_COMM == val)
params->tid_comm = optarg;
+ else if (FLAG_LEGACY_NOTIFICATION == val)
+ params->legacy_notification = true;
} while (val != -1);
return params->cmd_name && params->cmd_path && params->appid && params->pkgid && params->prstatus_fd > 0;
@@ -304,7 +317,7 @@ static void usage(const char *const progname)
{
assert(progname);
- printf("%s --prstatus_fd N --pid PID --tid TID --cmdline CMDLINE --cmdpath CMDPATH --appid APPID --pkgid PKGID --signal SIGNALNR\n", progname);
+ printf("%s --prstatus_fd N --pid PID --tid TID --cmdline CMDLINE --cmdpath CMDPATH --appid APPID --pkgid PKGID --signal SIGNALNR [--legacy-sig]\n", progname);
}
int main(int ac, char *av[])
diff --git a/src/crash-manager/main.c b/src/crash-manager/main.c
index 53211e8..994747c 100644
--- a/src/crash-manager/main.c
+++ b/src/crash-manager/main.c
@@ -1,9 +1,20 @@
#include <getopt.h>
+#include <grp.h>
+#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/capability.h>
+#include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include "shared/log.h"
+#include "shared/util.h"
#include "crash-manager.h"
+#define USER_NAME "crash_worker"
+
static void print_help(const char *name)
{
printf("Syntax: %s [OPTIONS]\n"
@@ -18,6 +29,7 @@ static void print_help(const char *name)
" -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"
+ " -E --executable-path path to executable that crashed\n"
" -h --help this message\n"
"\n"
"for --live option only --pid is required\n"
@@ -57,9 +69,10 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[])
{"print", no_argument, NULL, 'r'},
{"output", required_argument, NULL, 'o'},
{"help", no_argument, NULL, 'h'},
+ {"executable-path", required_argument, NULL, 'E'},
};
- while ((opt = getopt_long(argc, argv, "p:u:g:i:s:t:hlkro:", long_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "p:u:g:i:s:t:hlkro:E:", long_options, NULL)) != -1) {
switch (opt) {
case 'p':
GET_NUMBER(pid);
@@ -96,6 +109,14 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[])
cinfo->output_path = optarg;
_D("output path: %s\n", optarg);
break;
+ case 'E':
+ cinfo->executable_path = strdup(optarg);
+ if (!cinfo->executable_path)
+ return false;
+
+ kernel_exe_path_normalize(cinfo->executable_path);
+ _D("executable path: %s\n", cinfo->executable_path);
+ break;
case 'h':
default:
print_help(argv[0]);
@@ -103,6 +124,11 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[])
}
}
+ if (cinfo->livedump && !have_livecoredumper()) {
+ printf("livecoredumper not available - can not perform livedump.\n");
+ return false;
+ }
+
if (!pid_set || (!cinfo->livedump && (!gid_set || !uid_set || !sig_set))) {
printf("Not enough parameters.\n\n");
print_help(argv[0]);
@@ -124,9 +150,126 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[])
#undef GET_NUMBER
}
+static bool set_caps(const cap_flag_t flag)
+{
+ bool res = false;
+ cap_t caps;
+ cap_value_t cap_list[5] = {
+ CAP_DAC_READ_SEARCH,
+ CAP_DAC_OVERRIDE,
+ CAP_KILL,
+ CAP_SYS_PTRACE,
+ CAP_SYSLOG
+ };
+
+ caps = cap_get_proc();
+ if (caps == NULL) {
+ _E("cap_get_proc() error: %m");
+ goto exit;
+ }
+
+ if (cap_set_flag(caps, flag, ARRAY_SIZE(cap_list), cap_list, CAP_SET) == -1) {
+ _E("cap_set_flag() error: %m");
+ goto exit;
+ }
+
+ if (cap_set_proc(caps) == -1) {
+ _E("cap_set_proc() error: %m");
+ goto exit;
+ }
+
+ res = true;
+exit:
+ if (caps != NULL && cap_free(caps) == -1) {
+ _E("cap_free() error: %m");
+ res = false;
+ }
+ return res;
+}
+
+static bool set_groups(const char *user_name, const gid_t gid)
+{
+ int ngroup = 0;
+ errno = 0;
+ int ret = getgrouplist(user_name, gid, NULL, &ngroup);
+ if (ret != -1) {
+ _E("getgrouplist() unexpected return value: %d", ret);
+ return false;
+ } else if (errno != 0) {
+ _E("getgrouplist() unexcepted failure: %m");
+ return false;
+ }
+
+ gid_t groups[ngroup];
+ ret = getgrouplist(user_name, gid, groups, &ngroup);
+ if (ret == -1) {
+ _E("getgrouplist() error");
+ return false;
+ }
+
+ ret = setgroups(ngroup, groups);
+ if (ret != 0) {
+ _E("setgroups() error: %m\n");
+ return false;
+ }
+
+ return true;
+}
+
+static bool drop_privileges(const char *user_name)
+{
+ struct passwd *user_info = getpwnam(user_name);
+ if (!user_info) {
+ _E("getpwnam() error: %m");
+ return false;
+ }
+
+ if (!set_caps(CAP_PERMITTED))
+ return false;
+
+ /*
+ * setuid() clears capabilities, so we need to set PR_SET_KEEPCAPS and
+ * restore them after that
+ */
+ if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) {
+ _E("prctl(PR_SET_KEEPCAPS) error: %m");
+ return false;
+ }
+
+ if (!set_groups(user_name, user_info->pw_gid))
+ return false;
+
+ if (setgid(user_info->pw_gid) == -1) {
+ _E("setgid() error: %m\n");
+ return false;
+ }
+
+ if (setuid(user_info->pw_uid) == -1) {
+ _E("setuid() error: %m\n");
+ return false;
+ }
+
+ if (!set_caps(CAP_EFFECTIVE))
+ return false;
+
+ if (!set_caps(CAP_INHERITABLE))
+ return false;
+
+ return true;
+}
int main(int argc, char *argv[])
{
+ int res;
+
+ /* Have consinsent umask across invocations - from shell, crash-service, kernel */
+ umask(DEFAULT_UMASK);
+
+ if (!drop_privileges(USER_NAME)) {
+ res = EXIT_FAILURE;
+ goto exit;
+ }
+
struct crash_info cinfo;
/*
@@ -141,9 +284,10 @@ int main(int argc, char *argv[])
if (!parse_args(&cinfo, argc, argv))
return EXIT_FAILURE;
- int res = crash_manager_direct(&cinfo) ? EXIT_SUCCESS : EXIT_FAILURE;
+ res = crash_manager_direct(&cinfo) ? EXIT_SUCCESS : EXIT_FAILURE;
crash_manager_free(&cinfo);
+exit:
_I("Exiting with exit code %d", res);
return res;
}
diff --git a/src/crash-manager/so-info.c b/src/crash-manager/so-info.c
index b449791..410c6a7 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"
@@ -85,13 +88,13 @@ static unsigned char *map_file(const char *filename, int64_t *size)
static Elf##bits##_Off build_id_section_address##bits(const unsigned char *mapped_file, const int64_t size)\
{\
if (mapped_file <= 0)\
- return -1;\
+ return 0;\
\
Elf##bits##_Ehdr *elheader = (Elf##bits##_Ehdr*)mapped_file;\
Elf##bits##_Shdr *sec = (Elf##bits##_Shdr*)(mapped_file + elheader->e_shoff);\
\
if (size < (intptr_t)sec + elheader->e_shstrndx*sizeof(Elf##bits##_Shdr) - (intptr_t)mapped_file)\
- return -2;\
+ return 0;\
\
char *names = (char *)(mapped_file + sec[elheader->e_shstrndx].sh_offset);\
\
@@ -102,7 +105,7 @@ static Elf##bits##_Off build_id_section_address##bits(const unsigned char *mappe
return sec[i].sh_offset;\
} \
\
- return -1;\
+ return 0;\
} \
DECLARE_BUILD_ID_SECTION_ADDRESS(32)
@@ -157,10 +160,12 @@ static int get_build_id(char *filename, char **build_id)
if (mapped_file > 0) {
Elf64_Off offset = build_id_section_address(mapped_file, size);
- if (offset > 0)
+ if (offset > 0) {
ret = get_build_id_from(mapped_file, offset, build_id);
- else
+ } else {
+ _W("File %s doesn't contain build-id", filename);
ret = -1;
+ }
munmap(mapped_file, size);
} else {
@@ -169,12 +174,20 @@ static int get_build_id(char *filename, char **build_id)
return ret;
}
-static int get_perms(char *line, char *perms)
+enum Perms {
+ PERM_READ = 1,
+ PERM_WRITE = 2,
+ PERM_EXEC = 4
+};
+
+/* Parses beginning of the maps file in the form: `addr1-addr2 r-xp size ...` */
+static int get_perms(char *line, enum Perms *perms)
{
char *first_space = strchr(line, ' ');
- if (first_space > 0) {
- strncpy(perms, first_space+1, 4);
+ if (first_space != 0 && strlen(first_space) > 4 /* eg. " r-xp" from example above */) {
+ char *p = first_space + 1;
+ *perms = (p[0] == 'r' ? PERM_READ : 0) | (p[1] == 'w' ? PERM_WRITE : 0) | (p[2] == 'x' ? PERM_EXEC : 0);
return 0;
} else
return -1;
@@ -186,17 +199,36 @@ static int get_perms(char *line, char *perms)
*/
static char *get_exe_filename(char *line)
{
- char perms[4];
+ enum Perms perms;
- if (get_perms(line, perms) == 0 && perms[2] == 'x') {
+ if (get_perms(line, &perms) == 0) {
char *p = strstr(line, " /");
- if (p > 0)
- return p+1;
+ if (p == NULL)
+ return NULL;
+
+ char *path = p + 1;
+
+ if ((perms & PERM_EXEC) ||
+ is_dotnet_file(path))
+ return path;
}
return NULL;
}
-GSList* get_filepaths(char *map_path)
+bool list_contains_string(GSList *list, const char *string, const size_t max_len)
+{
+ if (list == NULL || string == NULL)
+ return false;
+
+ for (GSList *iterator = list; iterator; iterator = iterator->next) {
+ if (strncmp((char*)iterator->data, string, max_len) == 0)
+ return true;
+ }
+
+ return false;
+}
+
+GSList *get_filepaths(char *map_path)
{
char *line = NULL;
size_t len = 0;
@@ -223,7 +255,10 @@ GSList* get_filepaths(char *map_path)
snprintf(file_name, n+1, "%s", exe_filename);
- file_list = g_slist_append(file_list, file_name);
+ if (!list_contains_string(file_list, file_name, PATH_MAX))
+ file_list = g_slist_append(file_list, file_name);
+ else
+ free(file_name);
}
}
@@ -252,7 +287,7 @@ void free_rpm(rpmts ts)
}
}
-char* get_rpm_info_as_string_for_pkgname(Header h, const char *pkg_name)
+char *get_rpm_info_as_string_for_pkgname(Header h, const char *pkg_name)
{
char *result = NULL;
@@ -268,13 +303,13 @@ char* get_rpm_info_as_string_for_pkgname(Header h, const char *pkg_name)
return result;
}
-char* get_rpm_info_as_string(Header h)
+char *get_rpm_info_as_string(Header h)
{
const char *name = headerGetString(h, RPMTAG_NAME);
return get_rpm_info_as_string_for_pkgname(h, name);
}
-char* get_rpm_info(rpmts ts, const char* filename)
+char *get_rpm_info(rpmts ts, const char* filename)
{
char *rpm_info = NULL;
@@ -283,7 +318,7 @@ char* get_rpm_info(rpmts ts, const char* filename)
rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_INSTFILENAMES, filename, 0);
if (mi == NULL) {
- _E("Not found RPM package for %s\n", filename);
+ _W("Not found RPM package for %s\n", filename);
return NULL;
}
@@ -347,10 +382,12 @@ void search_for_tpk(rpmts ts, GSList *pkgs)
rpmdbFreeIterator(mi);
}
-char* get_app_name_from_path(const char *file_path)
+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)
@@ -365,6 +402,89 @@ char* get_app_name_from_path(const char *file_path)
return NULL;
}
+GHashTable *get_app_name_from_map(char *map_path)
+{
+ GHashTable *app_names = g_hash_table_new(g_str_hash, g_str_equal);
+ 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) {
+ if (!g_hash_table_lookup(app_names, app_name))
+ g_hash_table_add(app_names, app_name);
+ else
+ free(app_name);
+ }
+ free(iterator->data);
+ }
+ g_slist_free(file_list);
+ return app_names;
+}
+
+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);
+ char tmp_dir_name[PATH_MAX];
+
+ if (!file_exists_in_dir(dir_name, dll_name)) {
+ 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");
@@ -380,10 +500,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 (get_build_id(file_path, &build_id) <= 0 || build_id == NULL)
+
+ if (is_dotnet_file(file_path)) {
+ build_id = strdup("");
+ 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) {
@@ -401,6 +527,11 @@ void get_and_save_so_info(char *map_path, char *out_path)
break;
}
ri->app_name = get_app_name_from_path(file_path);
+ if (ri->app_name == NULL) {
+ free(ri);
+ free(build_id);
+ continue;
+ }
ri->build_id = build_id;
ri->rpm_info = NULL;
pkgs_not_found = g_slist_append(pkgs_not_found, ri);
diff --git a/src/crash-manager/so-info.h b/src/crash-manager/so-info.h
index 0b28770..474a47c 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);
-
+GHashTable *get_app_name_from_map(char *map_path);
#endif
diff --git a/src/crash-service/crash-service.c b/src/crash-service/crash-service.c
index 7b0a798..ad0655e 100644
--- a/src/crash-service/crash-service.c
+++ b/src/crash-service/crash-service.c
@@ -20,6 +20,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <sys/select.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -315,6 +316,14 @@ static bool dbus_init(void)
int main(void)
{
+ /* Have consinsent umask across invocations - from shell, crash-service, kernel */
+ umask(DEFAULT_UMASK);
+
+ if (!have_livecoredumper()) {
+ _E("livecoredumper not available - can not provide livedump API. Terminating.\n");
+ return EXIT_FAILURE;
+ }
+
loop = g_main_loop_new(NULL, false);
if (!dbus_init()) {
diff --git a/src/crash-service/crash-service.conf b/src/crash-service/crash-service.conf
index 904d93a..ef030b5 100644
--- a/src/crash-service/crash-service.conf
+++ b/src/crash-service/crash-service.conf
@@ -7,8 +7,23 @@
send_interface="org.tizen.system.crash.livedump"
send_member="livedump_pid"/>
</policy>
+ <policy user="crash_worker">
+ <allow own="org.tizen.system.crash.livedump"/>
+ <allow send_destination="org.tizen.system.crash.livedump"
+ send_interface="org.tizen.system.crash.livedump"
+ send_member="livedump_pid"/>
+ </policy>
+ <policy user="stability_monitor">
+ <allow send_destination="org.tizen.system.crash.livedump"
+ send_interface="org.tizen.system.crash.livedump"
+ send_member="livedump_pid"/>
+ </policy>
<policy context="default">
<deny own="org.tizen.system.crash.livedump"/>
<deny send_destination="org.tizen.system.crash.livedump"/>
+ <check privilege="http://tizen.org/privilege/internal/livecoredump"
+ send_destination="org.tizen.system.crash.livedump"
+ send_interface="org.tizen.system.crash.livedump"
+ send_member="livedump_pid"/>
</policy>
</busconfig>
diff --git a/src/crash-service/crash-service.service.m4 b/src/crash-service/crash-service.service.m4
index f080f40..b4221fd 100644
--- a/src/crash-service/crash-service.service.m4
+++ b/src/crash-service/crash-service.service.m4
@@ -3,8 +3,13 @@ Description=crash service
[Service]
Type=dbus
+User=crash_worker
+Group=crash_worker
+Capabilities=cap_dac_override,cap_dac_read_search,cap_sys_ptrace,cap_kill,cap_syslog=i
+SecureBits=keep-caps
BusName=org.tizen.system.crash.livedump
ExecStart=/usr/bin/crash-service
+SupplementaryGroups=log systemd-journal system_share
SmackProcessLabel=System
Nice=-5
KillMode=mixed
diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c
index 0445d9c..cd9138b 100644
--- a/src/crash-stack/crash-stack.c
+++ b/src/crash-stack/crash-stack.c
@@ -377,9 +377,11 @@ static struct addr_node *get_addr_list_from_maps(int fd)
if (result < 0)
continue;
perm[PERM_LEN] = 0;
+
/* rwxp */
if ((perm[2] == 'x' && path[0] == '/') ||
- (perm[1] == 'w' && path[0] != '/')) {
+ (perm[1] == 'w' && path[0] != '/') ||
+ is_dotnet_file(path)) {
char* addr2 = strchr(addr, '-');
if (addr2 == NULL) {
_E("Not found '-' in addr: %s", addr);
diff --git a/src/crash-stack/dwarf.h b/src/crash-stack/dwarf.h
new file mode 100644
index 0000000..8f37335
--- /dev/null
+++ b/src/crash-stack/dwarf.h
@@ -0,0 +1,652 @@
+/*-
+ * Copyright (c) 2007 John Birrell (jb@freebsd.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: dwarf.h 3749 2019-06-28 01:10:44Z emaste $
+ */
+
+#ifndef _DWARF_H_
+#define _DWARF_H_
+
+#define DW_TAG_array_type 0x01
+#define DW_TAG_class_type 0x02
+#define DW_TAG_entry_point 0x03
+#define DW_TAG_enumeration_type 0x04
+#define DW_TAG_formal_parameter 0x05
+#define DW_TAG_imported_declaration 0x08
+#define DW_TAG_label 0x0a
+#define DW_TAG_lexical_block 0x0b
+#define DW_TAG_member 0x0d
+#define DW_TAG_pointer_type 0x0f
+#define DW_TAG_reference_type 0x10
+#define DW_TAG_compile_unit 0x11
+#define DW_TAG_string_type 0x12
+#define DW_TAG_structure_type 0x13
+#define DW_TAG_subroutine_type 0x15
+#define DW_TAG_typedef 0x16
+#define DW_TAG_union_type 0x17
+#define DW_TAG_unspecified_parameters 0x18
+#define DW_TAG_variant 0x19
+#define DW_TAG_common_block 0x1a
+#define DW_TAG_common_inclusion 0x1b
+#define DW_TAG_inheritance 0x1c
+#define DW_TAG_inlined_subroutine 0x1d
+#define DW_TAG_module 0x1e
+#define DW_TAG_ptr_to_member_type 0x1f
+#define DW_TAG_set_type 0x20
+#define DW_TAG_subrange_type 0x21
+#define DW_TAG_with_stmt 0x22
+#define DW_TAG_access_declaration 0x23
+#define DW_TAG_base_type 0x24
+#define DW_TAG_catch_block 0x25
+#define DW_TAG_const_type 0x26
+#define DW_TAG_constant 0x27
+#define DW_TAG_enumerator 0x28
+#define DW_TAG_friend 0x2a
+#define DW_TAG_namelist 0x2b
+#define DW_TAG_namelist_item 0x2c
+#define DW_TAG_packed_type 0x2d
+#define DW_TAG_subprogram 0x2e
+#define DW_TAG_template_type_parameter 0x2f
+#define DW_TAG_template_type_param 0x2f
+#define DW_TAG_template_value_parameter 0x30
+#define DW_TAG_template_value_param 0x30
+#define DW_TAG_thrown_type 0x31
+#define DW_TAG_try_block 0x32
+#define DW_TAG_variant_part 0x33
+#define DW_TAG_variable 0x34
+#define DW_TAG_volatile_type 0x35
+#define DW_TAG_dwarf_procedure 0x36
+#define DW_TAG_restrict_type 0x37
+#define DW_TAG_interface_type 0x38
+#define DW_TAG_namespace 0x39
+#define DW_TAG_imported_module 0x3a
+#define DW_TAG_unspecified_type 0x3b
+#define DW_TAG_partial_unit 0x3c
+#define DW_TAG_imported_unit 0x3d
+#define DW_TAG_condition 0x3f
+#define DW_TAG_shared_type 0x40
+#define DW_TAG_type_unit 0x41
+#define DW_TAG_rvalue_reference_type 0x42
+#define DW_TAG_template_alias 0x43
+#define DW_TAG_lo_user 0x4080
+#define DW_TAG_hi_user 0xffff
+
+/* GNU extensions. */
+#define DW_TAG_format_label 0x4101
+#define DW_TAG_function_template 0x4102
+#define DW_TAG_class_template 0x4103
+#define DW_TAG_GNU_BINCL 0x4104
+#define DW_TAG_GNU_EINCL 0x4105
+#define DW_TAG_GNU_template_template_parameter 0x4106
+#define DW_TAG_GNU_template_template_param 0x4106
+#define DW_TAG_GNU_template_parameter_pack 0x4107
+#define DW_TAG_GNU_formal_parameter_pack 0x4108
+#define DW_TAG_GNU_call_site 0x4109
+#define DW_TAG_GNU_call_site_parameter 0x410a
+
+#define DW_CHILDREN_no 0x00
+#define DW_CHILDREN_yes 0x01
+
+#define DW_AT_sibling 0x01
+#define DW_AT_location 0x02
+#define DW_AT_name 0x03
+#define DW_AT_ordering 0x09
+#define DW_AT_subscr_data 0x0a
+#define DW_AT_byte_size 0x0b
+#define DW_AT_bit_offset 0x0c
+#define DW_AT_bit_size 0x0d
+#define DW_AT_element_list 0x0f
+#define DW_AT_stmt_list 0x10
+#define DW_AT_low_pc 0x11
+#define DW_AT_high_pc 0x12
+#define DW_AT_language 0x13
+#define DW_AT_member 0x14
+#define DW_AT_discr 0x15
+#define DW_AT_discr_value 0x16
+#define DW_AT_visibility 0x17
+#define DW_AT_import 0x18
+#define DW_AT_string_length 0x19
+#define DW_AT_common_reference 0x1a
+#define DW_AT_comp_dir 0x1b
+#define DW_AT_const_value 0x1c
+#define DW_AT_containing_type 0x1d
+#define DW_AT_default_value 0x1e
+#define DW_AT_inline 0x20
+#define DW_AT_is_optional 0x21
+#define DW_AT_lower_bound 0x22
+#define DW_AT_producer 0x25
+#define DW_AT_prototyped 0x27
+#define DW_AT_return_addr 0x2a
+#define DW_AT_start_scope 0x2c
+#define DW_AT_bit_stride 0x2e
+#define DW_AT_stride_size 0x2e
+#define DW_AT_upper_bound 0x2f
+#define DW_AT_abstract_origin 0x31
+#define DW_AT_accessibility 0x32
+#define DW_AT_address_class 0x33
+#define DW_AT_artificial 0x34
+#define DW_AT_base_types 0x35
+#define DW_AT_calling_convention 0x36
+#define DW_AT_count 0x37
+#define DW_AT_data_member_location 0x38
+#define DW_AT_decl_column 0x39
+#define DW_AT_decl_file 0x3a
+#define DW_AT_decl_line 0x3b
+#define DW_AT_declaration 0x3c
+#define DW_AT_discr_list 0x3d
+#define DW_AT_encoding 0x3e
+#define DW_AT_external 0x3f
+#define DW_AT_frame_base 0x40
+#define DW_AT_friend 0x41
+#define DW_AT_identifier_case 0x42
+#define DW_AT_macro_info 0x43
+#define DW_AT_namelist_item 0x44
+#define DW_AT_priority 0x45
+#define DW_AT_segment 0x46
+#define DW_AT_specification 0x47
+#define DW_AT_static_link 0x48
+#define DW_AT_type 0x49
+#define DW_AT_use_location 0x4a
+#define DW_AT_variable_parameter 0x4b
+#define DW_AT_virtuality 0x4c
+#define DW_AT_vtable_elem_location 0x4d
+#define DW_AT_allocated 0x4e
+#define DW_AT_associated 0x4f
+#define DW_AT_data_location 0x50
+#define DW_AT_byte_stride 0x51
+#define DW_AT_entry_pc 0x52
+#define DW_AT_use_UTF8 0x53
+#define DW_AT_extension 0x54
+#define DW_AT_ranges 0x55
+#define DW_AT_trampoline 0x56
+#define DW_AT_call_column 0x57
+#define DW_AT_call_file 0x58
+#define DW_AT_call_line 0x59
+#define DW_AT_description 0x5a
+#define DW_AT_binary_scale 0x5b
+#define DW_AT_decimal_scale 0x5c
+#define DW_AT_small 0x5d
+#define DW_AT_decimal_sign 0x5e
+#define DW_AT_digit_count 0x5f
+#define DW_AT_picture_string 0x60
+#define DW_AT_mutable 0x61
+#define DW_AT_threads_scaled 0x62
+#define DW_AT_explicit 0x63
+#define DW_AT_object_pointer 0x64
+#define DW_AT_endianity 0x65
+#define DW_AT_elemental 0x66
+#define DW_AT_pure 0x67
+#define DW_AT_recursive 0x68
+#define DW_AT_signature 0x69
+#define DW_AT_main_subprogram 0x6a
+#define DW_AT_data_bit_offset 0x6b
+#define DW_AT_const_expr 0x6c
+#define DW_AT_enum_class 0x6d
+#define DW_AT_linkage_name 0x6e
+#define DW_AT_lo_user 0x2000
+#define DW_AT_hi_user 0x3fff
+
+/* SGI/MIPS extensions. */
+#define DW_AT_MIPS_fde 0x2001
+#define DW_AT_MIPS_loop_begin 0x2002
+#define DW_AT_MIPS_tail_loop_begin 0x2003
+#define DW_AT_MIPS_epilog_begin 0x2004
+#define DW_AT_MIPS_loop_unroll_factor 0x2005
+#define DW_AT_MIPS_software_pipeline_depth 0x2006
+#define DW_AT_MIPS_linkage_name 0x2007
+#define DW_AT_MIPS_stride 0x2008
+#define DW_AT_MIPS_abstract_name 0x2009
+#define DW_AT_MIPS_clone_origin 0x200a
+#define DW_AT_MIPS_has_inlines 0x200b
+#define DW_AT_MIPS_stride_byte 0x200c
+#define DW_AT_MIPS_stride_elem 0x200d
+#define DW_AT_MIPS_ptr_dopetype 0x200e
+#define DW_AT_MIPS_allocatable_dopetype 0x200f
+#define DW_AT_MIPS_assumed_shape_dopetype 0x2010
+#define DW_AT_MIPS_assumed_size 0x2011
+
+/* GNU extensions. */
+#define DW_AT_sf_names 0x2101
+#define DW_AT_src_info 0x2102
+#define DW_AT_mac_info 0x2103
+#define DW_AT_src_coords 0x2104
+#define DW_AT_body_begin 0x2105
+#define DW_AT_body_end 0x2106
+#define DW_AT_GNU_vector 0x2107
+#define DW_AT_GNU_guarded_by 0x2108
+#define DW_AT_GNU_pt_guarded_by 0x2109
+#define DW_AT_GNU_guarded 0x210a
+#define DW_AT_GNU_pt_guarded 0x210b
+#define DW_AT_GNU_locks_excluded 0x210c
+#define DW_AT_GNU_exclusive_locks_required 0x210d
+#define DW_AT_GNU_shared_locks_required 0x210e
+#define DW_AT_GNU_odr_signature 0x210f
+#define DW_AT_GNU_template_name 0x2110
+#define DW_AT_GNU_call_site_value 0x2111
+#define DW_AT_GNU_call_site_data_value 0x2112
+#define DW_AT_GNU_call_site_target 0x2113
+#define DW_AT_GNU_call_site_target_clobbered 0x2114
+#define DW_AT_GNU_tail_call 0x2115
+#define DW_AT_GNU_all_tail_call_sites 0x2116
+#define DW_AT_GNU_all_call_sites 0x2117
+#define DW_AT_GNU_all_source_call_sites 0x2118
+
+/* Apple extensions. */
+#define DW_AT_APPLE_optimized 0x3fe1
+#define DW_AT_APPLE_flags 0x3fe2
+#define DW_AT_APPLE_isa 0x3fe3
+#define DW_AT_APPLE_block 0x3fe4
+#define DW_AT_APPLE_major_runtime_vers 0x3fe5
+#define DW_AT_APPLE_runtime_class 0x3fe6
+#define DW_AT_APPLE_omit_frame_ptr 0x3fe7
+#define DW_AT_APPLE_property_name 0x3fe8
+#define DW_AT_APPLE_property_getter 0x3fe9
+#define DW_AT_APPLE_property_setter 0x3fea
+#define DW_AT_APPLE_property_attribute 0x3feb
+#define DW_AT_APPLE_objc_complete_type 0x3fec
+#define DW_AT_APPLE_property 0x3fed
+
+#define DW_FORM_addr 0x01
+#define DW_FORM_block2 0x03
+#define DW_FORM_block4 0x04
+#define DW_FORM_data2 0x05
+#define DW_FORM_data4 0x06
+#define DW_FORM_data8 0x07
+#define DW_FORM_string 0x08
+#define DW_FORM_block 0x09
+#define DW_FORM_block1 0x0a
+#define DW_FORM_data1 0x0b
+#define DW_FORM_flag 0x0c
+#define DW_FORM_sdata 0x0d
+#define DW_FORM_strp 0x0e
+#define DW_FORM_udata 0x0f
+#define DW_FORM_ref_addr 0x10
+#define DW_FORM_ref1 0x11
+#define DW_FORM_ref2 0x12
+#define DW_FORM_ref4 0x13
+#define DW_FORM_ref8 0x14
+#define DW_FORM_ref_udata 0x15
+#define DW_FORM_indirect 0x16
+#define DW_FORM_sec_offset 0x17
+#define DW_FORM_exprloc 0x18
+#define DW_FORM_flag_present 0x19
+#define DW_FORM_ref_sig8 0x20
+#define DW_FORM_GNU_ref_alt 0x1f20
+#define DW_FORM_GNU_strp_alt 0x1f21
+
+#define DW_OP_addr 0x03
+#define DW_OP_deref 0x06
+#define DW_OP_const1u 0x08
+#define DW_OP_const1s 0x09
+#define DW_OP_const2u 0x0a
+#define DW_OP_const2s 0x0b
+#define DW_OP_const4u 0x0c
+#define DW_OP_const4s 0x0d
+#define DW_OP_const8u 0x0e
+#define DW_OP_const8s 0x0f
+#define DW_OP_constu 0x10
+#define DW_OP_consts 0x11
+#define DW_OP_dup 0x12
+#define DW_OP_drop 0x13
+#define DW_OP_over 0x14
+#define DW_OP_pick 0x15
+#define DW_OP_swap 0x16
+#define DW_OP_rot 0x17
+#define DW_OP_xderef 0x18
+#define DW_OP_abs 0x19
+#define DW_OP_and 0x1a
+#define DW_OP_div 0x1b
+#define DW_OP_minus 0x1c
+#define DW_OP_mod 0x1d
+#define DW_OP_mul 0x1e
+#define DW_OP_neg 0x1f
+#define DW_OP_not 0x20
+#define DW_OP_or 0x21
+#define DW_OP_plus 0x22
+#define DW_OP_plus_uconst 0x23
+#define DW_OP_shl 0x24
+#define DW_OP_shr 0x25
+#define DW_OP_shra 0x26
+#define DW_OP_xor 0x27
+#define DW_OP_bra 0x28
+#define DW_OP_eq 0x29
+#define DW_OP_ge 0x2a
+#define DW_OP_gt 0x2b
+#define DW_OP_le 0x2c
+#define DW_OP_lt 0x2d
+#define DW_OP_ne 0x2e
+#define DW_OP_skip 0x2f
+#define DW_OP_lit0 0x30
+#define DW_OP_lit1 0x31
+#define DW_OP_lit2 0x32
+#define DW_OP_lit3 0x33
+#define DW_OP_lit4 0x34
+#define DW_OP_lit5 0x35
+#define DW_OP_lit6 0x36
+#define DW_OP_lit7 0x37
+#define DW_OP_lit8 0x38
+#define DW_OP_lit9 0x39
+#define DW_OP_lit10 0x3a
+#define DW_OP_lit11 0x3b
+#define DW_OP_lit12 0x3c
+#define DW_OP_lit13 0x3d
+#define DW_OP_lit14 0x3e
+#define DW_OP_lit15 0x3f
+#define DW_OP_lit16 0x40
+#define DW_OP_lit17 0x41
+#define DW_OP_lit18 0x42
+#define DW_OP_lit19 0x43
+#define DW_OP_lit20 0x44
+#define DW_OP_lit21 0x45
+#define DW_OP_lit22 0x46
+#define DW_OP_lit23 0x47
+#define DW_OP_lit24 0x48
+#define DW_OP_lit25 0x49
+#define DW_OP_lit26 0x4a
+#define DW_OP_lit27 0x4b
+#define DW_OP_lit28 0x4c
+#define DW_OP_lit29 0x4d
+#define DW_OP_lit30 0x4e
+#define DW_OP_lit31 0x4f
+#define DW_OP_reg0 0x50
+#define DW_OP_reg1 0x51
+#define DW_OP_reg2 0x52
+#define DW_OP_reg3 0x53
+#define DW_OP_reg4 0x54
+#define DW_OP_reg5 0x55
+#define DW_OP_reg6 0x56
+#define DW_OP_reg7 0x57
+#define DW_OP_reg8 0x58
+#define DW_OP_reg9 0x59
+#define DW_OP_reg10 0x5a
+#define DW_OP_reg11 0x5b
+#define DW_OP_reg12 0x5c
+#define DW_OP_reg13 0x5d
+#define DW_OP_reg14 0x5e
+#define DW_OP_reg15 0x5f
+#define DW_OP_reg16 0x60
+#define DW_OP_reg17 0x61
+#define DW_OP_reg18 0x62
+#define DW_OP_reg19 0x63
+#define DW_OP_reg20 0x64
+#define DW_OP_reg21 0x65
+#define DW_OP_reg22 0x66
+#define DW_OP_reg23 0x67
+#define DW_OP_reg24 0x68
+#define DW_OP_reg25 0x69
+#define DW_OP_reg26 0x6a
+#define DW_OP_reg27 0x6b
+#define DW_OP_reg28 0x6c
+#define DW_OP_reg29 0x6d
+#define DW_OP_reg30 0x6e
+#define DW_OP_reg31 0x6f
+#define DW_OP_breg0 0x70
+#define DW_OP_breg1 0x71
+#define DW_OP_breg2 0x72
+#define DW_OP_breg3 0x73
+#define DW_OP_breg4 0x74
+#define DW_OP_breg5 0x75
+#define DW_OP_breg6 0x76
+#define DW_OP_breg7 0x77
+#define DW_OP_breg8 0x78
+#define DW_OP_breg9 0x79
+#define DW_OP_breg10 0x7a
+#define DW_OP_breg11 0x7b
+#define DW_OP_breg12 0x7c
+#define DW_OP_breg13 0x7d
+#define DW_OP_breg14 0x7e
+#define DW_OP_breg15 0x7f
+#define DW_OP_breg16 0x80
+#define DW_OP_breg17 0x81
+#define DW_OP_breg18 0x82
+#define DW_OP_breg19 0x83
+#define DW_OP_breg20 0x84
+#define DW_OP_breg21 0x85
+#define DW_OP_breg22 0x86
+#define DW_OP_breg23 0x87
+#define DW_OP_breg24 0x88
+#define DW_OP_breg25 0x89
+#define DW_OP_breg26 0x8a
+#define DW_OP_breg27 0x8b
+#define DW_OP_breg28 0x8c
+#define DW_OP_breg29 0x8d
+#define DW_OP_breg30 0x8e
+#define DW_OP_breg31 0x8f
+#define DW_OP_regx 0x90
+#define DW_OP_fbreg 0x91
+#define DW_OP_bregx 0x92
+#define DW_OP_piece 0x93
+#define DW_OP_deref_size 0x94
+#define DW_OP_xderef_size 0x95
+#define DW_OP_nop 0x96
+#define DW_OP_push_object_address 0x97
+#define DW_OP_call2 0x98
+#define DW_OP_call4 0x99
+#define DW_OP_call_ref 0x9a
+#define DW_OP_form_tls_address 0x9b
+#define DW_OP_call_frame_cfa 0x9c
+#define DW_OP_bit_piece 0x9d
+#define DW_OP_implicit_value 0x9e
+#define DW_OP_stack_value 0x9f
+#define DW_OP_lo_user 0xe0
+#define DW_OP_hi_user 0xff
+
+/* GNU extensions. */
+#define DW_OP_GNU_push_tls_address 0xe0
+#define DW_OP_GNU_uninit 0xf0
+#define DW_OP_GNU_encoded_addr 0xf1
+#define DW_OP_GNU_implicit_pointer 0xf2
+#define DW_OP_GNU_entry_value 0xf3
+#define DW_OP_GNU_const_type 0xf4
+#define DW_OP_GNU_regval_type 0xf5
+#define DW_OP_GNU_deref_type 0xf6
+#define DW_OP_GNU_convert 0xf7
+#define DW_OP_GNU_reinterpret 0xf9
+#define DW_OP_GNU_parameter_ref 0xfa
+#define DW_OP_GNU_addr_index 0xfb
+#define DW_OP_GNU_const_index 0xfc
+
+#define DW_ATE_address 0x1
+#define DW_ATE_boolean 0x2
+#define DW_ATE_complex_float 0x3
+#define DW_ATE_float 0x4
+#define DW_ATE_signed 0x5
+#define DW_ATE_signed_char 0x6
+#define DW_ATE_unsigned 0x7
+#define DW_ATE_unsigned_char 0x8
+#define DW_ATE_imaginary_float 0x9
+#define DW_ATE_packed_decimal 0xa
+#define DW_ATE_numeric_string 0xb
+#define DW_ATE_edited 0xc
+#define DW_ATE_signed_fixed 0xd
+#define DW_ATE_unsigned_fixed 0xe
+#define DW_ATE_decimal_float 0xf
+#define DW_ATE_lo_user 0x80
+#define DW_ATE_hi_user 0xff
+
+#define DW_ACCESS_public 0x01
+#define DW_ACCESS_protected 0x02
+#define DW_ACCESS_private 0x03
+
+#define DW_END_default 0x00
+#define DW_END_big 0x01
+#define DW_END_little 0x02
+#define DW_END_lo_user 0x40
+#define DW_END_high_user 0xff
+
+#define DW_VIS_local 0x01
+#define DW_VIS_exported 0x02
+#define DW_VIS_qualified 0x03
+
+#define DW_VIRTUALITY_none 0x00
+#define DW_VIRTUALITY_virtual 0x01
+#define DW_VIRTUALITY_pure_virtual 0x02
+
+#define DW_LANG_C89 0x0001
+#define DW_LANG_C 0x0002
+#define DW_LANG_Ada83 0x0003
+#define DW_LANG_C_plus_plus 0x0004
+#define DW_LANG_Cobol74 0x0005
+#define DW_LANG_Cobol85 0x0006
+#define DW_LANG_Fortran77 0x0007
+#define DW_LANG_Fortran90 0x0008
+#define DW_LANG_Pascal83 0x0009
+#define DW_LANG_Modula2 0x000a
+#define DW_LANG_Java 0x000b
+#define DW_LANG_C99 0x000c
+#define DW_LANG_Ada95 0x000d
+#define DW_LANG_Fortran95 0x000e
+#define DW_LANG_PLI 0x000f
+#define DW_LANG_ObjC 0x0010
+#define DW_LANG_ObjC_plus_plus 0x0011
+#define DW_LANG_UPC 0x0012
+#define DW_LANG_D 0x0013
+#define DW_LANG_Python 0x0014
+#define DW_LANG_OpenCL 0x0015
+#define DW_LANG_Go 0x0016
+#define DW_LANG_Modula3 0x0017
+#define DW_LANG_Haskell 0x0018
+#define DW_LANG_C_plus_plus_03 0x0019
+#define DW_LANG_C_plus_plus_11 0x001a
+#define DW_LANG_OCaml 0x001b
+#define DW_LANG_Rust 0x001c
+#define DW_LANG_C11 0x001d
+#define DW_LANG_Swift 0x001e
+#define DW_LANG_Julia 0x001f
+#define DW_LANG_Dylan 0x0020
+#define DW_LANG_C_plus_plus_14 0x0021
+#define DW_LANG_Fortran03 0x0022
+#define DW_LANG_Fortran08 0x0023
+#define DW_LANG_RenderScript 0x0024
+#define DW_LANG_BLISS 0x0025
+#define DW_LANG_lo_user 0x8000
+#define DW_LANG_Mips_Assembler 0x8001
+#define DW_LANG_hi_user 0xffff
+
+#define DW_ID_case_sensitive 0x00
+#define DW_ID_up_case 0x01
+#define DW_ID_down_case 0x02
+#define DW_ID_case_insensitive 0x03
+
+#define DW_CC_normal 0x01
+#define DW_CC_program 0x02
+#define DW_CC_nocall 0x03
+#define DW_CC_lo_user 0x40
+#define DW_CC_hi_user 0xff
+
+#define DW_INL_not_inlined 0x00
+#define DW_INL_inlined 0x01
+#define DW_INL_declared_not_inlined 0x02
+#define DW_INL_declared_inlined 0x03
+
+#define DW_ORD_row_major 0x00
+#define DW_ORD_col_major 0x01
+
+#define DW_DS_unsigned 0x01
+#define DW_DS_leading_overpunch 0x02
+#define DW_DS_trailing_overpunch 0x03
+#define DW_DS_leading_separate 0x04
+#define DW_DS_trailing_separate 0x05
+
+#define DW_DSC_label 0x00
+#define DW_DSC_range 0x01
+
+#define DW_LNS_copy 0x01
+#define DW_LNS_advance_pc 0x02
+#define DW_LNS_advance_line 0x03
+#define DW_LNS_set_file 0x04
+#define DW_LNS_set_column 0x05
+#define DW_LNS_negate_stmt 0x06
+#define DW_LNS_set_basic_block 0x07
+#define DW_LNS_const_add_pc 0x08
+#define DW_LNS_fixed_advance_pc 0x09
+#define DW_LNS_set_prologue_end 0x0a
+#define DW_LNS_set_epilogue_begin 0x0b
+#define DW_LNS_set_isa 0x0c
+
+#define DW_LNE_end_sequence 0x01
+#define DW_LNE_set_address 0x02
+#define DW_LNE_define_file 0x03
+#define DW_LNE_lo_user 0x80
+#define DW_LNE_hi_user 0xff
+
+#define DW_MACINFO_define 0x01
+#define DW_MACINFO_undef 0x02
+#define DW_MACINFO_start_file 0x03
+#define DW_MACINFO_end_file 0x04
+#define DW_MACINFO_vendor_ext 0xff
+
+#define DW_CFA_advance_loc 0x40
+#define DW_CFA_offset 0x80
+#define DW_CFA_restore 0xc0
+#define DW_CFA_extended 0
+
+#define DW_CFA_nop 0x00
+#define DW_CFA_set_loc 0x01
+#define DW_CFA_advance_loc1 0x02
+#define DW_CFA_advance_loc2 0x03
+#define DW_CFA_advance_loc4 0x04
+#define DW_CFA_offset_extended 0x05
+#define DW_CFA_restore_extended 0x06
+#define DW_CFA_undefined 0x07
+#define DW_CFA_same_value 0x08
+#define DW_CFA_register 0x09
+#define DW_CFA_remember_state 0x0a
+#define DW_CFA_restore_state 0x0b
+#define DW_CFA_def_cfa 0x0c
+#define DW_CFA_def_cfa_register 0x0d
+#define DW_CFA_def_cfa_offset 0x0e
+#define DW_CFA_def_cfa_expression 0x0f
+#define DW_CFA_expression 0x10
+#define DW_CFA_offset_extended_sf 0x11
+#define DW_CFA_def_cfa_sf 0x12
+#define DW_CFA_def_cfa_offset_sf 0x13
+#define DW_CFA_val_offset 0x14
+#define DW_CFA_val_offset_sf 0x15
+#define DW_CFA_val_expression 0x16
+#define DW_CFA_lo_user 0x1c
+#define DW_CFA_high_user 0x3f
+
+/*
+ * LSB(Linux Standard Base) extension to DWARF2.
+ */
+
+#define DW_EH_PE_absptr 0x00
+#define DW_EH_PE_uleb128 0x01
+#define DW_EH_PE_udata2 0x02
+#define DW_EH_PE_udata4 0x03
+#define DW_EH_PE_udata8 0x04
+#define DW_EH_PE_sleb128 0x09
+#define DW_EH_PE_sdata2 0x0a
+#define DW_EH_PE_sdata4 0x0b
+#define DW_EH_PE_sdata8 0x0c
+#define DW_EH_PE_pcrel 0x10
+#define DW_EH_PE_textrel 0x20
+#define DW_EH_PE_datarel 0x30
+#define DW_EH_PE_funcrel 0x40
+#define DW_EH_PE_aligned 0x50
+#define DW_EH_PE_omit 0xff
+
+#endif /* !_DWARF_H_ */
diff --git a/src/crash-stack/proc.c b/src/crash-stack/proc.c
index 46f40e1..8946c21 100644
--- a/src/crash-stack/proc.c
+++ b/src/crash-stack/proc.c
@@ -294,6 +294,8 @@ char *get_thread_states(const int *tids, int n)
{
int i;
char *res = calloc(1, n);
+ if (!res)
+ return NULL;
for (i = 0; i < n; ++i) {
int state = proc_state(tids[i]);
@@ -383,6 +385,9 @@ static int copy_memory_process_vm_readv(int pid,
remote_iov = malloc(sizeof(struct iovec)*n_frames);
frame_bytes = malloc(sizeof(ssize_t)*n_frames);
+ if (!local_iov || !remote_iov || !frame_bytes)
+ goto process_vm_readv_end;
+
for (i = 0; i < n_frames; ++i) {
local_iov[i].iov_base = frames[i]->data;
local_iov[i].iov_len = frames[i]->length;
diff --git a/src/crash-stack/unwind.c b/src/crash-stack/unwind.c
index d372bbe..be5b81a 100644
--- a/src/crash-stack/unwind.c
+++ b/src/crash-stack/unwind.c
@@ -27,8 +27,6 @@
* DAMAGE.
*/
-#include <dwarf.h>
-#include <gelf.h>
#include <libelf.h>
#include <libgen.h>
#include <libunwind.h>
@@ -39,11 +37,15 @@
#include <sys/user.h>
#include <unistd.h>
+#include "dwarf.h"
#include "mem_map.h"
#include "proc.h"
#include "crash-stack.h"
+#include "shared/elf_helpers.h"
+#ifndef LOG_TAG
#define LOG_TAG "CRASH_STACK"
+#endif
#include "shared/log.h"
size_t stack_size = 0xa00000;
@@ -76,6 +78,7 @@ static unsigned long eip = 0;
static unsigned long esp = 0;
static FILE *debug;
+
static Elf *elf_start(int fd, char *image, uint64_t size)
{
Elf *elf;
@@ -99,24 +102,16 @@ static int find_exidx(int fd, char *image, uint64_t size,
uint64_t *table_data, uint64_t *table_len)
{
Elf *elf;
- GElf_Ehdr ehdr;
Elf_Scn *scn = NULL;
- GElf_Shdr shdr;
uint64_t offset = 0;
if ((elf = elf_start(fd, image, size)) == NULL)
return -1;
- if (gelf_getehdr(elf, &ehdr) == NULL) {
- _E("elf_getehdr: %s", elf_errmsg(elf_errno()));
- goto find_exidx_end;
- }
-
while ((scn = elf_nextscn(elf, scn)) != NULL) {
- if (gelf_getshdr(scn, &shdr) == NULL) {
- _E("elf_getshdr: %s", elf_errmsg(elf_errno()));
- break;
- }
+ Elf64_Shdr shdr;
+ if (!elf_get_shdr(elf, scn, &shdr))
+ break;
if (shdr.sh_type == SHT_ARM_EXIDX) {
Elf_Data *data = NULL;
@@ -131,7 +126,6 @@ static int find_exidx(int fd, char *image, uint64_t size,
}
}
-find_exidx_end:
elf_end(elf);
return (offset ? 0 : -1);
}
@@ -252,28 +246,24 @@ static int find_eh_frame_hdr(int fd, char *image, uint64_t size,
uint64_t *table_data, uint64_t *segbase, uint64_t *fde_count)
{
Elf *elf;
- GElf_Ehdr ehdr;
+ Elf64_Ehdr ehdr;
Elf_Scn *scn = NULL;
- GElf_Shdr shdr;
+ Elf64_Shdr shdr;
uint64_t offset = 0;
if ((elf = elf_start(fd, image, size)) == NULL)
return -1;
- if (gelf_getehdr(elf, &ehdr) == NULL) {
+ if (!elf_get_ehdr(elf, &ehdr)) {
_E("elf_getehdr: %s", elf_errmsg(elf_errno()));
goto elf_section_offset_end;
}
while ((scn = elf_nextscn(elf, scn)) != NULL) {
- char *str;
-
- if (gelf_getshdr(scn, &shdr) == NULL) {
- _E("elf_getshdr: %s", elf_errmsg(elf_errno()));
+ if (!elf_get_shdr(elf, scn, &shdr))
break;
- }
- str = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name);
+ char *str = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name);
if (str != NULL && !strcmp(str, ".eh_frame_hdr")) {
Elf_Data *data = NULL;
@@ -315,7 +305,7 @@ static int find_unwind_table(int fd, char *image, uint64_t size,
*/
struct symbols
{
- GElf_Sym *s_data;
+ Elf64_Sym *s_data;
size_t s_size;
size_t s_cap;
};
@@ -323,22 +313,22 @@ struct symbols
/*
* add a symbol to array
*/
-static int push_symbol(struct symbols *array, const GElf_Sym *s)
+static int push_symbol(struct symbols *array, const Elf64_Sym *s)
{
++array->s_size;
if (array->s_size > array->s_cap) {
- GElf_Sym *new_data;
+ Elf64_Sym *new_data;
array->s_cap <<= 1;
- new_data = malloc(sizeof(GElf_Sym) * array->s_cap);
+ new_data = malloc(sizeof(Elf64_Sym) * array->s_cap);
if (new_data == NULL) {
_E("malloc(): %m");
return -1;
}
- memcpy(new_data, array->s_data, sizeof(GElf_Sym) * (array->s_size-1));
+ memcpy(new_data, array->s_data, sizeof(Elf64_Sym) * (array->s_size-1));
free(array->s_data);
array->s_data = new_data;
}
- memcpy(array->s_data + (array->s_size-1), s, sizeof(GElf_Sym));
+ memcpy(array->s_data + (array->s_size-1), s, sizeof(Elf64_Sym));
return 0;
}
@@ -347,8 +337,8 @@ static int push_symbol(struct symbols *array, const GElf_Sym *s)
*/
static int sym_compar(const void *v1, const void *v2)
{
- const GElf_Sym *s1 = v1;
- const GElf_Sym *s2 = v2;
+ const Elf64_Sym *s1 = v1;
+ const Elf64_Sym *s2 = v2;
if (s1->st_value < s2->st_value)
return -1;
@@ -388,7 +378,7 @@ static char *proc_name(int fd, char *image, size_t size, uint64_t load,
*/
all.s_cap = 64;
all.s_size = 0;
- all.s_data = malloc(all.s_cap * sizeof(GElf_Sym));
+ all.s_data = malloc(all.s_cap * sizeof(Elf64_Sym));
if (all.s_data == NULL)
goto proc_name_end;
@@ -397,8 +387,8 @@ static char *proc_name(int fd, char *image, size_t size, uint64_t load,
goto proc_name_end;
for (i = 0; i < pnum; ++i) {
- GElf_Phdr phdr;
- if (gelf_getphdr(elf, i, &phdr) == NULL)
+ Elf64_Phdr phdr;
+ if (!elf_get_phdr(elf, i, &phdr))
goto proc_name_end;
if (phdr.p_type != PT_LOAD)
continue;
@@ -420,10 +410,9 @@ static char *proc_name(int fd, char *image, size_t size, uint64_t load,
* search symtab or dynsym section
*/
while ((scn = elf_nextscn(elf, scn)) != NULL) {
- GElf_Shdr shdr;
+ Elf64_Shdr shdr;
- if (gelf_getshdr(scn, &shdr) == NULL) {
- _E("elf_nextscn: %s", elf_errmsg(elf_errno()));
+ if (!elf_get_shdr(elf, scn, &shdr)) {
goto proc_name_end;
}
@@ -436,11 +425,15 @@ static char *proc_name(int fd, char *image, size_t size, uint64_t load,
goto proc_name_end;
}
- symbol_count = shdr.sh_size / shdr.sh_entsize;
+ if (shdr.sh_entsize == 0)
+ symbol_count = 0;
+ else
+ symbol_count = shdr.sh_size / shdr.sh_entsize;
+
for (i = 0; i < (size_t)symbol_count; ++i) {
- GElf_Sym s;
+ Elf64_Sym s;
- if (gelf_getsym(data, i, &s) == NULL) {
+ if (!elf_get_sym(elf, data, i, &s)) {
_E("elf_getsym: %s",
elf_errmsg(elf_errno()));
rc = -1;
@@ -489,10 +482,10 @@ static char *proc_name(int fd, char *image, size_t size, uint64_t load,
* one of zero size
*/
if (!rc && str == NULL) {
- qsort(all.s_data, all.s_size, sizeof(GElf_Sym), sym_compar);
+ qsort(all.s_data, all.s_size, sizeof(Elf64_Sym), sym_compar);
for (i = 0; i < (all.s_size-1); ++i) {
- const GElf_Sym *cur = all.s_data + i;
- const GElf_Sym *next = all.s_data + i + 1;
+ const Elf64_Sym *cur = all.s_data + i;
+ const Elf64_Sym *next = all.s_data + i + 1;
if (cur->st_size == 0) {
if (cur->st_value <= addr && addr < next->st_value) {
str = elf_strptr(elf, cur->st_shndx, cur->st_name);
diff --git a/src/dump_systemstate/CMakeLists.txt b/src/dump_systemstate/CMakeLists.txt
index 7c3fa21..aadbe1f 100755..100644
--- a/src/dump_systemstate/CMakeLists.txt
+++ b/src/dump_systemstate/CMakeLists.txt
@@ -31,9 +31,10 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${dump_systemstate_pkgs_LDFLAGS} -pie)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/files.conf.example
- DESTINATION ${DUMP_SYSTEMSTATE_CONFIG_DIR_PATH}/files
- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/programs.conf.example
- DESTINATION ${DUMP_SYSTEMSTATE_CONFIG_DIR_PATH}/programs
- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+
+INSTALL(DIRECTORY files DESTINATION ${DUMP_SYSTEMSTATE_CONFIG_DIR_PATH}
+ PATTERN "files/*.conf*"
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+INSTALL(DIRECTORY programs DESTINATION ${DUMP_SYSTEMSTATE_CONFIG_DIR_PATH}
+ PATTERN "programs/*.conf*"
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
diff --git a/src/dump_systemstate/dump_systemstate.c b/src/dump_systemstate/dump_systemstate.c
index 30a8f35..dd183e6 100644
--- a/src/dump_systemstate/dump_systemstate.c
+++ b/src/dump_systemstate/dump_systemstate.c
@@ -21,6 +21,7 @@
* @brief dump system states.
*/
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -31,6 +32,7 @@
#include <limits.h>
#include <getopt.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <sys/vfs.h>
#include "dump_systemstate.h"
@@ -59,27 +61,27 @@ static struct dump_item {
static void usage()
{
- fprintf(stderr, "usage: dump_systemstate [-k] [-d] [-j] [-p] [-e] [-f file]\n"
+ fprintf(stderr, "usage: dump_systemstate [-b] [-k] [-d] [-j] [-p] [-e] [-E] [-f file]\n"
+ " -b: dump Buxton data\n"
" -f: write to file (instead of stdout)\n"
" -k: dump kernel messages (only root)\n"
" -d: dump dlog messages\n"
" -j: dump journal log messages\n"
" -p: dump list of installed packages\n"
- " -e: dump extras defined in the config\n"
+ " -e: dump extras defined in the config (default)\n"
" at " DUMP_SYSTEMSTATE_CONFIG_DIR_PROGRAMS_PATH "\n"
" and " DUMP_SYSTEMSTATE_CONFIG_DIR_FILES_PATH "\n"
+ " -E: without extras defined in the config\n"
);
}
-/* get disk used percentage */
static int get_disk_used_percent(const char *path)
{
+ assert(path);
+
struct statfs lstatfs;
int percent;
- if (!path)
- return -1;
-
if (statfs(path, &lstatfs) < 0)
return -1;
percent = (((lstatfs.f_blocks - lstatfs.f_bfree) * 1000) / (lstatfs.f_blocks)) + 9;
@@ -87,54 +89,58 @@ static int get_disk_used_percent(const char *path)
return percent;
}
+static dev_t get_disk_device(const char *path)
+{
+ assert(path);
+
+ struct stat st;
+ if (stat(path, &st) < 0)
+ return -1;
+
+ return st.st_dev;
+}
+
int main(int argc, char *argv[])
{
- int c, ret, i, is_root, dpercent, exit_code = 0;
+ int c, ret, i, dpercent, exit_code = 0;
const char *arg_file = NULL;
int out_fd = -1;
- bool arg_dlog = false;
- bool arg_dmesg = false;
- bool arg_extras = false;
- bool arg_journal = false;
- bool arg_pkgs = false;
+ bool arg_extras = true;
char timestr[80];
time_t cur_time;
struct tm gm_tm;
struct tm loc_tm;
+ const struct option long_options[] = {
+ { "no-extra", no_argument, NULL, 'E' },
+ { "help", no_argument, NULL, 'h' },
+ };
- while ((c = getopt(argc, argv, "hf:kdjep")) != -1) {
+ while ((c = getopt_long(argc, argv, "hf:kdbjeEp", long_options, NULL)) != -1) {
switch (c) {
- case 'd':
- arg_dlog = true;
- break;
- case 'k':
- arg_dmesg = true;
- break;
- case 'e':
+ case 'e': // This flag is here for backward compatibility
arg_extras = true;
break;
- case 'j':
- arg_journal = true;
- break;
- case 'p':
- arg_pkgs = true;
+ case 'E':
+ arg_extras = false;
break;
case 'f':
arg_file = optarg;
break;
- case '?':
case 'h':
printf("\n");
usage();
ret = 0;
goto exit;
+ default:
+ // All other flags are ignored as might be handled through extra
+ // config files (cmdflag=)
+ continue;
}
}
ret = 0;
cur_time = time(NULL);
gmtime_r(&cur_time, &gm_tm);
localtime_r(&cur_time, &loc_tm);
- is_root = !(geteuid());
/* open output file */
if (arg_file == NULL) {
@@ -165,7 +171,7 @@ int main(int argc, char *argv[])
fprintf_fd(out_fd, "\n");
if (arg_extras)
- exit_code |= handle_extra_dir(out_fd, DUMP_SYSTEMSTATE_CONFIG_DIR_FILES_PATH, handle_extra_file);
+ exit_code |= handle_extra_dir(out_fd, DUMP_SYSTEMSTATE_CONFIG_DIR_FILES_PATH, handle_extra_file, argc, argv);
#define spawn_wait_checked(av, env) \
do { \
@@ -183,63 +189,30 @@ int main(int argc, char *argv[])
dpercent = get_disk_used_percent("/opt");
if (90 < dpercent) {
- fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt)\n", dpercent);
+ fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt --exclude=/opt/usr)\n", dpercent);
char *du_args[] = {"/bin/du", "-ah", "/opt", "--exclude=/opt/usr", NULL};
spawn_wait_checked(du_args, NULL);
}
- fprintf_fd(out_fd, "\n==== System timezone (ls -al /opt/etc/localtime)\n");
- char *ls_args[] = {"/bin/ls", "-al", "/opt/etc/localtime", NULL};
- spawn_wait_checked(ls_args, NULL);
-
- fprintf_fd(out_fd, "\n==== System summary (/usr/bin/top -bcH -n 1)\n");
- char *top_args[] = {"/bin/top", "-bcH", "-n", "1", NULL};
- char *top_env[] = {"COLUMNS=200", NULL};
- spawn_wait_checked(top_args, top_env);
-
- fprintf_fd(out_fd, "\n==== Current processes (/bin/ps auxfw)\n");
- char *ps_args[] = {"/bin/ps", "auxfw", NULL};
- spawn_wait_checked(ps_args, NULL);
-
- fprintf_fd(out_fd, "\n==== System memory statistics (/usr/bin/memps -v)\n");
- char *memps_args[] = {"/bin/memps", "-v", NULL};
- spawn_wait_checked(memps_args, NULL);
-
- if (is_root) {
- fprintf_fd(out_fd, "\n==== System configuration (/usr/bin/buxton2ctl dump memory, system)\n");
- char *get_mem_args[] = {"/bin/buxton2ctl", "dump", "memory", NULL};
- spawn_wait_checked(get_mem_args, NULL);
-
- char *get_sys_args[] = {"/bin/buxton2ctl", "dump", "system", NULL};
- spawn_wait_checked(get_sys_args, NULL);
- }
- if (arg_pkgs) {
- fprintf_fd(out_fd, "\n==== Installed packages (/usr/bin/pkgcmd -l)\n");
- char *pkgcmd_args[] = {"/usr/bin/pkgcmd", "-l", NULL};
- spawn_wait_checked(pkgcmd_args, NULL);
- }
+ if (get_disk_device("/opt") != get_disk_device("/opt/usr")) {
+ dpercent = get_disk_used_percent("/opt/usr");
- if (arg_dmesg && is_root) {
- fprintf_fd(out_fd, "\n==== Kernel messages (TZ=UTC /bin/dmesg -T)\n");
- char *dmesg_args[] = {"/bin/dmesg", "-T", NULL};
- char *dmesg_env[] = {"TZ=UTC", NULL};
- spawn_wait_checked(dmesg_args, dmesg_env);
- }
-
- if (arg_dlog) {
- fprintf_fd(out_fd, "\n==== Log messages\n");
- char *dlogutil_args[] = {"/bin/dlogutil", "-d", "-v", "threadtime", "-u", "16384", NULL};
- spawn_wait_checked(dlogutil_args, NULL);
+ if (90 < dpercent) {
+ fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt/usr)\n", dpercent);
+ char *du_args[] = {"/bin/du", "-ah", "/opt/usr", NULL};
+ spawn_wait_checked(du_args, NULL);
+ }
}
- if (arg_journal) {
- fprintf_fd(out_fd, "\n==== Journal messages\n");
- char *journalctl_args[] = {"/bin/journalctl", "-b", "-n", "1024", NULL};
- spawn_wait_checked(journalctl_args, NULL);
+ dpercent = get_disk_used_percent("/tmp");
+ if (80 < dpercent) {
+ fprintf_fd(out_fd, "\n==== tmp usage detail - %d%% (/bin/du -ah /tmp)\n", dpercent);
+ char *du_args[] = {"/bin/du", "-ah", "/tmp", NULL};
+ spawn_wait_checked(du_args, NULL);
}
if (arg_extras)
- exit_code |= handle_extra_dir(out_fd, DUMP_SYSTEMSTATE_CONFIG_DIR_PROGRAMS_PATH, handle_extra_program);
+ exit_code |= handle_extra_dir(out_fd, DUMP_SYSTEMSTATE_CONFIG_DIR_PROGRAMS_PATH, handle_extra_program, argc, argv);
#undef spawn_wait_checked
diff --git a/src/dump_systemstate/extras.c b/src/dump_systemstate/extras.c
index 90625a5..6f17b34 100644
--- a/src/dump_systemstate/extras.c
+++ b/src/dump_systemstate/extras.c
@@ -33,6 +33,7 @@
// C
#include <assert.h>
+#include <limits.h>
#include <stdbool.h>
static inline void cleanup_dictionary(dictionary **ini)
@@ -49,6 +50,7 @@ enum ini_fields {
INI_FIELD_PATH,
INI_FIELD_ARGS,
INI_FIELD_ENV,
+ INI_FIELD_FLAG,
COUNT_INI_FIELDS,
};
@@ -57,15 +59,49 @@ static const char *const INI_KEYS[COUNT_INI_FIELDS] = {
[INI_FIELD_PATH] = "path",
[INI_FIELD_ARGS] = "args",
[INI_FIELD_ENV] = "env",
+ [INI_FIELD_FLAG] = "cmdflag",
+ // non-string field: "order"
};
-static const size_t MAX_INI_KEY_LEN = 5;
+static const size_t MAX_INI_KEY_LEN = 7;
struct extra_dump_item {
// not separate named fields, for convenient iteration
char *fields[COUNT_INI_FIELDS];
+ int order;
};
-int handle_extra_program(int out_fd, struct extra_dump_item *item)
+void cleanup_extra_dump_item(struct extra_dump_item *edi)
+{
+ for (size_t i = 0; i < ARRAY_SIZE(edi->fields); ++i)
+ free(edi->fields[i]);
+}
+
+struct extra_items_vector {
+ size_t size;
+ struct extra_dump_item *data;
+};
+
+bool check_cmdflag(const char *const flag, int argc, char **argv)
+{
+ if (!flag)
+ return true;
+
+ for (int i = 1; i < argc; i++) {
+ char *p = argv[i];
+ if (*p != '-')
+ continue;
+ for (++p; *p; p++) {
+ if (*p == '-')
+ break;
+ if (*p == flag[0])
+ return true;
+ }
+ }
+
+ return false;
+}
+
+int handle_extra_program(int out_fd, struct extra_dump_item *item, int argc, char **argv)
{
assert(out_fd >= 0);
assert(item);
@@ -74,6 +110,10 @@ int handle_extra_program(int out_fd, struct extra_dump_item *item)
char *const path = item->fields[INI_FIELD_PATH];
char *const args = item->fields[INI_FIELD_ARGS] ?: "";
char *const env = item->fields[INI_FIELD_ENV] ?: "";
+ char *const flag = item->fields[INI_FIELD_FLAG];
+
+ if (!check_cmdflag(flag, argc, argv))
+ return 0;
if (!title || !path) {
fprintf_fd(out_fd, "\nNo title or path in extra program config");
@@ -94,17 +134,17 @@ int handle_extra_program(int out_fd, struct extra_dump_item *item)
* an array of char pointers. Splitting isn't trivial (consider a brutal set
* of arguments using " or `) and I don't want to reinvent the wheel so I'm
* delegating the splitting to the shell. */
- char *argv[] = {"/bin/sh", "-c", command_line, NULL};
+ char *av[] = {"/bin/sh", "-c", command_line, NULL};
int err;
spawn_param_s param = { .fn = spawn_setstdout, .u.int_val = out_fd };
- bool failed = !spawn_wait(argv, NULL, &param, DEFAULT_COMMAND_TIMEOUT_MS, &err) || err != 0;
+ bool failed = !spawn_wait(av, NULL, &param, DEFAULT_COMMAND_TIMEOUT_MS, &err) || err != 0;
free(command_line);
return failed ? EXIT_CMDERR : 0;
}
-int handle_extra_file(int out_fd, struct extra_dump_item *item)
+int handle_extra_file(int out_fd, struct extra_dump_item *item, int argc, char **argv)
{
assert(out_fd >= 0);
assert(item);
@@ -125,15 +165,14 @@ int handle_extra_file(int out_fd, struct extra_dump_item *item)
return 0;
}
-typedef int (*handle_ini_section_t)(int out_fd, struct extra_dump_item *);
+typedef int (*handle_ini_section_t)(int out_fd, struct extra_dump_item *, int argc, char **argv);
-static int handle_ini_Nth_section(int out_fd, dictionary *ini, int n, handle_ini_section_t handle_ini_section)
+static int handle_ini_Nth_section(struct extra_dump_item *item, dictionary *ini, int n)
{
- assert(out_fd >= 0);
+ assert(item);
assert(ini);
assert(n >= 0);
assert(n < iniparser_getnsec(ini));
- assert(handle_ini_section);
char *const secname = iniparser_getsecname(ini, n);
assert(secname); // can only be NULL if `ini` is NULL or `n` is outta bounds
@@ -143,21 +182,34 @@ static int handle_ini_Nth_section(int out_fd, dictionary *ini, int n, handle_ini
memcpy(key_buf, secname, secname_len);
key_buf[secname_len] = ':';
- char *const key_suffix_ptr = key_buf + secname_len + 1;
- struct extra_dump_item item;
- for (size_t i = 0; i < ARRAY_SIZE(item.fields); ++i) {
+ int ret = 0;
+ char *key_suffix_ptr = key_buf + secname_len + 1;
+ for (size_t i = 0; i < ARRAY_SIZE(item->fields); ++i) {
strcpy(key_suffix_ptr, INI_KEYS[i]);
- item.fields[i] = iniparser_getstring(ini, key_buf, NULL);
+
+ char *tmp = iniparser_getstring(ini, key_buf, NULL);
+ if (!tmp) {
+ item->fields[i] = NULL;
+ continue;
+ }
+
+ item->fields[i] = strdup(tmp);
+ if (!item->fields[i])
+ ret |= EXIT_ERR;
}
- return handle_ini_section(out_fd, &item);
+ strcpy(key_suffix_ptr, "order");
+ char *tmp = iniparser_getstring(ini, key_buf, NULL);
+ item->order = tmp ? atoi(tmp) : INT_MAX;
+
+ return ret;
}
-static int handle_extra_ini(int out_fd, const char *ini_path, handle_ini_section_t handle_ini_section)
+static int handle_extra_ini(int out_fd, struct extra_items_vector *eiv, const char *ini_path)
{
assert(out_fd >= 0);
+ assert(eiv);
assert(ini_path);
- assert(handle_ini_section);
__attribute__((cleanup(cleanup_dictionary))) dictionary *ini = iniparser_load(ini_path);
if (!ini) {
@@ -168,9 +220,16 @@ static int handle_extra_ini(int out_fd, const char *ini_path, handle_ini_section
const int nsec = iniparser_getnsec(ini);
assert(nsec >= 0); // can only be -1 when ini is NULL
+ const size_t prev_size = eiv->size;
+ struct extra_dump_item *const temp = realloc(eiv->data, (eiv->size + nsec) * sizeof *eiv->data);
+ if (!temp)
+ return EXIT_ERR;
+ eiv->data = temp;
+ eiv->size += nsec;
+
int ret = 0;
for (int i = 0; i < nsec; ++i)
- ret |= handle_ini_Nth_section(out_fd, ini, i, handle_ini_section);
+ ret |= handle_ini_Nth_section(eiv->data + prev_size + i, ini, i);
return ret;
}
@@ -180,7 +239,27 @@ static int config_entry_filter(const struct dirent *de)
return de->d_type == DT_REG && string_ends_with(de->d_name, ".conf");
}
-int handle_extra_dir(int out_fd, char *dir_path, handle_ini_section_t handle_ini_section)
+int handle_items_vector(struct extra_items_vector *eiv, int out_fd, handle_ini_section_t handle_ini_section, int argc, char **argv)
+{
+ inline int cmp(const void *a, const void *b) {
+ return ((struct extra_dump_item *)a)->order - ((struct extra_dump_item *)b)->order;
+ }
+ qsort(eiv->data, eiv->size, sizeof *eiv->data, cmp);
+
+ int ret = 0;
+ for (size_t i = 0; i < eiv->size; ++i)
+ ret |= handle_ini_section(out_fd, eiv->data + i, argc, argv);
+ return ret;
+}
+
+void free_items_vector(struct extra_items_vector *eiv)
+{
+ for (size_t i = 0; i < eiv->size; ++i)
+ cleanup_extra_dump_item(eiv->data + i);
+ free(eiv->data);
+}
+
+int handle_extra_dir(int out_fd, char *dir_path, handle_ini_section_t handle_ini_section, int argc, char **argv)
{
assert(out_fd >= 0);
assert(dir_path);
@@ -200,6 +279,11 @@ int handle_extra_dir(int out_fd, char *dir_path, handle_ini_section_t handle_ini
return EXIT_ERR;
}
+ __attribute__((cleanup(free_items_vector))) struct extra_items_vector eiv = {
+ .size = 0,
+ .data = NULL,
+ };
+
int ret = 0;
for (int i = 0; i < entry_count; ++i) {
struct dirent *const de = entries[i];
@@ -212,8 +296,10 @@ int handle_extra_dir(int out_fd, char *dir_path, handle_ini_section_t handle_ini
snprintf(ini_path, sizeof ini_path, "%s/%s", dir_path, de->d_name);
free(de);
- ret |= handle_extra_ini(out_fd, ini_path, handle_ini_section);
+ ret |= handle_extra_ini(out_fd, &eiv, ini_path);
}
+ ret |= handle_items_vector(&eiv, out_fd, handle_ini_section, argc, argv);
+
free(entries);
close(dir_fd);
return ret;
diff --git a/src/dump_systemstate/extras.h b/src/dump_systemstate/extras.h
index c6d78de..392bff0 100644
--- a/src/dump_systemstate/extras.h
+++ b/src/dump_systemstate/extras.h
@@ -27,9 +27,9 @@
struct extra_dump_item;
-typedef int (*handle_ini_section_t)(int out_fd, struct extra_dump_item *);
+typedef int (*handle_ini_section_t)(int out_fd, struct extra_dump_item *, int argc, char **argv);
-int handle_extra_dir(int out_fd, char *dir_path, handle_ini_section_t handle_ini_section);
-int handle_extra_file(int out_fd, struct extra_dump_item *item);
-int handle_extra_program(int out_fd, struct extra_dump_item *item);
+int handle_extra_dir(int out_fd, char *dir_path, handle_ini_section_t handle_ini_section, int argc, char **argv);
+int handle_extra_file(int out_fd, struct extra_dump_item *item, int argc, char **argv);
+int handle_extra_program(int out_fd, struct extra_dump_item *item, int argc, char **argv);
diff --git a/src/dump_systemstate/files/crash-worker-files.conf b/src/dump_systemstate/files/crash-worker-files.conf
new file mode 100644
index 0000000..8989450
--- /dev/null
+++ b/src/dump_systemstate/files/crash-worker-files.conf
@@ -0,0 +1,9 @@
+[VMSTAT]
+order=100
+title=Virtual Memory statistics
+path=/proc/vmstat
+
+[KERNEL_LOCKS]
+order=110
+title=Kernel lock
+path=/proc/locks
diff --git a/src/dump_systemstate/files.conf.example b/src/dump_systemstate/files/files.conf.example
index 92d5f22..a47de41 100644
--- a/src/dump_systemstate/files.conf.example
+++ b/src/dump_systemstate/files/files.conf.example
@@ -1,3 +1,6 @@
+# Please use order=NUMBER directive to have entries printed in (increasing)
+# order. Entries with the same order value are also printed in random order.
+
[UNIQUE_ID_KEY]
title=header line that gets printed (path gets appended too)
path=/path/to/the/file
diff --git a/src/dump_systemstate/programs/crash-worker-programs.conf b/src/dump_systemstate/programs/crash-worker-programs.conf
new file mode 100644
index 0000000..c8980ac
--- /dev/null
+++ b/src/dump_systemstate/programs/crash-worker-programs.conf
@@ -0,0 +1,73 @@
+[timezone]
+order=100
+title=System timezone
+path=/bin/ls
+args=-l /opt/etc/localtime
+
+[top]
+order=110
+title=System summary
+path=/bin/top
+args=-bcHn1
+env=COLUMNS=200
+
+[ps]
+order=120
+title=Current processes
+path=/bin/ps
+args=auxfw
+
+[memps]
+order=130
+title=System memory statistics
+path=/usr/bin/memps
+args=-v
+
+[buxton memory]
+order=140
+cmdflag=b
+title=System configuration
+path=/usr/bin/buxton2ctl
+args=dump memory
+
+[buxton system]
+order=141
+cmdflag=b
+title=System configuration
+path=/usr/bin/buxton2ctl
+args=dump system
+
+[Tizen packages]
+order=150
+cmdflag=p
+title=Installed packages
+path=/usr/bin/pkgcmd
+args=-l --global
+
+[IPC]
+order=160
+title=System IPC facilities
+path=/usr/bin/ipcs
+args=-a
+
+[dmesg]
+order=200
+cmdflag=k
+title=Kernel messages
+path=/bin/dmesg
+args=-T
+env=TZ=UTC
+
+[dlog]
+order=210
+cmdflag=d
+title=Log messages
+path=/usr/bin/dlogutil
+args=-d -v threadtime -u 16384
+
+[journal]
+order=220
+cmdflag=j
+title=Journal messages
+path=/usr/bin/journalctl
+args=-b -n 1024
diff --git a/src/dump_systemstate/programs.conf.example b/src/dump_systemstate/programs/programs.conf.example
index 8e26083..b44b9ce 100644
--- a/src/dump_systemstate/programs.conf.example
+++ b/src/dump_systemstate/programs/programs.conf.example
@@ -1,3 +1,5 @@
+# See files.conf.example for note about ordering.
+
[UNIQUE_ID_KEY]
title=header line describing the program (will be printed alongside env, path and args)
path=/path/to/the/program/executable
diff --git a/src/livedumper/CMakeLists.txt b/src/livedumper/CMakeLists.txt
index efdf65a..26b8902 100644
--- a/src/livedumper/CMakeLists.txt
+++ b/src/livedumper/CMakeLists.txt
@@ -4,7 +4,7 @@ project(livedumper CXX)
set(LIVEDUMPER_BIN "livedumper")
find_package( Boost 1.58 COMPONENTS system REQUIRED)
-include_directories ( ${Boost_INCLUDE_DIR} )
+include_directories ( ${Boost_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src )
set(PREFIX ${CMAKE_INSTALL_PREFIX})
add_definitions(-std=c++11)
diff --git a/src/livedumper/core.hpp b/src/livedumper/core.hpp
index e9ae8dc..d93df7e 100644
--- a/src/livedumper/core.hpp
+++ b/src/livedumper/core.hpp
@@ -22,9 +22,9 @@
#include "log.hpp"
#include "note.hpp"
#include "program.hpp"
+#include "shared/elf_helpers.h"
#include <fcntl.h>
-#include <gelf.h>
#include <inttypes.h>
#include <libelf.h>
#include <limits.h>
@@ -289,7 +289,6 @@ class Core {
sym_data->elf = elf_begin(sym_data->fd, ELF_C_READ, nullptr);
while (1) {
- GElf_Shdr *shdr;
scn = elf_nextscn(sym_data->elf, scn);
if (!scn) {
@@ -300,8 +299,8 @@ class Core {
return nullptr;
}
- shdr = gelf_getshdr(scn, &sym_data->shdr);
- if (shdr && sym_data->shdr.sh_type == type)
+ if (elf_get_shdr(sym_data->elf, scn, &sym_data->shdr) &&
+ sym_data->shdr.sh_type == type)
break;
}
@@ -366,19 +365,17 @@ class Core {
bool SymAddress(const char *sym_name, unsigned long *addr) {
for (const auto &sd : m_symdata) {
for (int i = 0; i < sd->count; i++) {
- GElf_Sym sym;
- GElf_Sym *s;
+ Elf64_Sym sym;
- s = gelf_getsym(sd->data, i, &sym);
- if (!s)
+ if (!elf_get_sym(sd->elf, sd->data, i, &sym))
continue;
- const char *st = elf_strptr(sd->elf, sd->shdr.sh_link, s->st_name);
+ const char *st = elf_strptr(sd->elf, sd->shdr.sh_link, sym.st_name);
if (strcmp(st, sym_name) != 0)
continue;
- *addr = sd->start + s->st_value;
+ *addr = sd->start + sym.st_value;
return true;
}
}
diff --git a/src/shared/config.c b/src/shared/config.c
index 3154752..694596d 100644
--- a/src/shared/config.c
+++ b/src/shared/config.c
@@ -15,10 +15,14 @@
* limitations under the License.
*/
#include <assert.h>
+#include <dirent.h>
+#include <fcntl.h>
#include <iniparser.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "config.h"
#include "defs.h"
@@ -42,55 +46,259 @@ enum ReportType report_type_from_str(const char *report_type_str)
assert(report_type_str);
for (int i = 0; i < (int)ARRAY_SIZE(report_type_strmap); i++) {
- if (0 == strcmp(report_type_str, report_type_strmap[i]))
+ if (0 == strcasecmp(report_type_str, report_type_strmap[i]))
return (enum ReportType)i;
}
return REP_TYPE_INVALID;
}
-bool config_init(config_t *c, const char *const path)
+static int config_load_exclude_paths(config_t *c, dictionary *ini)
+{
+ assert(c);
+ assert(ini);
+
+ int n = iniparser_getsecnkeys(ini, EXCLUDEPATHS_SECTION);
+ _D("config: Found %d entries in " EXCLUDEPATHS_SECTION, n);
+ if (n <= 0)
+ return 0;
+
+ int total = n + c->n_exclude_paths;
+ int n_added = 0;
+
+ c->exclude_paths = realloc(c->exclude_paths, sizeof(char *) * total);
+
+ if (!c->exclude_paths)
+ goto err_oom;
+
+ // keys are destroyed by iniparser
+ char **keys = iniparser_getseckeys(ini, EXCLUDEPATHS_SECTION);
+ if (!keys)
+ goto err_oom;
+
+ for (int i = c->n_exclude_paths, j = 0; i < total; i++, j++) {
+ const char *const str = iniparser_getstring(ini, keys[j], NULL);
+ if (!str)
+ continue;
+
+ _D("config: Adding <%s> to exclude paths list", str);
+ c->exclude_paths[i] = strdup(str);
+ if (!c->exclude_paths[i])
+ goto err_oom;
+ c->n_exclude_paths += 1;
+ n_added += 1;
+ }
+ return n_added;
+
+err_oom:
+ _E("Out of memory. ExcludePaths configuration not loaded.");
+ return n_added;
+}
+
+bool config_is_path_excluded(config_t *c, const char *const path)
{
assert(c);
assert(path);
+ for (int i = 0; i < c->n_exclude_paths; i++) {
+ if (strcmp(path, c->exclude_paths[i]) == 0) {
+ _I("Found match on exclude paths list: %s", path);
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool config_load_from_dict(config_t *c, dictionary *ini)
+{
+ assert(c);
+ assert(ini);
+
+ const char *str = iniparser_getstring(ini, CRASH_SECTION ":CrashRootPath", NULL);
+ if (str) {
+ char *crash_root_path = strdup(str);
+ if (!crash_root_path) {
+ _E("config: Unable to set CrashRootPath - aborting");
+ return false;
+ }
+
+ free(c->crash_root_path);
+ c->crash_root_path = crash_root_path;
+ }
+
+ /* strdup() can technically fail, but we don't mind. It is better to
+ * create a report without the extra script than to abort completely. */
+ str = iniparser_getstring(ini, CRASH_SECTION ":ExtraScript", NULL);
+ if (str) {
+ char *extra_script = strdup(str);
+ if (extra_script) {
+ free(c->extra_script);
+ c->extra_script = extra_script;
+ } else
+ _W("Out of memory. ExtraScript will not be executed.");
+ }
+
+ str = iniparser_getstring(ini, CRASH_SECTION ":ReportType", NULL);
+ if (str) {
+ int type = report_type_from_str(str);
+ if (report_type_to_str(type))
+ c->report_type = type;
+ }
+
+#define UPDATE(where, type, key) where = iniparser_get##type(ini, CRASH_SECTION ":" key, where)
+
+ UPDATE(c->system_max_use, int, "SystemMaxUse");
+ UPDATE(c->max_retention_sec, int, "MaxRetentionSec");
+ UPDATE(c->max_crash_dump, int, "MaxCrashDump");
+ UPDATE(c->dump_core, boolean, "DumpCore");
+ UPDATE(c->dump_so_info, boolean, "DumpSharedObjectInfo");
+ UPDATE(c->allow_zip, boolean, "AllowZip");
+ UPDATE(c->legacy_notification, boolean, "UseLegacyNotification");
+ UPDATE(c->release_early, boolean, "ReleaseProcessLockEarly");
+
+#undef UPDATE
+
+ config_load_exclude_paths(c, ini);
+
+ return true;
+}
+
+static bool config_load_from_path(config_t *c, const char *const path)
+{
+ assert(path);
+
dictionary *ini = iniparser_load(path);
if (!ini) {
_E("Failed to load config file %s", path);
return false;
}
- bool ret = false;
+ bool ret = config_load_from_dict(c, ini);
+ iniparser_freedict(ini);
+
+ return ret;
+}
+
+static int entry_filter(const struct dirent *e)
+{
+ assert(e);
-#define GET(type, key, defval) iniparser_get##type(ini, CRASH_SECTION ":" key, defval)
+ const char *const conf_suffix = ".conf";
+ const char *const name = e->d_name;
+ int len = strlen(name);
- c->crash_root_path = strdup(GET(string, "CrashRootPath", CRASH_ROOT_PATH));
- if (!c->crash_root_path)
- goto out;
+ if (e->d_type != DT_REG || len <= strlen(conf_suffix))
+ return 0;
- /* strdup() can technically fail, but we don't mind. It is better to
- * create a report without the extra script than to abort completely. */
- char *extrascript = GET(string, "ExtraScript", NULL);
- c->extra_script = extrascript ? strdup(extrascript) : NULL;
+ // accept only files ending with predefined suffix
+ return strcmp(name + len - strlen(conf_suffix), conf_suffix) == 0;
+}
- char *reptype = GET(string, "ReportType", (char *)report_type_strmap[REP_TYPE_FULL]);
- c->report_type = report_type_from_str(reptype);
- if (!report_type_to_str(c->report_type))
- goto out;
+static bool config_load_from_dir_prefix(config_t *c, const char *const dir_prefix)
+{
+ assert(dir_prefix);
- c->system_max_use = GET(int, "SystemMaxUse", SYSTEM_MAX_USE);
- c->system_keep_free = GET(int, "SystemKeepFree", SYSTEM_KEEP_FREE);
- c->max_retention_sec = GET(int, "MaxRetentionSec", MAX_RETENTION_SEC);
- c->max_crash_dump = GET(int, "MaxCrashDump", MAX_CRASH_DUMP);
- c->dump_core = GET(boolean, "DumpCore", DUMP_CORE);
- c->allow_zip = GET(boolean, "AllowZip", ALLOW_ZIP);
+ char dir_path[PATH_MAX];
+ int ret = snprintf(dir_path, sizeof(dir_path), "%s.d", dir_prefix);
+ if (ret < 0 || ret >= PATH_MAX) {
+ _W("config: internal error while trying to prepare config dir path");
+ return false;
+ }
-#undef GET
+ int fd = open(dir_path, O_RDONLY | O_DIRECTORY);
+ if (fd < 0 && errno == ENOENT)
+ return true;
+ if (fd < 0) {
+ _E("config: Unable to access config directory at %s: %m", dir_path);
+ return false;
+ }
+
+ struct dirent **entries = NULL;
+ int n = scandirat(fd, ".", &entries, entry_filter, alphasort);
+ if (n < 0)
+ goto out;
+
+ for (int i = 0; i < n; ++i) {
+ char file_path[PATH_MAX];
+ const char *fname = entries[i]->d_name;
+ ret = snprintf(file_path, sizeof(file_path), "%s/%s", dir_path, fname);
+ if (ret < 0 || ret >= PATH_MAX) {
+ _W("config: internal error while trying to prepare for reading %s config file", fname);
+ continue;
+ }
+ _D("config: reading additional configuration file from %s", file_path);
+ (void)config_load_from_path(c, file_path);
+ }
- ret = true;
out:
- iniparser_freedict(ini);
- return ret;
+ free(entries);
+ close(fd);
+ return true;
+}
+
+static bool config_apply_defaults(config_t *c)
+{
+ assert(c);
+
+ memset(c, 0, sizeof(*c));
+
+ c->crash_root_path = strdup(CRASH_ROOT_PATH);
+ c->report_type = REP_TYPE_FULL;
+ c->system_max_use = SYSTEM_MAX_USE;
+ c->system_keep_free = SYSTEM_KEEP_FREE;
+ c->max_retention_sec = MAX_RETENTION_SEC;
+ c->max_crash_dump = MAX_CRASH_DUMP;
+ c->dump_core = DUMP_CORE;
+ c->dump_so_info = DUMP_SO_INFO;
+ c->allow_zip = ALLOW_ZIP;
+ c->legacy_notification = LEGACY_NOTIFICATION;
+ c->release_early = RELEASE_EARLY;
+
+ return c->crash_root_path != NULL;
+}
+
+static void config_dump(config_t *c)
+{
+ assert(c);
+
+ _D("config: crash_root_path = %s\n"
+ "config: extra_script = %s\n"
+ "config: report_type = %s\n"
+ "config: system_max_use = %d\n"
+ "config: system_keep_free = %d\n"
+ "config: max_retention_sec = %d\n"
+ "config: max_crash_dump = %d\n"
+ "config: dump_core = %d\n"
+ "config: dump_so_info = %d\n"
+ "config: allow_zip = %d\n"
+ "config: legacy_notification = %d\n"
+ "config: release_early = %d\n",
+ c->crash_root_path,
+ c->extra_script,
+ report_type_to_str(c->report_type),
+ c->system_max_use,
+ c->system_keep_free,
+ c->max_retention_sec,
+ c->max_crash_dump,
+ c->dump_core,
+ c->dump_so_info,
+ c->allow_zip,
+ c->legacy_notification,
+ c->release_early);
+}
+
+bool config_init(config_t *c, const char *const path)
+{
+ if (!config_apply_defaults(c) || !config_load_from_path(c, path)) {
+ _E("config: Unable to initialize configuration");
+ return false;
+ }
+
+ (void)config_load_from_dir_prefix(c, path);
+
+ config_dump(c);
+
+ return true;
}
void config_free(config_t *c)
@@ -99,4 +307,9 @@ void config_free(config_t *c)
free(c->crash_root_path);
free(c->extra_script);
+ for (int i = 0; i < c->n_exclude_paths; i++)
+ free(c->exclude_paths[i]);
+ free(c->exclude_paths);
+
+ memset(c, 0, sizeof(*c));
}
diff --git a/src/shared/config.h b/src/shared/config.h
index aea42ea..99a5485 100644
--- a/src/shared/config.h
+++ b/src/shared/config.h
@@ -26,10 +26,21 @@
#define MAX_RETENTION_SEC 0
#define MAX_CRASH_DUMP 0
#define DUMP_CORE 1
+#define DUMP_SO_INFO 1
#define ALLOW_ZIP 1
+#define LEGACY_NOTIFICATION 0
+#define RELEASE_EARLY 0
#define CRASH_SECTION "CrashManager"
+/* ExcludePaths section name must be lowercase with iniparser 3.x.
+ *
+ * This is to workaround for iniparser 3.x bug, where loaded strings
+ * are converted to lowercase, but query string is not, precisely
+ * getsecnkeys() does strcmp(lowercase-key-in-db, user-provided-str).
+ */
+#define EXCLUDEPATHS_SECTION "excludepaths"
+
enum ReportType {
REP_TYPE_INVALID = -1,
REP_TYPE_INFO = 0,
@@ -40,13 +51,19 @@ enum ReportType {
typedef struct config {
bool allow_zip;
bool dump_core;
+ bool dump_so_info;
+ bool legacy_notification;
+ bool release_early;
+ enum ReportType report_type;
int system_max_use;
int system_keep_free;
int max_retention_sec;
int max_crash_dump;
- enum ReportType report_type;
+ int n_exclude_paths;
+ char **exclude_paths;
char *crash_root_path;
char *extra_script;
+
} config_t;
@@ -57,6 +74,8 @@ extern "C" {
bool config_init(config_t *c, const char *const path);
void config_free(config_t *c);
+bool config_is_path_excluded(config_t *c, const char *const path);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/shared/elf_helpers.h b/src/shared/elf_helpers.h
new file mode 100644
index 0000000..b919e7a
--- /dev/null
+++ b/src/shared/elf_helpers.h
@@ -0,0 +1,209 @@
+/* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TBRICKS
+ * AB BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THISS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+#ifndef ELF_HELPERS_H
+#define ELF_HELPERS_H
+
+#include <assert.h>
+#include <libelf.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "shared/log.h"
+
+bool elf_get_shdr(Elf *elf, Elf_Scn *scn, Elf64_Shdr *shdr)
+{
+ assert(elf);
+ assert(scn);
+ assert(shdr);
+
+ size_t ident_size;
+ char *elf_ident = elf_getident(elf, &ident_size);
+ if (elf_ident == NULL || ident_size <= EI_CLASS) {
+ _E("Cannot read ELF ident");
+ return false;
+ }
+
+ if (elf_ident[EI_CLASS] == ELFCLASS32) {
+ Elf32_Shdr *shdr32;
+ shdr32 = elf32_getshdr(scn);
+ if (shdr32 == NULL) {
+ _E("elf32_getshdr error: %s", elf_errmsg(elf_errno()));
+ return false;
+ }
+
+ shdr->sh_name = shdr32->sh_name;
+ shdr->sh_type = shdr32->sh_type;
+ shdr->sh_flags = (Elf64_Xword) shdr32->sh_flags;
+ shdr->sh_addr = (Elf64_Addr) shdr32->sh_addr;
+ shdr->sh_offset = (Elf64_Off) shdr32->sh_offset;
+ shdr->sh_size = (Elf64_Xword) shdr32->sh_size;
+ shdr->sh_link = shdr32->sh_link;
+ shdr->sh_info = shdr32->sh_info;
+ shdr->sh_addralign = (Elf64_Xword) shdr32->sh_addralign;
+ shdr->sh_entsize = (Elf64_Xword) shdr32->sh_entsize;
+ } else {
+ Elf64_Shdr *shdr64 = elf64_getshdr(scn);
+ if (shdr64 == NULL) {
+ _E("elf64_getshdr error: %s", elf_errmsg(elf_errno()));
+ return false;
+ }
+ *shdr = *shdr64;
+ }
+ return true;
+}
+
+bool elf_get_ehdr(Elf *elf, Elf64_Ehdr *ehdr)
+{
+ assert(elf);
+ assert(ehdr);
+
+ size_t ident_size;
+ char *elf_ident = elf_getident(elf, &ident_size);
+ if (elf_ident == NULL || ident_size <= EI_CLASS) {
+ _E("Cannot read ELF ident");
+ return false;
+ }
+
+ if (elf_ident[EI_CLASS] == ELFCLASS32) {
+ Elf32_Ehdr *ehdr32;
+ ehdr32 = elf32_getehdr(elf);
+ if (ehdr32 == NULL) {
+ _E("elf32_getehdr error: %s", elf_errmsg(elf_errno()));
+ return false;
+ }
+
+ (void) memcpy(ehdr->e_ident,
+ ehdr32->e_ident,
+ sizeof(ehdr32->e_ident));
+
+ ehdr->e_type = ehdr32->e_type;
+ ehdr->e_machine = ehdr32->e_machine;
+ ehdr->e_version = ehdr32->e_version;
+ ehdr->e_entry = ehdr32->e_entry;
+ ehdr->e_phoff = ehdr32->e_phoff;
+ ehdr->e_shoff = ehdr32->e_shoff;
+ ehdr->e_flags = ehdr32->e_flags;
+ ehdr->e_ehsize = ehdr32->e_ehsize;
+ ehdr->e_phentsize = ehdr32->e_phentsize;
+ ehdr->e_phnum = ehdr32->e_phnum;
+ ehdr->e_shentsize = ehdr32->e_shentsize;
+ ehdr->e_shnum = ehdr32->e_shnum;
+ ehdr->e_shstrndx = ehdr32->e_shstrndx;
+ } else {
+ Elf64_Ehdr *ehdr64 = elf64_getehdr(elf);
+ if (ehdr64 == NULL) {
+ _E("elf64_getehdr error: %s", elf_errmsg(elf_errno()));
+ return false;
+ }
+ *ehdr = *ehdr64;
+ }
+ return true;
+}
+
+bool elf_get_phdr(Elf *elf, int index, Elf64_Phdr *phdr)
+{
+ assert(elf);
+ assert(index >= 0);
+ assert(phdr);
+
+ size_t ident_size;
+ char *elf_ident = elf_getident(elf, &ident_size);
+ if (elf_ident == NULL || ident_size <= EI_CLASS) {
+ _E("Cannot read ELF ident");
+ return false;
+ }
+
+ size_t phdr_num;
+ if (elf_getphdrnum(elf, &phdr_num) == -1) {
+ _E("Cannot get program headers count");
+ return false;
+ }
+
+ if ((size_t)index >= phdr_num) {
+ _E("Index is larger than the number of program headers");
+ return false;
+ }
+
+ if (elf_ident[EI_CLASS] == ELFCLASS32) {
+ Elf32_Phdr *phdr32;
+ phdr32 = elf32_getphdr(elf);
+ if (phdr32 == NULL) {
+ _E("elf32_getphdr error: %s", elf_errmsg(elf_errno()));
+ return false;
+ }
+
+ phdr32 += index;
+
+ phdr->p_type = phdr32->p_type;
+ phdr->p_offset = phdr32->p_offset;
+ phdr->p_vaddr = (Elf64_Addr) phdr32->p_vaddr;
+ phdr->p_paddr = (Elf64_Addr) phdr32->p_paddr;
+ phdr->p_filesz = (Elf64_Xword) phdr32->p_filesz;
+ phdr->p_memsz = (Elf64_Xword) phdr32->p_memsz;
+ phdr->p_flags = phdr32->p_flags;
+ phdr->p_align = (Elf64_Xword) phdr32->p_align;
+ } else {
+ Elf64_Phdr *phdr64 = elf64_getphdr(elf);
+ if (phdr64 == NULL) {
+ _E("elf64_getphdr error: %s", elf_errmsg(elf_errno()));
+ return false;
+ }
+ phdr64 += index;
+ *phdr = *phdr64;
+ }
+ return true;
+}
+
+bool elf_get_sym(Elf *elf, Elf_Data *data, int index, Elf64_Sym *sym)
+{
+ assert(elf);
+ assert(index >= 0);
+ assert(sym);
+
+ size_t ident_size;
+ char *elf_ident = elf_getident(elf, &ident_size);
+ if (elf_ident == NULL || ident_size <= EI_CLASS) {
+ _E("Cannot read ELF ident");
+ return false;
+ }
+
+ if (elf_ident[EI_CLASS] == ELFCLASS32) {
+ Elf32_Sym *sym32 = &((Elf32_Sym *)data->d_buf)[index];
+
+ sym->st_name = sym32->st_name;
+ sym->st_info = sym32->st_info;
+ sym->st_other = sym32->st_other;
+ sym->st_shndx = sym32->st_shndx;
+ sym->st_value = sym32->st_value;
+ sym->st_size = sym32->st_size;
+ } else {
+ *sym = ((Elf64_Sym *)data->d_buf)[index];
+ }
+ return true;
+}
+#endif // ELF_HELPERS_H
diff --git a/src/shared/log.h b/src/shared/log.h
index bee783b..8ee72b2 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-
-
#ifndef __CRASH_LOG_H__
#define __CRASH_LOG_H__
@@ -25,6 +23,8 @@
#endif
#include <dlog.h>
+#include "defs.h" // for DLOG_LOG_LEVEL
+
#ifdef LOG_FILE
#include <sys/types.h>
#include <unistd.h>
@@ -52,14 +52,10 @@ static inline char __dlog_prio(int prio)
} while (0); })
#endif
-#define _D(fmt, arg...) SLOGD(fmt, ##arg)
-#define _I(fmt, arg...) SLOGI(fmt, ##arg)
-#define _W(fmt, arg...) SLOGW(fmt, ##arg)
-#define _E(fmt, arg...) SLOGE(fmt, ##arg)
-#define _SD(fmt, arg...) SECURE_SLOGD(fmt, ##arg)
-#define _SI(fmt, arg...) SECURE_SLOGI(fmt, ##arg)
-#define _SW(fmt, arg...) SECURE_SLOGW(fmt, ##arg)
-#define _SE(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
+#define _D(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_DEBUG) SLOGD(fmt, ##arg); } while (0)
+#define _I(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_INFO) SLOGI(fmt, ##arg); } while (0)
+#define _W(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_WARN) SLOGW(fmt, ##arg); } while (0)
+#define _E(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_ERROR) SLOGE(fmt, ##arg); } while (0)
#endif
/* __CRASH_LOG_H__ */
diff --git a/src/shared/util.c b/src/shared/util.c
index 6afc936..667f28e 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -134,7 +134,7 @@ int copy_file(char *dst, char *src)
dfd = open(dst, O_WRONLY|O_CREAT|O_EXCL, 0644);
if (dfd < 0) {
close(sfd);
- _SE("Failed to open (%s)\n", dst);
+ _E("Failed to open (%s)\n", dst);
return -1;
}
@@ -165,7 +165,7 @@ int dump_file_write_fd(int dfd, char *src)
}
sfd = open(src, O_RDONLY);
if (sfd < 0) {
- _SE("Failed to open (%s)\n", src);
+ _E("Failed to open (%s)\n", src);
return -1;
}
@@ -205,15 +205,16 @@ int make_dir(const char *path, const char *name, int mode)
return r == 0 || (r == -1 && errno == EEXIST) ? 0 : -1;
}
-static int remove_dir_internal(int fd)
+static bool remove_dir_internal(int fd)
{
DIR *dir;
struct dirent *de;
- int subfd, ret = 0;
+ bool ret = true;
+ int subfd = 0;
dir = fdopendir(fd);
if (!dir)
- return -1;
+ return false;
while ((de = readdir(dir))) {
if (de->d_type == DT_DIR) {
@@ -221,21 +222,21 @@ static int remove_dir_internal(int fd)
continue;
subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY);
if (subfd < 0) {
- _SE("Couldn't openat %s: %d\n", de->d_name, errno);
- ret = -1;
+ _E("Couldn't openat %s: %d\n", de->d_name, errno);
+ ret = false;
continue;
}
- if (remove_dir_internal(subfd))
- ret = -1;
+ if (!remove_dir_internal(subfd))
+ ret = false;
close(subfd);
if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) {
- _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno);
- ret = -1;
+ _E("Couldn't unlinkat %s: %d\n", de->d_name, errno);
+ ret = false;
}
} else {
if (unlinkat(fd, de->d_name, 0) < 0) {
- _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno);
- ret = -1;
+ _E("Couldn't unlinkat %s: %d\n", de->d_name, errno);
+ ret = false;
}
}
}
@@ -243,24 +244,25 @@ static int remove_dir_internal(int fd)
return ret;
}
-int remove_dir(const char *path, int del_dir)
+bool remove_dir(const char *path, bool del_dir)
{
- int fd, ret = 0;
+ bool ret = true;
+ int fd = 0;
if (!path)
- return -1;
+ return false;
fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0) {
- _SE("Couldn't opendir %s: %d\n", path, errno);
- return -errno;
+ _E("Couldn't opendir %s: %d\n", path, errno);
+ return false;
}
ret = remove_dir_internal(fd);
close(fd);
if (del_dir) {
if (rmdir(path)) {
- _SE("Couldn't rmdir %s: %d\n", path, errno);
- ret = -1;
+ _E("Couldn't rmdir %s: %d\n", path, errno);
+ ret = false;
}
}
return ret;
@@ -359,7 +361,7 @@ off_t get_directory_usage(char *path)
if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3))
continue;
if (fstatat(fd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
- _SE("Failed to fstatat %s: %d\n", de->d_name, errno);
+ _E("Failed to fstatat %s: %d\n", de->d_name, errno);
continue;
}
usage += st.st_size;
@@ -546,7 +548,7 @@ bool get_exe_path(pid_t pid, char *outbuf, size_t outbuf_len)
* (argv and envp), which can be arrays of strings as well as NULL
* pointer.
*/
-char* concatenate(char *const vec[])
+char *concatenate(char *const vec[])
{
size_t length = 0;
for (char *const *p = vec; p && *p; p++)
@@ -578,6 +580,15 @@ bool string_ends_with(const char *string, const char *suffix)
return (string_len >= suffix_len) && !strcmp(string + string_len - suffix_len, suffix);
}
+/* what for: kernel.core_pattern's %E replaces / with !, this function does opposite process */
+void kernel_exe_path_normalize(char *path)
+{
+ assert(path);
+
+ for (size_t i = 0, len = strlen(path); i < len; i++)
+ path[i] = path[i] == '!' ? '/' : path[i];
+}
+
bool file_exists(const char *path)
{
struct stat buf;
@@ -628,6 +639,27 @@ exit:
return result;
}
+bool is_dotnet_file(const char *path)
+{
+ static const char *DOTNET_EXTS[] = { ".dll", ".exe", NULL };
+
+ bool result = false;
+ size_t p_len = strlen(path);
+ while (p_len > 0 && path[p_len-1] == '\n')
+ p_len--;
+
+ for (const char **ext = DOTNET_EXTS; *ext != NULL; ext++) {
+ size_t d_len = strlen(*ext);
+
+ if ((p_len >= d_len) &&
+ (strncasecmp(&path[p_len - d_len], *ext, d_len) == 0)) {
+ result = true;
+ break;
+ }
+ }
+ return result;
+}
+
/**
* @}
*/
diff --git a/src/shared/util.h b/src/shared/util.h
index f820997..3de0ce1 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -46,7 +46,7 @@ int fsync_path(char *const path);
int make_dir(const char *path, const char *name, int mode);
-int remove_dir(const char *path, int del_dir);
+bool remove_dir(const char *path, bool del_dir);
int get_exec_pid(const char *execpath);
@@ -64,16 +64,19 @@ typedef bool (*charp0filter)(char *buf, int size, int datalen);
bool filter_drop_trailing_whitespace(char *buf, int size, int datalen);
bool read_proc_file(pid_t pid, const char * const file, char *outbuf, size_t bufsize, charp0filter filter);
-char* concatenate(char *const vec[]);
+char *concatenate(char *const vec[]);
bool string_ends_with(const char *string, const char *suffix);
+void kernel_exe_path_normalize(char *path);
+
bool file_exists(const char *path);
bool file_exists_in_dir(const char *dir_path, const char *file_name);
bool write_to_file(const char *content, const char *base_dir, const char *file_name);
+bool is_dotnet_file(const char *path);
#ifdef __cplusplus
}
#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6c4d658..2c5baf5 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
+add_subdirectory(system)
+
# tests
INCLUDE(FindPkgConfig)
diff --git a/tests/system/CMakeLists.txt b/tests/system/CMakeLists.txt
index 95e4474..e8661a1 100644
--- a/tests/system/CMakeLists.txt
+++ b/tests/system/CMakeLists.txt
@@ -4,7 +4,8 @@ ADD_SUBDIRECTORY(utils)
macro(CONFIGURE_TEST_FILE dir_name file_name)
configure_file("${dir_name}/${file_name}.sh.template" "${dir_name}/${file_name}.sh" @ONLY)
- INSTALL(DIRECTORY ${dir_name}/ DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/${dir_name} FILES_MATCHING PATTERN "*sh")
+ INSTALL(DIRECTORY ${dir_name}/ DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/${dir_name} FILES_MATCHING PATTERN "*sh"
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endmacro()
macro(CONFIGURE_TEST test_name)
@@ -17,23 +18,31 @@ macro(CONFIGURE_TEST test_name)
endmacro()
configure_test("check_minicore_mem")
-configure_test("time_test")
+configure_test("clean_temp")
configure_test("cmp_backtraces" "cp")
+configure_test("copy_tizen_manifest")
+configure_test("crash_root_path")
configure_test("critical_process")
-configure_test("wait_for_opt_usr")
+configure_test("dbus_notify")
+configure_test("dbus_notify_legacy")
+configure_test("dump_systemstate_extras")
+configure_test("exclude_paths")
+configure_test("extra_script")
+configure_test("full_core")
configure_test("info_file")
+configure_test("libcrash-service")
+configure_test("livedumper")
configure_test("log_file")
-configure_test("so_info_file")
+configure_test("output_param")
configure_test("report_basic")
configure_test("report_type_info")
+configure_test("so_info_file")
+configure_test("temp_lock")
+configure_test("time_test")
+configure_test("wait_for_opt_usr")
configure_test("without_core")
-configure_test("crash_root_path")
-configure_test("dump_systemstate_extras")
-configure_test("livedumper")
-configure_test("extra_script")
-configure_test("dbus_notify")
-configure_test("output_param")
-configure_test("libcrash-service")
+configure_test("without_so_info_file")
configure_file("run.sh.template" "run.sh" @ONLY)
-INSTALL(FILES run.sh DESTINATION ${CRASH_SYSTEM_TESTS_PATH})
+INSTALL(FILES "run.sh" DESTINATION bin RENAME crash-worker-system-tests-run
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
diff --git a/tests/system/clean_temp/clean_temp.sh.template b/tests/system/clean_temp/clean_temp.sh.template
new file mode 100644
index 0000000..9e6d615
--- /dev/null
+++ b/tests/system/clean_temp/clean_temp.sh.template
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+# Check if the temp directory will be cleaned up
+
+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
+
+TEST_TMP_DIR="${CRASH_TEMP_PATH}"/tmp1
+mkdir "${TEST_TMP_DIR}"
+echo "test" > "${TEST_TMP_DIR}"/some_file
+
+${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
+pid=$!
+sleep 2
+kill -6 $pid
+
+sleep 1
+
+wait_for_app crash-manager || fail "crash-manager is still working"
+
+if [ -d "${TEST_TMP_DIR}" ]; then
+ fail "temp directory still exists"
+fi
+
+exit_ok
diff --git a/tests/system/cmp_backtraces/cmp_backtraces.sh.template b/tests/system/cmp_backtraces/cmp_backtraces.sh.template
index 417cadd..5795397 100755
--- a/tests/system/cmp_backtraces/cmp_backtraces.sh.template
+++ b/tests/system/cmp_backtraces/cmp_backtraces.sh.template
@@ -44,8 +44,14 @@ wait_for_app minicoredumper
untar_file ${BASE_DIR} ${CORE_MINI}.tar
-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}
+# We want to compare if the call stack from the original dump is the same as
+# the one from the minidump. GDB can also sometimes display the type of
+# argument based on the data stored in the heap. Unfortunately, the minidump does
+# not contain heap, and this causes differences in result. Therefore, the GDB
+# result is filtered so that we can compare the two call stacks.
+
+gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_ORIG} -ex "thread apply all bt" -ex "q" 2> /dev/null | grep -e '^#' | sed 's/: [0-9]\+\(x[0-9]\+\( <[^>]\+>\)\?\)\?/: 0/g' > ${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 '^#' | sed 's/: [0-9]\+\(x[0-9]\+\( <[^>]\+>\)\?\)\?/: 0/g' > ${BASE_DIR}/${THREADS_MINI}
if ! diff ${BASE_DIR}/${THREADS_ORIG} ${BASE_DIR}/${THREADS_MINI} > /dev/null; then
fail "backtraces are different"
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
diff --git a/tests/system/crash_root_path/crash_root_path.sh.template b/tests/system/crash_root_path/crash_root_path.sh.template
index 0f59b55..7fe5e96 100644
--- a/tests/system/crash_root_path/crash_root_path.sh.template
+++ b/tests/system/crash_root_path/crash_root_path.sh.template
@@ -8,7 +8,9 @@ fi
. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
-CRASH_MANAGER_CONF=/etc/crash-manager.conf
+CONF_DIR=/etc/crash-manager.conf.d
+CONF_FILE=${CONF_DIR}/crash-root-path-test.conf
+
NEW_PATH=/tmp/crash_path_test/
if [ ! -d ${NEW_PATH} ]; then
mkdir ${NEW_PATH}
@@ -23,8 +25,13 @@ function check_file_exists {
}
mount -o rw,remount /
-backup_file ${CRASH_MANAGER_CONF}
-cat ${CRASH_MANAGER_CONF}.backup | sed "s|#[ ]\+CrashRootPath=.*|CrashRootPath=${NEW_PATH}|" > ${CRASH_MANAGER_CONF}
+
+mkdir -p $CONF_DIR
+rm -f $CONF_FILE || :
+cat <<EOF >$CONF_FILE
+[CrashManager]
+CrashRootPath=${NEW_PATH}
+EOF
{
${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
@@ -34,10 +41,10 @@ cat ${CRASH_MANAGER_CONF}.backup | sed "s|#[ ]\+CrashRootPath=.*|CrashRootPath=$
sleep 2
-restore_file ${CRASH_MANAGER_CONF}
-
wait_for_app crash-manager
+rm -f ${CONF_FILE} || :
+
pushd ${NEW_PATH}/dump
if ! unzip kenny*zip > /dev/null; then
popd
diff --git a/tests/system/dbus_notify_legacy/dbus_notify_legacy.sh.template b/tests/system/dbus_notify_legacy/dbus_notify_legacy.sh.template
new file mode 100644
index 0000000..946e9c3
--- /dev/null
+++ b/tests/system/dbus_notify_legacy/dbus_notify_legacy.sh.template
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+# Check the support for old-style DBus notification signal
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+ CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+# We are looking for following signal - example for `sleep` command:
+#
+# signal time=1420079847.594970 sender=:1.82 -> destination=(null destination) serial=2 path=/Org/Tizen/System/Crash/Crash; interface=org.tizen.system.crash.Crash; member=ProcessCrashed
+# string "sleep"
+# string "/usr/bin/sleep"
+# string "sleep"
+# string "sleep"
+#
+# Note! Regular programs (Unix sleep, tests-provided kenny) are not enough to check all fields of the signal.
+# Complete test, with appid & pkgid checks, would require building proper "Tizen Application".
+
+CONF_DIR=/etc/crash-manager.conf.d
+CONF_FILE=${CONF_DIR}/system-test-dbus-notify-legacy.conf
+
+mount -o rw,remount /
+
+mkdir -p $CONF_DIR
+rm -f $CONF_FILE || :
+cat <<EOF >$CONF_FILE
+[CrashManager]
+UseLegacyNotification=true
+EOF
+
+( ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
+ pid=$!
+ sleep 2
+ kill -6 $pid ) &
+
+TMPFILE=$(mktemp /tmp/dbus_notify.XXXXXX)
+dbus-monitor --system type=signal,path=/Org/Tizen/System/Crash/Crash,interface=org.tizen.system.crash.Crash,member=ProcessCrashed > $TMPFILE &
+monpid=$!
+
+cleanup()
+{
+ kill $monpid
+ rm -f $TMPFILE
+ rm -f $CONF_FILE
+}
+
+trap cleanup 0
+
+sleep 3
+
+PATTERN='path=/Org/Tizen/System/Crash/Crash; interface=org\.tizen\.system\.crash\.Crash; member=ProcessCrashed'
+for i in $(seq 1 10); do
+ score=0
+ if egrep "$PATTERN" $TMPFILE; then
+ if egrep "string \"kenny" $TMPFILE; then
+ score=$(($score + 1))
+ fi
+
+ # legacy signal must not have the report_path and additional metadata
+
+ if ! egrep "string \"/opt/usr/share/crash/dump.*kenny" $TMPFILE; then
+ score=$(($score + 1))
+ fi
+
+ if ! egrep -A1 "string \"sys.signal" $TMPFILE; then
+ score=$(($score + 1))
+ fi
+
+ if [ $score -eq 3 ]; then
+ exit_ok
+ fi
+ fi
+
+ sleep 1
+done
+
+fail "legacy dbus signal does not match"
diff --git a/tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template b/tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template
index 41e270f..391cf4c 100644
--- a/tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template
+++ b/tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template
@@ -47,12 +47,33 @@ args=magic_cookie is $cookie1
title=/bin/env test
path=/bin/env
env=MAGIC_SECRET=$cookie2
+
+[44]
+order=50
+title=FOO
+path=/foo
+
+[55]
+order=40
+title=BAR
+path=/bar
+
+[33]
+order=60
+title=QUUX
+path=/quux
EOF
cat > /etc/dump_systemstate.conf.d/files/dump_systemstate_extras_system_test.conf <<EOF
[File1]
+order=99
title=file for cookie3
path=$cookie3_tmpfile
+
+[File2]
+order=1
+title=first_file
+path=/nonexistent
EOF
dump_systemstate -e > $tmpfile
@@ -61,4 +82,9 @@ do_check $tmpfile "==== $cookie1" 1 "^magic_cookie is $cookie1"
do_check $tmpfile "==== /bin/env test" 999 "^MAGIC_SECRET=$cookie2"
do_check $tmpfile "==== file for cookie3" 1 "^$cookie3"
+# ordering checks
+do_check $tmpfile "==== first_file" 6 "^==== file for cookie3"
+do_check $tmpfile "==== BAR" 6 "^==== FOO"
+do_check $tmpfile "==== FOO" 6 "^==== QUUX"
+
exit_ok
diff --git a/tests/system/exclude_paths/exclude_paths.sh.template b/tests/system/exclude_paths/exclude_paths.sh.template
new file mode 100644
index 0000000..f3742af
--- /dev/null
+++ b/tests/system/exclude_paths/exclude_paths.sh.template
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+ CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+CONF_DIR=/etc/crash-manager.conf.d
+CONF_FILE=${CONF_DIR}/crash-root-exclude-list.conf
+
+mount -o rw,remount /
+
+mkdir -p $CONF_DIR
+rm -f $CONF_FILE || :
+
+cat <<EOF >$CONF_FILE
+[ExcludePaths]
+e1=${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny
+EOF
+
+cleanup()
+{
+ rm -f $CONF_FILE
+}
+trap cleanup 0
+
+clean_crash_dump
+
+{
+ ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
+ sleep 1
+ kill -6 $!
+} 1> /dev/null 2>&1
+
+sleep 1
+
+wait_for_app crash-manager
+
+for i in $(seq 1 10); do
+ [ ${CRASH_DUMP_PATH}/kenny_* == "${CRASH_DUMP_PATH}/kenny_*" ] || fail "Crash dump exists for process added to exclude list"
+
+ sleep 1
+done
+
+exit_ok
diff --git a/tests/system/full_core/full_core.sh.template b/tests/system/full_core/full_core.sh.template
new file mode 100755
index 0000000..5d5595f
--- /dev/null
+++ b/tests/system/full_core/full_core.sh.template
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# Check the full coredump
+
+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_dump
+
+MINICOREDUMPER_DIR=/etc/minicoredumper/
+CONFIG_FILE=${MINICOREDUMPER_DIR}/generic.recept.json
+ORIG_CONFIG_FILE=$(readlink ${CONFIG_FILE})
+FULLCORE_CONFIG_FILE=${MINICOREDUMPER_DIR}/generic-fullcore.recept.json
+BACKUP_CONFIG_FILE=/tmp/generic.recept.json
+
+function modify_config {
+ ln -sf ${FULLCORE_CONFIG_FILE} ${CONFIG_FILE}
+}
+
+function restore {
+ ln -sf ${ORIG_CONFIG_FILE} ${CONFIG_FILE}
+ popd
+}
+
+trap restore 0
+pushd ${CRASH_DUMP_PATH}
+
+modify_config
+
+{
+ ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
+ sleep 1
+ kill -6 $!
+} 1> /dev/null 2>&1
+
+sleep 2
+
+wait_for_file ${CRASH_DUMP_PATH}/*kenny*zip
+
+unzip ${CRASH_DUMP_PATH}/*kenny*zip
+
+RESULT=`gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${CRASH_DUMP_PATH}/*kenny*/kenny*coredump --batch -ex "thread apply all bt"`
+
+check "MAGICNAME.*id=.*kenny.cpp:31"
+check "run.*id=.*kenny.cpp:56"
+
+exit_ok
diff --git a/tests/system/libcrash-service/libcrash-service.sh.template b/tests/system/libcrash-service/libcrash-service.sh.template
index 611978a..97b81cf 100755
--- a/tests/system/libcrash-service/libcrash-service.sh.template
+++ b/tests/system/libcrash-service/libcrash-service.sh.template
@@ -29,8 +29,6 @@ wait_for_file ${LIVE_DUMP_PATH}/kenny*zip
kill -9 ${KENNY_PID}
-trap popd 0
-
pushd ${LIVE_DUMP_PATH}
unzip kenny*zip
diff --git a/tests/system/log_file/log_file.sh.template b/tests/system/log_file/log_file.sh.template
index d684c2d..436fa41 100644
--- a/tests/system/log_file/log_file.sh.template
+++ b/tests/system/log_file/log_file.sh.template
@@ -65,7 +65,8 @@ 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 "==== System configuration.*dump memory" 10
+check_section "==== System configuration.*dump system" 10
check_section "==== Kernel messages" 10
check_section "==== Log messages" 10
check_section "==== Journal messages" 10
diff --git a/tests/system/report_basic/report_basic.sh.template b/tests/system/report_basic/report_basic.sh.template
index 18d7836..e78ad12 100644
--- a/tests/system/report_basic/report_basic.sh.template
+++ b/tests/system/report_basic/report_basic.sh.template
@@ -18,6 +18,8 @@ pid=$!
sleep 2
kill -6 $pid
+sleep 2
+
wait_for_app crash-manager
pushd ${CRASH_DUMP_PATH}
diff --git a/tests/system/so_info_file/so_info_file.sh.template b/tests/system/so_info_file/so_info_file.sh.template
index d8437ac..23cd7d9 100644
--- a/tests/system/so_info_file/so_info_file.sh.template
+++ b/tests/system/so_info_file/so_info_file.sh.template
@@ -35,7 +35,7 @@ popd
RESULT=$(cat ${CRASH_DUMP_PATH}/${REPORT_DIR}/${REPORT_DIR}.so_info)
-check "utils/kenny [a-z0-9]+ crash-worker_system-tests;[^;]+;[^;]+;[a-z0-9]+"
+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]+"
diff --git a/tests/system/temp_lock/temp_lock.sh.template b/tests/system/temp_lock/temp_lock.sh.template
new file mode 100644
index 0000000..08b9f1c
--- /dev/null
+++ b/tests/system/temp_lock/temp_lock.sh.template
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# 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_dump
+clean_temp
+
+${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
+pid=$!
+sleep 2
+kill -6 $pid
+
+sleep 1
+
+pushd ${CRASH_TEMP_PATH}
+wait_for_dir $(echo *) || fail "temp directory not exists"
+name=$(echo *)
+
+flock -n -x "${name}" echo
+
+if [ $? == 0 ]; then
+ fail "temp directory is not locked"
+fi
+
+if [ ! -d "${name}" ]; then
+ fail "temp directory no longer exists"
+fi
+
+exit_ok
diff --git a/tests/system/utils/CMakeLists.txt b/tests/system/utils/CMakeLists.txt
index 5bd6710..0d2bbe4 100644
--- a/tests/system/utils/CMakeLists.txt
+++ b/tests/system/utils/CMakeLists.txt
@@ -12,11 +12,10 @@ add_executable(libcrash-servicetest libcrash-servicetest.c)
INCLUDE(FindPkgConfig)
pkg_check_modules(helper_pkgs REQUIRED
- crash-service
gio-2.0
dlog)
-TARGET_LINK_LIBRARIES(libcrash-servicetest crash-service ${helper_pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(libcrash-servicetest libcrash-service ${helper_pkgs_LDFLAGS})
install(TARGETS kenny DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/utils)
install(TARGETS btee DESTINATION ${CRASH_SYSTEM_TESTS_PATH}/utils)
diff --git a/tests/system/utils/minicore-utils.sh b/tests/system/utils/minicore-utils.sh
index dd64a99..2805d54 100644
--- a/tests/system/utils/minicore-utils.sh
+++ b/tests/system/utils/minicore-utils.sh
@@ -118,6 +118,19 @@ function wait_for_file {
return 0
}
+function wait_for_dir {
+ TIMEOUT=240
+ while [ ! -d ${1} ];
+ do
+ if endoftime; then
+ fail "${1} does not exist"
+ else
+ sleep 1
+ fi
+ done
+ return 0
+}
+
function wait_for_app {
TIMEOUT=240
while true;
diff --git a/tests/system/without_so_info_file/without_so_info_file.sh.template b/tests/system/without_so_info_file/without_so_info_file.sh.template
new file mode 100644
index 0000000..038e773
--- /dev/null
+++ b/tests/system/without_so_info_file/without_so_info_file.sh.template
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+# Checks ability to disable .so_info
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+ CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+CONF_DIR=/etc/crash-manager.conf.d
+CONF_FILE=${CONF_DIR}/crash-worker-without-so-info.conf
+
+mount -o rw,remount /
+
+mkdir -p $CONF_DIR
+rm -f $CONF_FILE || :
+cat <<EOF >$CONF_FILE
+[CrashManager]
+DumpSharedObjectInfo=0
+EOF
+
+clean_crash_dump
+
+{
+ ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny &
+ sleep 1
+ kill -6 $!
+} 1> /dev/null 2>&1
+
+sleep 2
+
+wait_for_app crash-manager
+
+rm -f ${CONF_FILE} || :
+
+test -f ${CRASH_DUMP_PATH}/kenny*zip || fail "crash report not created"
+unzip -l ${CRASH_DUMP_PATH}/kenny*zip | egrep 'kenny*/kenny*.so_info$' && fail ".so_info file found despite being disabled in config"
+
+exit_ok