crash-manager: add minicoredumper 75/170975/13
authorMateusz Moscicki <mmoscicki2@partner.samsung.com>
Thu, 22 Feb 2018 09:45:37 +0000 (10:45 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Mon, 18 Jun 2018 12:29:42 +0000 (14:29 +0200)
minicoredumper strips unnecessary data from coredump
and makes use of sparse file mechanism, to quickly save
core files on disc.

Change-Id: Ic8e968b5e7a011f9a06794876c372063e968a354

CMakeLists.txt
packaging/crash-worker.spec
src/crash-manager/CMakeLists.txt
src/crash-manager/crash-manager.c
src/crash-manager/crash-manager.h.in

index d55fc2b..f6e47cb 100644 (file)
@@ -10,7 +10,10 @@ IF("${SYS_ASSERT}" STREQUAL "ON")
        ADD_SUBDIRECTORY(src/sys-assert)
 ENDIF("${SYS_ASSERT}" STREQUAL "ON")
 
-ADD_SUBDIRECTORY(src/crash-pipe)
+IF(TIZEN_ENABLE_COREDUMP STREQUAL on)
+       ADD_SUBDIRECTORY(src/crash-pipe)
+ENDIF()
+
 IF(TIZEN_FEATURE_PTRACE_CALLSTACK STREQUAL on)
        ADD_SUBDIRECTORY(src/crash-stack)
 ENDIF()
index 0584e3e..d4743e3 100644 (file)
@@ -3,6 +3,7 @@
 
 %define _with_tests on
 %define TIZEN_FEATURE_PTRACE_CALLSTACK on
+%define TIZEN_FEATURE_MINICOREDUMPER on
 %bcond_with doc
 %bcond_with sys_assert
 %bcond_with tests
@@ -39,6 +40,10 @@ Requires(post): gzip
 Requires: zip
 Requires: libelf
 Requires: libdw
+
+%if "%{TIZEN_FEATURE_MINICOREDUMPER}" == "on"
+Requires: /sbin/minicoredumper
+%endif
 # If you need support for core dump files (see building below),
 # you should add this dependency
 # Requires: libebl
@@ -85,7 +90,6 @@ cp %{SOURCE1001} .
 
 export CFLAGS+=" -Werror"
 export CFLAGS+=" -DTIZEN_ENGINEER_MODE"
-export CFLAGS+=" -DTIZEN_ENABLE_COREDUMP"
 
 %ifarch %{arm} aarch64
        %define ARCH arm
@@ -110,7 +114,14 @@ export CFLAGS+=" -DTIZEN_ENABLE_COREDUMP"
           -DCRASH_PATH=%{crash_path} \
           -DCRASH_TEMP=%{crash_temp} \
           -DDEBUGMODE_PATH=%{debugmode_path} \
+%if "%{TIZEN_FEATURE_MINICOREDUMPER}" == "on"
+          -DTIZEN_ENABLE_MINICOREDUMP=on \
+          -DMINICOREDUMPER_PATH=%{_sbindir}/minicoredumper \
+          -DMINICOREDUMPER_CONF_DIR=%{_sysconfdir}/minicoredumper \
+%else
+          -DTIZEN_ENABLE_COREDUMP=on \
           -DCRASH_PIPE_PATH=%{_libexecdir}/crash-pipe \
+%endif
 %if "%{TIZEN_FEATURE_PTRACE_CALLSTACK}" == "on"
           -DCRASH_STACK_PATH=%{_libexecdir}/crash-stack \
 %endif
@@ -188,7 +199,9 @@ sed -i "/${pattern}/D" %{_sysconfdir}/ld.so.preload
 %{_sysconfdir}/tmpfiles.d/sys-assert.conf
 %endif
 
+%if "%{TIZEN_FEATURE_MINICOREDUMPER}" != "on"
 %{_libexecdir}/crash-pipe
+%endif
 %if "%{TIZEN_FEATURE_PTRACE_CALLSTACK}" == "on"
 %{_libexecdir}/crash-stack
 %endif
index db1c99b..d95e846 100644 (file)
@@ -5,6 +5,14 @@ IF(TIZEN_FEATURE_PTRACE_CALLSTACK STREQUAL on)
        ADD_DEFINITIONS(-DTIZEN_FEATURE_PTRACE_CALLSTACK)
 ENDIF()
 
+IF(TIZEN_ENABLE_COREDUMP STREQUAL on)
+        ADD_DEFINITIONS(-DTIZEN_ENABLE_COREDUMP)
+ENDIF()
+
+IF(TIZEN_ENABLE_MINICOREDUMP STREQUAL on)
+        ADD_DEFINITIONS(-DTIZEN_ENABLE_MINICOREDUMP)
+ENDIF()
+
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
 SET(CRASH_MANAGER_SRCS
        crash-manager.c
@@ -26,7 +34,11 @@ ENDFOREACH(flag)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
 
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_ENABLE_COREDUMP")
+IF(TIZEN_ENABLE_COREDUMP AND TIZEN_ENABLE_MINICOREDUMP)
+        message(FATAL_ERROR "You can not define TIZEN_ENABLE_COREDUMP and TIZEN_ENABLE_MINICOREDUMP at once.")
+ENDIF()
+
+IF(TIZEN_ENABLE_COREDUMP OR TIZEN_ENABLE_MINICOREDUMP)
         OPTION(USE_COREDUMP_CONF "Use COREDUMP CONF" ON)
 ENDIF()
 
index 8012e48..172327c 100644 (file)
@@ -43,6 +43,7 @@
 
 /* Parsing */
 #define CRASH_CONF_FILE      tzplatform_mkpath(TZ_SYS_ETC, "crash-manager.conf")
+#define MINICOREDUMPER_CONF_FILE       MINICOREDUMPER_CONF_DIR "/minicoredumper.cfg.json"
 #define KEY_MAX              255
 #define CRASH_SECTION        "CrashManager"
 
@@ -62,6 +63,8 @@
 
 #define CRASH_CHECK_DISK_PATH "/opt/usr"
 
+#define MINICOREDUMPER_TIMEOUT 12*60
+
 enum {
        RET_EXCEED = 1,
        NUM_EXCEED,
@@ -393,7 +396,7 @@ static int get_sysassert_cs(void)
 }
 #endif
 
-#ifdef TIZEN_ENABLE_COREDUMP
+#if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_ENABLE_MINICOREDUMP)
 static void launch_crash_popup(void)
 {
        GDBusConnection *conn;
@@ -478,17 +481,21 @@ static void save_so_info()
 static void execute_crash_modules(int argc, char *argv[])
 {
 
-#if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_FEATURE_PTRACE_CALLSTACK)
+#if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_ENABLE_MINICOREDUMP) || defined(TIZEN_FEATURE_PTRACE_CALLSTACK)
        int ret;
        char command[PATH_MAX];
 #endif
 
+       _D("Execute crash module: ");
 #ifdef TIZEN_ENABLE_COREDUMP
        /* Execute crash-pipe */
        ret = snprintf(command, sizeof(command),
                        "%s --save-core %s",
                        CRASH_PIPE_PATH,
                        crash_info.core_path);
+
+       _D("    %s", command);
+
        if (ret < 0) {
                _E("Failed to snprintf for crash-pipe command");
                return;
@@ -496,6 +503,37 @@ static void execute_crash_modules(int argc, char *argv[])
        system_command(command);
 #endif
 
+
+#ifdef TIZEN_ENABLE_MINICOREDUMP
+       char *coredump_name = NULL;
+       if (asprintf(&coredump_name, "%s.coredump", crash_info.name) == -1)
+               coredump_name = strdup("core");
+
+       /* Execute minicoredumper */
+       char *args[] = {
+                       MINICOREDUMPER_PATH,       // minicoredumper filename path
+                       crash_info.pid_info,       // %p - pid
+                       argv[2],                   // %u - UID
+                       argv[3],                   // %g - GID
+                       crash_info.sig_info,       // %s - number of signal
+                       argv[5],                   // %t - time of dump
+                       "localhost",               // %h - hostname
+                       "core",                    // %e - exe name (need for result filename)
+                       MINICOREDUMPER_CONF_FILE,  // config file
+                       "-d",
+                       crash_info.pfx,            // temp dir
+                       "-o",
+                       coredump_name,             // coredump filename
+                       NULL
+                       };
+
+       _D("    %s", args[0]);
+
+       run_command_timeout(args[0], args, NULL, MINICOREDUMPER_TIMEOUT);
+
+       free(coredump_name);
+#endif
+
 #ifdef TIZEN_FEATURE_PTRACE_CALLSTACK
 
 # ifdef SYS_ASSERT
@@ -818,7 +856,7 @@ int main(int argc, char *argv[])
 {
        /* Execute dump_systemstate in parallel */
        static int dump_state_pid;
-#ifdef TIZEN_ENABLE_COREDUMP
+#if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_ENABLE_MINICOREDUMP)
        int debug_mode = access(DEBUGMODE_PATH, F_OK) == 0;
 #endif
 
@@ -862,7 +900,7 @@ int main(int argc, char *argv[])
                compress();
        else
                move_dump_dir();
-#ifdef TIZEN_ENABLE_COREDUMP
+#if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_ENABLE_MINICOREDUMP)
        /* launch crash-popup only if the .debugmode file is exist*/
        if (debug_mode)
                launch_crash_popup();
index 7a4089e..84c9775 100644 (file)
@@ -27,6 +27,8 @@
 #define CRASH_STACK_PATH "@CRASH_STACK_PATH@"
 #endif
 #define CRASH_PIPE_PATH  "@CRASH_PIPE_PATH@"
+#define MINICOREDUMPER_PATH  "@MINICOREDUMPER_PATH@"
+#define MINICOREDUMPER_CONF_DIR  "@MINICOREDUMPER_CONF_DIR@"
 #define DEBUGMODE_PATH   "@DEBUGMODE_PATH@"
 
 #endif