diff options
author | Sunmin Lee <sunm.lee@samsung.com> | 2017-02-28 15:02:25 +0900 |
---|---|---|
committer | Sunmin Lee <sunm.lee@samsung.com> | 2017-02-28 15:02:25 +0900 |
commit | c7826eefdccc5776eb0665cb0feb5d060e69fe96 (patch) | |
tree | b588741f67bf1e36ce1c05ade9e1079da625925a /src | |
parent | cdbc00c464c1f714fc51a27f02548035b6c97155 (diff) | |
download | crash-worker-c7826eefdccc5776eb0665cb0feb5d060e69fe96.tar.gz crash-worker-c7826eefdccc5776eb0665cb0feb5d060e69fe96.tar.bz2 crash-worker-c7826eefdccc5776eb0665cb0feb5d060e69fe96.zip |
Separate logdump from crash-worker
In Tizen 4.0, the log_dump tool is supposed to be managed
in separate package.
Change-Id: Ie45cfdd9ee0530ef2e520ac781e9971120c87aeb
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/log_dump/CMakeLists.txt | 35 | ||||
-rw-r--r-- | src/log_dump/dbus-handler.c | 238 | ||||
-rw-r--r-- | src/log_dump/dbus-handler.h | 26 | ||||
-rw-r--r-- | src/log_dump/log_dump.c | 293 | ||||
-rw-r--r-- | src/log_dump/log_dump.conf | 31 | ||||
-rw-r--r-- | src/log_dump/log_dump.h.in | 43 | ||||
-rw-r--r-- | src/log_dump/org.tizen.system.crash.service | 5 |
7 files changed, 0 insertions, 671 deletions
diff --git a/src/log_dump/CMakeLists.txt b/src/log_dump/CMakeLists.txt deleted file mode 100644 index 20202b6..0000000 --- a/src/log_dump/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -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 deleted file mode 100644 index 2eecde6..0000000 --- a/src/log_dump/dbus-handler.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * 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 deleted file mode 100644 index a936f31..0000000 --- a/src/log_dump/dbus-handler.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 deleted file mode 100644 index 16150a9..0000000 --- a/src/log_dump/log_dump.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * 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 deleted file mode 100644 index 3d3e8e0..0000000 --- a/src/log_dump/log_dump.conf +++ /dev/null @@ -1,31 +0,0 @@ -<!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 deleted file mode 100644 index 9c5cfaa..0000000 --- a/src/log_dump/log_dump.h.in +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 deleted file mode 100644 index 1e9a605..0000000 --- a/src/log_dump/org.tizen.system.crash.service +++ /dev/null @@ -1,5 +0,0 @@ -[D-BUS Service] -Name=org.tizen.system.crash -Exec=/usr/bin/log_dump --dbus -User=root -Group=root |