Several modifications for backward compatibility 53/98853/3
authorSunmin Lee <sunm.lee@samsung.com>
Mon, 21 Nov 2016 05:03:36 +0000 (14:03 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Thu, 24 Nov 2016 02:44:11 +0000 (11:44 +0900)
1) Change log_dump dbus path and interface.
2) Add delete_dump option to log_dump's dbus interface.
3) Move log_dump's result from CRASH_ROOT to LOG_DUMP_RESULT.
4) tizen-debug on/off services are added.

Change-Id: I0257537ad69b524714370c1ecfa11cc9d942a560
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
packaging/crash-worker.spec
src/log_dump/CMakeLists.txt
src/log_dump/dbus-handler.c
src/log_dump/log_dump.c
src/log_dump/log_dump.h.in [moved from src/log_dump/log_dump.h with 67% similarity]
src/sys-assert/CMakeLists.txt
src/sys-assert/tizen-debug-off.service [new file with mode: 0644]
src/sys-assert/tizen-debug-on.service [new file with mode: 0644]

index 6c5101f..b94edff 100644 (file)
@@ -101,14 +101,14 @@ mkdir -p %{buildroot}%{crash_temp}
 mkdir -p %{buildroot}%{crash_all_log}
 mkdir -p %{buildroot}%{crash_dump_gen}
 cp dump_scripts/* %{buildroot}%{crash_dump_gen}
+chmod 755 %{buildroot}%{crash_dump_gen}/*
 
 %if "%{eng_mode}" == "on"
 install -m 644 src/crash-manager/debugmode %{buildroot}%{eng_mode_path}/.debugmode
 %endif
 
-%if "%{?sys_assert}" == "on"
-
 %post
+%if "%{?sys_assert}" == "on"
 if [ ! -d /.build ]; then
        orig="%{_libdir}/libsys-assert.so"
        pattern=$(echo $orig | sed -e 's|/|\\/|g')
@@ -119,17 +119,21 @@ if [ ! -d /.build ]; then
        chmod 644 %{_sysconfdir}/ld.so.preload
 fi
 
+/sbin/ldconfig
+%endif
+
 /usr/bin/chsmack -a "System::Shared" -t %{crash_path}
 /usr/bin/chsmack -a "System::Shared" -t %{crash_temp}
-
-/sbin/ldconfig
+/usr/bin/chsmack -a "System::Shared" -t %{crash_dump_gen}
+/usr/bin/chsmack -a "System::Shared" -t %{crash_dump_gen}/module.d
+/usr/bin/chsmack -d %{crash_dump_gen}/module.d/*
 
 %postun
+%if "%{?sys_assert}" == "on"
 orig="%{_libdir}/libsys-assert.so"
 pattern=$(echo $orig | sed -e 's|/|\\/|g')
 sed -i "/${pattern}/D" %{_sysconfdir}/ld.so.preload
 /sbin/ldconfig
-
 %endif
 
 %files
@@ -144,6 +148,8 @@ sed -i "/${pattern}/D" %{_sysconfdir}/ld.so.preload
 %attr(0755,system,system) %{_bindir}/dump_systemstate
 %attr(0755,system,system) %{_bindir}/crash-manager.sh
 %attr(0755,system,system) %{_bindir}/log_dump
+%attr(0644,root,system) %{_unitdir}/tizen-debug-on.service
+%attr(0644,root,system) %{_unitdir}/tizen-debug-off.service
 %{_prefix}/lib/sysctl.d/99-crash-manager.conf
 %{_datadir}/dbus-1/system-services/org.tizen.system.crash.service
 
index 8124a79..1d6d220 100644 (file)
@@ -23,6 +23,7 @@ ENDFOREACH(flag)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
 
+CONFIGURE_FILE(log_dump.h.in log_dump.h @ONLY)
 ADD_EXECUTABLE(${PROJECT_NAME} ${LOG_DUMP_SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${log_dump_pkgs_LDFLAGS} -pie)
 
index adfe7ac..db87328 100644 (file)
@@ -23,7 +23,7 @@
 #include "dbus-handler.h"
 
 #define CRASH_BUS_NAME "org.tizen.system.crash"
-#define CRASH_BUS_PATH "/Org/Tizen/System/Crash"
+#define CRASH_BUS_PATH "/Org/Tizen/System/Crash/Crash"
 
 #define TIMEOUT_INTERVAL 30
 
@@ -33,11 +33,12 @@ static guint timeout_id;
 static GDBusNodeInfo *introspection_data;
 static const gchar introspection_xml[] =
 "<node>"
-" <interface name='org.tizen.system.crash'>"
-"  <method name='normal_dump'>"
+" <interface name='org.tizen.system.crash.Crash'>"
+"  <method name='dump_log'>"
+"   <arg type='s' name='arg' direction='in'/>"
 "   <arg type='i' name='response' direction='out'/>"
 "  </method>"
-"  <method name='short_dump'>"
+"  <method name='delete_dump'>"
 "   <arg type='i' name='response' direction='out'/>"
 "  </method>"
 " </interface>"
@@ -86,17 +87,22 @@ static void method_call_handler(GDBusConnection *conn,
                                gpointer user_data)
 {
        int ret = -1;
-       int option = -1;
+       const gchar *arg;
 
        remove_timeout();
 
-       if (g_strcmp0(method_name, "normal_dump") == 0)
-               option = OPT_NORMAL;
-       else if (g_strcmp0(method_name, "short_dump") == 0)
-               option = OPT_SHORT;
+       if (g_strcmp0(method_name, "dump_log") == 0) {
+               g_variant_get(parameters, "(&s)", &arg);
+               if (g_strcmp0(arg, "normal") == 0)
+                       ret = log_dump(OPT_NORMAL);
+               else if (g_strcmp0(arg, "short") == 0)
+                       ret = log_dump(OPT_SHORT);
+               else
+                       LOGE("Wrong option for log_dump");
+       } else if (g_strcmp0(method_name, "delete_dump") == 0) {
+               ret = delete_dump();
+       }
 
-       if (option >= 0)
-               ret = log_dump(option);
        g_dbus_method_invocation_return_value(invocation,
                        g_variant_new("(i)", ret));
 
index 8459e73..228112f 100644 (file)
 #include <dirent.h>
 #include <libgen.h>
 #include <system_info.h>
-#include <tzplatform_config.h>
 #include "shared/util.h"
 #include "log_dump.h"
 #include "dbus-handler.h"
 
 #undef LOG_TAG
 #define LOG_TAG          "LOG_DUMP"
-#define LOG_DUMP_ROOT    tzplatform_getenv(TZ_SYS_CRASH_ROOT)
-#define LOG_DUMP_DIR     tzplatform_getenv(TZ_SYS_ALLLOGS)
-#define CRASH_DUMP_DIR   tzplatform_getenv(TZ_SYS_CRASH)
-#define DUMP_SCRIPTS_DIR tzplatform_getenv(TZ_SYS_DUMPGEN)
 #define SYSTEM_INFO_KEY_BUILD_STRING "http://tizen.org/system/build.string"
 
 static const struct option opts[] = {
@@ -65,7 +60,7 @@ static int dump_scripts(void)
 
        script_num = scandir(DUMP_SCRIPTS_DIR, &dir_list, NULL, NULL);
        if (script_num < 0) {
-               LOGE("Failed to scandir");
+               LOGE("Failed to scandir %s",DUMP_SCRIPTS_DIR);
                return -1;
        }
 
@@ -110,6 +105,17 @@ int log_dump(int option)
                system_command(command);
        }
 
+       /* Make result directory */
+       if (access(LOG_DUMP_RESULT, F_OK) != 0) {
+               ret = snprintf(command, sizeof(command),
+                               "/usr/bin/mkdir -p %s", LOG_DUMP_RESULT);
+               if (ret < 0) {
+                       LOGE("Failed to mkdir");
+                       return -1;
+               }
+               system_command(command);
+       }
+
        /* Get timestamp */
        cur_time = time(NULL);
        localtime_r(&cur_time, &loc_tm);
@@ -169,7 +175,7 @@ int log_dump(int option)
 
                ret = snprintf(command, sizeof(command),
                                "/bin/tar -zcf %s/%s%s.tar.gz -C %s %s %s",
-                               LOG_DUMP_ROOT, dump_filename, timestr,
+                               LOG_DUMP_RESULT, dump_filename, timestr,
                                LOG_DUMP_ROOT, basename(dump_dirname),
                                basename(crash_dirname));
                if (ret < 0) {
@@ -179,7 +185,7 @@ int log_dump(int option)
        } else {
                ret = snprintf(command, sizeof(command),
                                "/bin/tar -zcf %s/%s%s.tar.gz -C %s %s",
-                               LOG_DUMP_ROOT, dump_filename, timestr,
+                               LOG_DUMP_RESULT, dump_filename, timestr,
                                LOG_DUMP_ROOT, basename(dump_dirname));
                if (ret < 0) {
                        LOGE("Failed to snprintf for command");
@@ -217,6 +223,18 @@ exit:
        return ret;
 }
 
+int delete_dump(void)
+{
+       LOGI("delete_dump!");
+
+       remove_dir(LOG_DUMP_DIR, 0);
+       remove_dir(LOG_DUMP_RESULT, 1);
+       remove_dir(CRASH_DUMP_DIR, 0);
+       remove_dir(CRASH_TEMP_DIR, 0);
+
+       return 0;
+}
+
 int main(int argc, char *argv[])
 {
        int c, ret;
similarity index 67%
rename from src/log_dump/log_dump.h
rename to src/log_dump/log_dump.h.in
index 9936a08..0d39555 100644 (file)
 #ifndef __LOGDUMP_H__
 #define __LOGDUMP_H__
 
+#include <tzplatform_config.h>
 #include <dlog.h>
 #undef LOG_TAG
 #define LOG_TAG "LOG_DUMP"
 
+#define LOG_DUMP_ROOT    tzplatform_getenv(TZ_SYS_CRASH_ROOT)
+#define LOG_DUMP_DIR     tzplatform_getenv(TZ_SYS_ALLLOGS)
+#define LOG_DUMP_RESULT  tzplatform_mkpath(TZ_SYS_CRASH_ROOT, "debug")
+#define CRASH_DUMP_DIR   "@CRASH_PATH@"
+#define CRASH_TEMP_DIR   "@CRASH_TEMP@"
+#define DUMP_SCRIPTS_DIR tzplatform_getenv(TZ_SYS_DUMPGEN)
+
 enum {
        OPT_NORMAL,
        OPT_SHORT,
@@ -30,5 +38,6 @@ enum {
 };
 
 int log_dump(int option);
+int delete_dump(void);
 
 #endif
index 99d3383..e6c7ca0 100644 (file)
@@ -62,3 +62,11 @@ INSTALL(TARGETS ${LIBNAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
 
 CONFIGURE_FILE(sys-assert.conf.in sys-assert.conf)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sys-assert.conf DESTINATION ${TMP_FILES_DIR})
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen-debug-on.service DESTINATION /usr/lib/systemd/system
+        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+        GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen-debug-off.service DESTINATION /usr/lib/systemd/system
+        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+        GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
\ No newline at end of file
diff --git a/src/sys-assert/tizen-debug-off.service b/src/sys-assert/tizen-debug-off.service
new file mode 100644 (file)
index 0000000..870964e
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=tizen debug off
+DefaultDependencies=no
+After=opt.mount tizen-debug-on.service
+Before=sysinit.target
+
+[Service]
+SmackProcessLabel=System
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/bin/rm -f /opt/etc/.debugmode
+ExecStart=/sbin/sysctl kernel.core_pattern=/dev/null
+
+[Install]
+WantedBy=sysinit.target
diff --git a/src/sys-assert/tizen-debug-on.service b/src/sys-assert/tizen-debug-on.service
new file mode 100644 (file)
index 0000000..22ae97a
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=tizen debug on
+DefaultDependencies=no
+After=opt.mount
+Before=sysinit.target
+
+[Service]
+SmackProcessLabel=System
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/bin/touch -f /opt/etc/.debugmode
+ExecStart=/sbin/sysctl -p /usr/lib/sysctl.d/99-crash-manager.conf
+
+[Install]
+WantedBy=sysinit.target