Revert "Separate logdump from crash-worker" 14/122514/1
authorSunmin Lee <sunm.lee@samsung.com>
Mon, 3 Apr 2017 01:27:39 +0000 (10:27 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Mon, 3 Apr 2017 01:27:49 +0000 (10:27 +0900)
This reverts commit c7826eefdccc5776eb0665cb0feb5d060e69fe96.

Change-Id: I398cf722d445b037d32d8116cc9c18a3a326b673

12 files changed:
CMakeLists.txt
dump_scripts/module_log.sh [new file with mode: 0755]
dump_scripts/system_log.sh [new file with mode: 0755]
packaging/crash-worker.manifest
packaging/crash-worker.spec
src/log_dump/CMakeLists.txt [new file with mode: 0644]
src/log_dump/dbus-handler.c [new file with mode: 0644]
src/log_dump/dbus-handler.h [new file with mode: 0644]
src/log_dump/log_dump.c [new file with mode: 0644]
src/log_dump/log_dump.conf [new file with mode: 0644]
src/log_dump/log_dump.h.in [new file with mode: 0644]
src/log_dump/org.tizen.system.crash.service [new file with mode: 0644]

index ab7ad7a..a3ca59d 100644 (file)
@@ -16,5 +16,6 @@ IF(TIZEN_FEATURE_PTRACE_CALLSTACK STREQUAL on)
 ENDIF()
 
 ADD_SUBDIRECTORY(src/dump_systemstate)
+ADD_SUBDIRECTORY(src/log_dump)
 ADD_SUBDIRECTORY(tests)
 
diff --git a/dump_scripts/module_log.sh b/dump_scripts/module_log.sh
new file mode 100755 (executable)
index 0000000..8e1a187
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# Dump module log
+#
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+DUMP_DEST=$1/module_log
+DUMP_SCRIPT_DIR=/opt/etc/dump.d/module.d
+
+mkdir -p ${DUMP_DEST}
+
+if [ -d ${DUMP_SCRIPT_DIR} ]
+then
+       SCRIPTS=`/bin/ls ${DUMP_SCRIPT_DIR}`
+
+       for SCRIPT in ${SCRIPTS}; do
+               /bin/sh ${DUMP_SCRIPT_DIR}/${SCRIPT} ${DUMP_DEST}
+       done
+fi
diff --git a/dump_scripts/system_log.sh b/dump_scripts/system_log.sh
new file mode 100755 (executable)
index 0000000..6d57f64
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Dump system log
+#
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+DUMP_DEST=$1/system_log
+
+mkdir -p ${DUMP_DEST}
+
+/bin/cp -fr /opt/var/log/* ${DUMP_DEST}
+/bin/cp -fr /run/systemd/journal ${DUMP_DEST}
index 25bee3e..c6cdebc 100644 (file)
@@ -5,5 +5,6 @@
        <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/bin/log_dump" label="System" exec_label="System"/>
        </assign>
 </manifest>
index 32890c5..8af23ea 100644 (file)
@@ -73,6 +73,10 @@ This package contains installable tests in Bash.
 %define crash_path      %{TZ_SYS_CRASH}
 %define crash_temp      %{crash_root_path}/temp
 
+#Path for log_dump module
+%define crash_all_log   %{TZ_SYS_ALLLOGS}
+%define crash_dump_gen  %{TZ_SYS_DUMPGEN}
+
 %define upgrade_script_path %{TZ_SYS_RO_SHARE}/upgrade/scripts
 
 %build
@@ -124,6 +128,12 @@ mkdir -p %{buildroot}%{crash_root_path}
 mkdir -p %{buildroot}%{crash_path}
 mkdir -p %{buildroot}%{crash_temp}
 
+# log_dump dir
+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}/*
+
 %post
 %if %{with sys_assert}
 if [ ! -d /.build ]; then
@@ -141,6 +151,10 @@ fi
 
 /usr/bin/chsmack -a "System" -t %{crash_path}
 /usr/bin/chsmack -a "System" -t %{crash_temp}
+/usr/bin/chsmack -a "System" -t %{crash_dump_gen}
+/usr/bin/chsmack -a "System" -t %{crash_dump_gen}/module.d
+/usr/bin/chsmack -a "System::Shared" -t %{crash_all_log}
+/usr/bin/chsmack -a "_"  %{crash_dump_gen}/module.d/*
 
 %postun
 %if %{with sys_assert}
@@ -157,11 +171,15 @@ sed -i "/${pattern}/D" %{_sysconfdir}/ld.so.preload
 %dir %{crash_root_path}
 %dir %{crash_path}
 %dir %{crash_temp}
+%dir %{crash_all_log}
+%{crash_dump_gen}/*
 %attr(0755,root,root) %{_bindir}/*
 %attr(0644,root,system) %{_unitdir}/tizen-debug-on.service
 %attr(0644,root,system) %{_unitdir}/tizen-debug-off.service
 %{TZ_SYS_ETC}/crash-manager.conf
+%attr(-,root,root) %{_sysconfdir}/dbus-1/system.d/log_dump.conf
 %attr(-,root,root) %{_prefix}/lib/sysctl.d/99-crash-manager.conf
+%attr(-,root,root) %{_datadir}/dbus-1/system-services/org.tizen.system.crash.service
 
 %if %{with sys_assert}
 %{_libdir}/libsys-assert.so
diff --git a/src/log_dump/CMakeLists.txt b/src/log_dump/CMakeLists.txt
new file mode 100644 (file)
index 0000000..20202b6
--- /dev/null
@@ -0,0 +1,35 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(log_dump C)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+SET(LOG_DUMP_SRCS
+       log_dump.c
+       dbus-handler.c
+       ${CMAKE_SOURCE_DIR}/src/shared/util.c
+   )
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(log_dump_pkgs REQUIRED
+       dlog
+       capi-system-info
+       libtzplatform-config
+       gio-2.0
+       )
+
+FOREACH(flag ${log_dump_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+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)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.system.crash.service
+       DESTINATION /usr/share/dbus-1/system-services)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/log_dump.conf
+       DESTINATION /etc/dbus-1/system.d)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin
+               PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+               GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
diff --git a/src/log_dump/dbus-handler.c b/src/log_dump/dbus-handler.c
new file mode 100644 (file)
index 0000000..2eecde6
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * log_dump
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdbool.h>
+#include <gio/gio.h>
+#include "log_dump.h"
+#include "dbus-handler.h"
+
+/* Dbus activation */
+#define CRASH_BUS_NAME          "org.tizen.system.crash"
+#define CRASH_OBJECT_PATH       "/Org/Tizen/System/Crash/Crash"
+
+/* Log dump signal */
+#define LOG_DUMP_BUS_NAME       "org.tizen.system.logdump"
+#define LOG_DUMP_OBJECT_PATH    "/Org/Tizen/System/LogDump"
+#define LOG_DUMP_INTERFACE_NAME LOG_DUMP_BUS_NAME
+#define LOG_DUMP_START_SIGNAL   "Start"
+#define LOG_DUMP_FINISH_SIGNAL  "Finish"
+
+#define TIMEOUT_INTERVAL 30
+
+static GMainLoop *loop;
+static GMutex timeout_mutex;
+static guint timeout_id;
+static GDBusNodeInfo *introspection_data;
+static const gchar introspection_xml[] =
+"<node>"
+" <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='delete_dump'>"
+"   <arg type='i' name='response' direction='out'/>"
+"  </method>"
+" </interface>"
+"</node>";
+
+static int timeout_cb(gpointer data)
+{
+       _I("Time out!");
+       g_main_loop_quit((GMainLoop *)data);
+
+       return 0;
+}
+
+static void add_timeout(void)
+{
+       g_mutex_lock(&timeout_mutex);
+
+       if (timeout_id)
+               g_source_remove(timeout_id);
+       timeout_id = g_timeout_add_seconds(TIMEOUT_INTERVAL, timeout_cb, loop);
+
+       g_mutex_unlock(&timeout_mutex);
+       _I("Add loop timeout (%d)", TIMEOUT_INTERVAL);
+}
+
+static void remove_timeout(void)
+{
+       g_mutex_lock(&timeout_mutex);
+
+       if (timeout_id) {
+               g_source_remove(timeout_id);
+               timeout_id = 0;
+       }
+
+       g_mutex_unlock(&timeout_mutex);
+       _I("Remove loop timeout");
+}
+
+static void method_call_handler(GDBusConnection *conn,
+                               const gchar *sender,
+                               const gchar *object_path,
+                               const gchar *iface_name,
+                               const gchar *method_name,
+                               GVariant *parameters,
+                               GDBusMethodInvocation *invocation,
+                               gpointer user_data)
+{
+       int ret = -1;
+       const gchar *arg;
+
+       remove_timeout();
+
+       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
+                       _E("Wrong option for log_dump");
+       } else if (g_strcmp0(method_name, "delete_dump") == 0) {
+               ret = delete_dump();
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+                       g_variant_new("(i)", ret));
+
+       add_timeout();
+}
+
+static const GDBusInterfaceVTable interface_vtable = {
+       method_call_handler,
+       NULL,
+       NULL
+};
+
+static void on_bus_acquired(GDBusConnection *conn,
+                           const gchar *name,
+                           gpointer user_data)
+{
+       guint registration_id;
+
+       registration_id = g_dbus_connection_register_object(conn,
+                       CRASH_OBJECT_PATH, introspection_data->interfaces[0],
+                       &interface_vtable, NULL, NULL, NULL);
+       if (registration_id == 0)
+               _E("Failed to g_dbus_connection_register_object");
+}
+
+static void on_name_acquired(GDBusConnection *conn,
+                            const gchar *name,
+                            gpointer user_data)
+{
+       _D("Acquired the name %s on the system bus", name);
+}
+
+static void on_name_lost(GDBusConnection *conn,
+                        const gchar *name,
+                        gpointer user_data)
+{
+       _D("Lost the name %s on the system bus", name);
+}
+
+static void dbus_init(void)
+{
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+
+       introspection_data =
+               g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+       if (introspection_data == NULL) {
+               _E("Failed to init g_dbus_info_new_for_xml");
+               return;
+       }
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (!conn) {
+               _E("Failed to get dbus");
+               return;
+       }
+
+       if (error) {
+               _E("Failed to get dbus: %s", error->message);
+               g_error_free(error);
+               return;
+       }
+
+       g_bus_own_name(G_BUS_TYPE_SYSTEM, CRASH_BUS_NAME,
+                       G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired,
+                       on_name_acquired, on_name_lost, NULL, NULL);
+}
+
+int log_dump_dbus(void)
+{
+       loop = g_main_loop_new(NULL, false);
+
+       dbus_init();
+
+       g_mutex_init(&timeout_mutex);
+       add_timeout();
+
+       _I("log_dump_dbus activated");
+       g_main_loop_run(loop);
+
+       if (introspection_data)
+               g_dbus_node_info_unref(introspection_data);
+       g_mutex_clear(&timeout_mutex);
+       g_main_loop_unref(loop);
+
+       return 0;
+}
+
+static int broadcast_logdump(const char *signal)
+{
+       GDBusConnection *conn;
+       GError *error = NULL;
+
+       _I("broadcast signal: %s", signal);
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error) {
+               _E("Failed to get dbus: %s", error->message);
+               g_error_free(error);
+               return -1;
+       }
+
+       g_dbus_connection_emit_signal(conn,
+                                     NULL,
+                                     LOG_DUMP_OBJECT_PATH,
+                                     LOG_DUMP_INTERFACE_NAME,
+                                     signal,
+                                     NULL,
+                                     &error);
+       if (error) {
+               _E("Failed to emit signal: %s", error->message);
+               g_error_free(error);
+               return -1;
+       }
+
+       return 0;
+}
+
+int broadcast_logdump_start(void)
+{
+       return broadcast_logdump(LOG_DUMP_START_SIGNAL);
+}
+
+int broadcast_logdump_finish(void)
+{
+       return broadcast_logdump(LOG_DUMP_FINISH_SIGNAL);
+}
diff --git a/src/log_dump/dbus-handler.h b/src/log_dump/dbus-handler.h
new file mode 100644 (file)
index 0000000..a936f31
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * log_dump
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LOGDUMP_DBUS_H__
+#define __LOGDUMP_DBUS_H__
+
+int log_dump_dbus(void);
+int broadcast_logdump_start(void);
+int broadcast_logdump_finish(void);
+
+#endif
diff --git a/src/log_dump/log_dump.c b/src/log_dump/log_dump.c
new file mode 100644 (file)
index 0000000..16150a9
--- /dev/null
@@ -0,0 +1,293 @@
+/*
+ * log_dump: dump current system states
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <limits.h>
+#include <time.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <libgen.h>
+#include <system_info.h>
+#include "shared/util.h"
+#include "log_dump.h"
+#include "dbus-handler.h"
+
+#undef LOG_TAG
+#define LOG_TAG          "LOG_DUMP"
+#define SYSTEM_INFO_KEY_BUILD_STRING "http://tizen.org/system/build.string"
+
+static const struct option opts[] = {
+       { "normal", no_argument, 0, OPT_NORMAL },
+       { "short",  no_argument, 0, OPT_SHORT  },
+       { "dbus",   no_argument, 0, OPT_DBUS   },
+       { 0, 0, 0, 0 }
+};
+
+static inline void usage(void)
+{
+       printf("Usage: log_dump [OPTION]\n");
+       printf("Dump options:\n");
+       printf("  %-10s %s (%s)\n", "--normal",
+                       "dump all logs", DUMP_SCRIPTS_DIR);
+       printf("  %-10s %s\n", "--short",
+                       "dump systemstate only");
+       printf("  %-10s %s\n", "--dbus",
+                       "activate dbus interface");
+}
+
+static int dump_scripts(void)
+{
+       struct dirent **dir_list = NULL;
+       char command[PATH_MAX];
+       int script_num, i;
+
+       script_num = scandir(DUMP_SCRIPTS_DIR, &dir_list, NULL, NULL);
+       if (script_num < 0) {
+               _E("Failed to scandir %s",DUMP_SCRIPTS_DIR);
+               return -1;
+       }
+
+       for (i = 0; i < script_num; i++) {
+               if (dir_list[i]->d_type != DT_REG)
+                       continue;
+
+               snprintf(command, sizeof(command), "%s/%s %s",
+                               DUMP_SCRIPTS_DIR, dir_list[i]->d_name,
+                               LOG_DUMP_DIR);
+               _D("%s", command);
+               system_command(command);
+       }
+
+       for (i = 0; i < script_num; i++)
+               free(dir_list[i]);
+       free(dir_list);
+
+       return 0;
+}
+
+int log_dump(int option)
+{
+       int ret;
+       char *version_str = NULL;
+       char *dump_dirname = NULL;
+       char *crash_dirname = NULL;
+       char timestr[80];
+       char command[PATH_MAX];
+       char dump_filename[NAME_MAX];
+       time_t cur_time;
+       struct tm loc_tm;
+
+       broadcast_logdump_start();
+
+       /* Make debug directory */
+       if (access(LOG_DUMP_DIR, F_OK) != 0) {
+               ret = snprintf(command, sizeof(command),
+                               "/usr/bin/mkdir -p %s", LOG_DUMP_DIR);
+               if (ret < 0) {
+                       _E("Failed to mkdir");
+                       return -1;
+               }
+               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) {
+                       _E("Failed to mkdir");
+                       return -1;
+               }
+               system_command(command);
+       }
+
+       /* Get timestamp */
+       cur_time = time(NULL);
+       localtime_r(&cur_time, &loc_tm);
+       strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", &loc_tm);
+
+       /* Get version */
+       ret = system_info_get_platform_string(SYSTEM_INFO_KEY_BUILD_STRING,
+                       &version_str);
+       if (ret != SYSTEM_INFO_ERROR_NONE) {
+               _E("Failed to system_info_get_platform_string");
+               version_str = NULL;
+       }
+
+       /* Dump system states */
+       ret = snprintf(command, sizeof(command),
+                       "/usr/bin/dump_systemstate -k -d -f "
+                       "%s/dump_systemstate_%s.log", LOG_DUMP_DIR, timestr);
+       if (ret < 0) {
+               _E("Failed to snprintf for command");
+               goto exit;
+       }
+       system_command(command);
+
+       /* Dump all logs */
+       if (option == OPT_NORMAL)
+               dump_scripts();
+
+       if (version_str) {
+               ret = snprintf(dump_filename, sizeof(dump_filename), "%s_%s",
+                               "log_dump", version_str);
+               if (ret < 0) {
+                       _E("Failed to snprintf for dump path");
+                       goto exit;
+               }
+       } else {
+               ret = snprintf(dump_filename, sizeof(dump_filename), "%s",
+                               "log_dump");
+               if (ret < 0) {
+                       _E("Failed to snprintf for dump path");
+                       return -1;
+               }
+       }
+
+       /* Compression */
+       dump_dirname = strdup(LOG_DUMP_DIR);
+       if (!dump_dirname) {
+               _E("Failed to strdup for dump_dirname");
+               goto exit;
+       }
+
+       if (option == OPT_NORMAL) {
+               crash_dirname = strdup(CRASH_DUMP_DIR);
+               if (!crash_dirname) {
+                       _E("Failed to strdup for dump_dirname");
+                       goto exit;
+               }
+
+               ret = snprintf(command, sizeof(command),
+                               "cd %s && /bin/zip -r %s/%s%s.zip %s %s > /dev/null 2>&1",
+                               LOG_DUMP_ROOT,
+                               LOG_DUMP_RESULT, dump_filename, timestr,
+                               basename(dump_dirname), basename(crash_dirname));
+               if (ret < 0) {
+                       _E("Failed to snprintf for command");
+                       goto exit;
+               }
+       } else {
+               ret = snprintf(command, sizeof(command),
+                               "cd %s && /bin/zip -r %s/%s%s.zip %s > /dev/null 2>&1",
+                               LOG_DUMP_ROOT,
+                               LOG_DUMP_RESULT, dump_filename, timestr,
+                               basename(dump_dirname));
+               if (ret < 0) {
+                       _E("Failed to snprintf for command");
+                       goto exit;
+               }
+       }
+       system_command(command);
+
+       sync();
+
+       /* Remove gatherd dump */
+       ret = remove_dir(LOG_DUMP_DIR, 0);
+       if (ret < 0) {
+               _E("Failed to delete dump directory");
+               goto exit;
+       }
+       if (option == OPT_NORMAL) {
+               ret = remove_dir(CRASH_DUMP_DIR, 0);
+               if (ret < 0) {
+                       _E("Failed to delete crash dump directory");
+                       goto exit;
+               }
+       }
+
+       broadcast_logdump_finish();
+
+       /* Further operations for log_dump here */
+
+exit:
+       if (version_str)
+               free(version_str);
+       if (dump_dirname)
+               free(dump_dirname);
+       if (crash_dirname)
+               free(crash_dirname);
+
+       return ret;
+}
+
+int delete_dump(void)
+{
+       _I("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;
+       int option;
+
+       if (argc < 2) {
+               usage();
+               exit(EXIT_SUCCESS);
+       }
+
+       option = -1;
+       while ((c = getopt_long_only(argc, argv, "", opts, NULL)) != -1) {
+               switch (c) {
+               case OPT_NORMAL:
+                       if (option >= 0) {
+                               usage();
+                               exit(EXIT_SUCCESS);
+                       }
+                       option = OPT_NORMAL;
+                       break;
+               case OPT_SHORT:
+                       if (option >= 0) {
+                               usage();
+                               exit(EXIT_SUCCESS);
+                       }
+                       option = OPT_SHORT;
+                       break;
+               case OPT_DBUS:
+                       if (option >= 0) {
+                               usage();
+                               exit(EXIT_SUCCESS);
+                       }
+                       option = OPT_DBUS;
+                       break;
+               default:
+                       usage();
+                       exit(EXIT_SUCCESS);
+                       break;
+               }
+       }
+
+       if (option == OPT_DBUS)
+               ret = log_dump_dbus();
+       else
+               ret = log_dump(option);
+
+       if (ret < 0)
+               exit(EXIT_FAILURE);
+
+       return 0;
+}
diff --git a/src/log_dump/log_dump.conf b/src/log_dump/log_dump.conf
new file mode 100644 (file)
index 0000000..3d3e8e0
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="org.tizen.system.crash"/>
+       <allow send_destination="org.tizen.system.crash"
+              send_interface="org.tizen.system.crash.Crash"
+              send_member="dump_log"/>
+       <allow send_destination="org.tizen.system.crash"
+              send_interface="org.tizen.system.crash.Crash"
+              send_member="delete_dump"/>
+    </policy>
+    <policy user="system">
+        <allow own="org.tizen.system.crash"/>
+       <allow send_destination="org.tizen.system.crash"
+              send_interface="org.tizen.system.crash.Crash"
+              send_member="dump_log"/>
+       <allow send_destination="org.tizen.system.crash"
+              send_interface="org.tizen.system.crash.Crash"
+              send_member="delete_dump"/>
+    </policy>
+
+    <policy context="default">
+       <deny send_destination="org.tizen.system.crash"
+             send_interface="org.tizen.system.crash.Crash"
+             send_member="dump_log"/>
+       <deny send_destination="org.tizen.system.crash"
+             send_interface="org.tizen.system.crash.Crash"
+             send_member="delete_dump"/>
+    </policy>
+</busconfig>
diff --git a/src/log_dump/log_dump.h.in b/src/log_dump/log_dump.h.in
new file mode 100644 (file)
index 0000000..9c5cfaa
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * log_dump
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LOGDUMP_H__
+#define __LOGDUMP_H__
+
+#include <tzplatform_config.h>
+#include "shared/log.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,
+       OPT_DBUS,
+};
+
+int log_dump(int option);
+int delete_dump(void);
+
+#endif
diff --git a/src/log_dump/org.tizen.system.crash.service b/src/log_dump/org.tizen.system.crash.service
new file mode 100644 (file)
index 0000000..1e9a605
--- /dev/null
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=org.tizen.system.crash
+Exec=/usr/bin/log_dump --dbus
+User=root
+Group=root